How to change the property of a control from a flowlayoutpanel?
2014-03-24 22:06
453 查看
Well, the easiest way would be to retain an explicit reference to the buttons you're adding. Otherwise you could add a tag to distinguish them (to be robust against i18n issues). E.g. you can set the tag of "button2" to "button2" and then you can use:
}
I am assuming your problem is to find the actual button again and not setting the background color. You could likewise check for the control being a button and its text being "button2" but if the text can change depending on the UI language that's probably not a good idea.
ETA: Totally forgot that you can use the control's
If you just want to change the background color of the button in a response to an event from the button you can just use the
//////
You can try Control.ControlCollection.Find.
foreach(Control ctl in flp.Controls){if("button2".Equals(ctl.Tag)){ ctl.BackColor=Color.Red;}
}
I am assuming your problem is to find the actual button again and not setting the background color. You could likewise check for the control being a button and its text being "button2" but if the text can change depending on the UI language that's probably not a good idea.
ETA: Totally forgot that you can use the control's
Nameproperty for this as well.
If you just want to change the background color of the button in a response to an event from the button you can just use the
senderargument of the event handler, though.
//////
You can try Control.ControlCollection.Find.
flowLayoutPanel1.Controls.Add(newButton(){Text="button 1",Name="btn1"}); Button btn1 = flowLayoutPanel1.Controls.Find("btn1",true).FirstOrDefault()asButton; btn1.Text="found!";
相关文章推荐
- How to change the text color of the selected property sheet tab in Visual C++
- How To Change the Background Color of a Tab Control
- How to get the DOM of a WebBrowser control from a window handle (VB6)
- How To Retrieve the URL of a Web Page from an ActiveX Control
- How to change the language of oracle sqlplus from chinese to english in windows(如何将oracle sql plus中的中文变成英文版)
- Xcode4 布置Git环境Your working copy is out of date. Try pulling from the remote to get the latest change
- 如何给上传控件上色【HOW TO SET CSS FOR THE CONTROL OF FILEUPLOAD】
- How to change the default location of the Office 2010 Document Cache
- QUESTION 66 To recover from the loss of the entire database, including all current control files, al
- How to programmatically change the default view of an InfoPath form
- How to pass a value from User Control to the Page
- How to change the size of the button of an android checkbox?
- How do I change the FROM address to a friendly name?
- How to obtain access to an ActiveX control from its property page 如何从一个控件的属性页中获取对该控件的访问?
- How can I protect derived classes from breaking when I change the internal parts of the base class?
- How to print the content of a Rich Edit Control
- [Drupal] How to change the content from English to language Language neutral
- How to change the color of a CEikLabel
- How to change the Text color of Menu item in Android?
- How to customize the context menus of a WebBrowser control via the IDocHostUIHandler interface.