前提
c#でフォーム1ではradiobtn1で画像1radiobtn2で画像2を表示し
フォーム2ではradiobtn1で画像2、radiobtn2で画像1を表示させたいです。
それぞれのフォームでは常に別の画像が表示できるようにしたく、
片方のradiobtnを変更するともう片方も自動で変更されるようにしたいです。
どのようにすればよいか教えてください。
Form1
c#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10 11namespace WindowsFormsApp2 12{ 13 public partial class Form1 : Form 14 { 15 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void groupBox1_Enter(object sender, EventArgs e) 22 { 23 24 } 25 26 private void radioButton1_CheckedChanged(object sender, EventArgs e) 27 { 28 //画像1を表示 29 } 30 31 private void radioButton2_CheckedChanged(object sender, EventArgs e) 32 { 33 //画像2を表示 34 } 35 36 private void button1_Click(object sender, EventArgs e) 37 { 38 //form2を起動 39 Form2 form2; 40 form2 = new Form2(); 41 form2.Show(); 42 } 43 } 44} 45
Form2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp2 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void groupBox1_Enter(object sender, EventArgs e) { } private void radioButton1_CheckedChanged(object sender, EventArgs e) { //画像2を表示 } private void radioButton2_CheckedChanged(object sender, EventArgs e) { //画像1を表示 } } }
何を何で作っているか書いてください。(例: Windows 10 の Visual Studio 2022 で Windows Forms アプリをターゲットフレームワーク .NET Framework 4.8 で作っています・・・とか)