C#控件数组实现
下面是兩種控件數組處理方法,推薦使用方法2
方法1與方法2的區別是
方法1返回的是字面內容? 既返回的是 text
方法2返回的是控件名稱? 既返回的是 name
調試環境 vs2010 c#
?
?
方法1
//返回控件text文字string str = sender.ToString();System.Diagnostics.Debug.WriteLine("Write str --> " + str);string str2 = str.Substring(str.Length - 1, 1);System.Diagnostics.Debug.WriteLine("Write str2 --> " + str2);switch (str2){case "0":break;case "1":radioButton1.Checked = true;break;case "2":radioButton2.Checked = true;break;case "3":radioButton3.Checked = true;break;case "4":radioButton4.Checked = true;break;case "5":radioButton5.Checked = true;break;case "6":radioButton6.Checked = true;break;}?
方法2
//返回控件名稱nameToolStripMenuItem menu = (ToolStripMenuItem)sender;System.Diagnostics.Debug.WriteLine("Write --> " + menu.Name);//if (menu.Name == "ToolStripMenuItem_QiT1")//{// richTextBox_Run.Text += menu.Name;//}switch (menu.Name){case "ToolStripMenuItem_QiT0":break;case "ToolStripMenuItem_QiT1":radioButton1.Checked = true;break;case "ToolStripMenuItem_QiT2":radioButton2.Checked = true;break;case "ToolStripMenuItem_QiT3":radioButton3.Checked = true;break;case "ToolStripMenuItem_QiT4":radioButton4.Checked = true;break;case "ToolStripMenuItem_QiT5":radioButton5.Checked = true;break;case "ToolStripMenuItem_QiT6":radioButton6.Checked = true;break;}?
特此記錄
by: anlog
2021年4月9日 09點49分
總結
- 上一篇: DAVINCI DM3730开发攻略——
- 下一篇: magento 2 di.xml etc