ここで行っていることは次のとおりです。値を視覚的に更新する UI を作成すると、他のタイプのサポートも追加されます。おそらく全種類。updateIcons この関数は、コントローラーがロードされるたびに呼び出され、毎回新しい値と名前を持ちます。countControls を使用してコントローラーを追跡するため、クリック時に値を更新できます。myP は、実行時に取得された値を保持するオブジェクトです。ユーザーは、別の画面で作成されたラジオボタン グループボックスからタブを押して値をシャッフルし、ラジオボタン グループを管理できるようにします。プロパティはすべて 1 つのオブジェクトに属します。各プロパティには、私の例の列挙型のように可能な値はほとんどありません。
今、私のrb_CheckedChangedがある種の混乱を返しているので、これを行う最善の方法がわからないので、ちょっと迷っています。これを正しい方法で行うにはどうすればよいですか?全体として、少なくともそのアプローチはやや正しいと感じています。の辞書を作ろうと思いました。チェックされたイベントで使用します。よくわからない
private void updateIcons(List<Props> prop) {
countControls++;
locationY = 10;
int gbHeight;
foreach (var p in prop) {
radioButtonY = 10;
IType pType = p.Type;
if (pType is Enum) {
var myP = new MyProp(p, this);
GroupBox gb = new GroupBox();
gb.Location = new Point(nextLocationX,locationY);
nextLocationX += rbWidth+10;
gb.Name = "groupBox" + countControls;
gb.Text = "smthn";
var TypesArray = set here;
gbHeight = TypesArray.Length;
foreach (var type in TypesArray) {
getimagesPath(TypesArray);
RadioButton rb = new RadioButton();
rb.Appearance = Appearance.Button;
rb.Width = rbWidth;
rb.Height = rbHeight;
rb.Name = type.Name + countControls;
rb.Text = type.Name;
string path = imagePaths[type.Name];
Bitmap rbImage = new Bitmap(path);
rb.BackgroundImage = rbImage;
countControls++;
rb.Location = new Point(radioButtonX, radioButtonY);
if (myP.Value != null && type.Name.SafeEquals(myP.Value.ToString())) {
rb.Checked = true;
}
radioButtonY += rbHeight;
gb.Controls.Add(rb);
rb.CheckedChanged += rb_CheckedChanged;
}
gb.Height = rbHeight * gbHeight + 20;
gb.Width = rbWidth + 10;
Controls.Add(gb);
}
}
}
void rb_CheckedChanged(object sender, EventArgs e) {
RadioButton rb = (RadioButton)sender;
Control control = (Control)sender;
if (rb.Checked) {
MessageBox.Show("You have just checked: " + rb.Text);
MessageBox.Show("You have just called Controller: " + control.Name);
var t = PropSeq;
}
else {
MessageBox.Show("you have just unchecked: " + rb.Text);
MessageBox.Show("You have just called Controller: " + control.Name);
}
}