In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the detailed introduction of the C# control array". In the daily operation, I believe that many people have doubts about the detailed introduction of the C# control array. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "detailed introduction of C# control array"! Next, please follow the editor to study!
1. Cyclic attached value
In general, there are two ways to do this:
1.1 defines a dynamic array of controls. Because dynamic control arrays are supported in Dot.Net, we can attach designed controls to dynamic arrays so that we can use them at will. The code is as follows:
Private void button1_Click (object sender, System.EventArgs e) {TextBox [] myTextBox = new TextBox [5]; myTextBox [0] = textBox1; myTextBox [1] = textBox2; myTextBox [2] = textBox3; myTextBox [3] = textBox4; myTextBox [4] = textBox5; for
< 5;i++) { myTextBox[i].Text = "fill_1"; } } 1.2 利用窗体的控件数组。因为窗体里的控件,都被包括在Control里面,所以可以根据其类别加以区分。代码如下: private void button2_Click(object sender, System.EventArgs e) { foreach(Control myControls in this.Controls) { if (myControls.ToString().IndexOf("TextBox") >0) {myControls.Text = "fill_2";}
two。 Event response
Let the controls in the array all respond to the same corresponding event, and then distinguish them by the identification that starts in the array. The following example causes five textBox to respond to the same keypress event.
Customize a control event, textBox_KeyPress, with the following code:
Private void textBox_KeyPress
(object sender,System.Windows.Forms.KeyPressEventArgs e) {
TextBox box = (TextBox) sender
MessageBox.Show (this, "you choose" + box.Name + "and you keypress" +
E.KeyChar.ToString (), "try", MessageBoxButtons.OK)
}
Select textBox1, press F4 to display its property page, select the "Events" button (that is, the small lightning), list all the events of textBox1, and write the name of the event we want him to correspond to-textBox_KeyPress in keypress, so that when textBox1 generates a keypress event, it corresponds to textBox_KeyPress, which is our custom event. Similarly, the same property settings are made for other textBox controls. In this way, five textBox respond to one keypress event at the same time, which can be distinguished by the difference of object sender. This achieves the effect of an array.
At this point, the study of "detailed introduction to the array of C# controls" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 211
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.