How to change the property of a control from a flowlayoutpanel?
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:
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 Name
property 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 sender
argument 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 property of a control from a flowlayoutpanel?的更多相关文章
- How to change Form & Property & Report font for current User [AX2012]
对于我们开发人员来说,系统默认的字体,本人实在不喜欢,尤其是属性字体[太小,太细,根本看不清],每次做一个新项目[AX2012]第一件事就是更改字体. 由于AX2012没有像AX2009那样,可以工具 ...
- List<> of struct with property. Cannot change value of property. why?
这个返回如下错误:"Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.th ...
- Overview of Form Control Types [AX 2012]
Overview of Form Control Types [AX 2012] Other Versions 0 out of 1 rated this helpful - Rate this to ...
- A Complete ActiveX Web Control Tutorial
A Complete ActiveX Web Control Tutorial From: https://www.codeproject.com/Articles/14533/A-Complete- ...
- Writing a Reusable Custom Control in WPF
In my previous post, I have already defined how you can inherit from an existing control and define ...
- Splitter Control for Dialog
原文链接地址:https://www.codeproject.com/Articles/595602/Splitter-Control-for-Dialog Introduction Yes, tha ...
- Shape Control for .NET
Shape Control for .NET Yang Kok Wah, 23 Mar 2017 CPOL 4.83 (155 votes) Rate this: vote 1vote 2v ...
- How to: Change the Format Used for the FullAddress and FullName Properties 如何:更改用于FullAddress和FullName属性的格式
There are FullAddress and FullName properties in the Address and Person business classes that are su ...
- WPF整理-Style
"Consistency in a user interface is an important trait; there are many facets of consistency, ...
随机推荐
- 轻松解决fedora21装完NVIDIA显卡驱动后无法进入gnome问题
本来打算昨天写的,最近感冒了,打点滴,耽搁了! 我用的是联想14寸笔记本,装好了fedora21后,想装个NVIDIA显卡驱动试试,结果和很多人一样无法进入gnome界面,搞了三四个小时终于搞定.下面 ...
- linux (centos 6.4)安装自定义分区方案(转载)
在计算机上安装 Linux 系统,对硬盘进行分区是一个非常重要的步骤,下面介绍几个分区方案. 方案 1 / :建议大小在 5GB 以上. swap :即交换分区,建议大小是物理内存的 1~2 倍. 方 ...
- centos 端口开放及关闭
之前有讲过公司新买的服务器使用的是CentOS 5.5,部署好Tomcat之后却发现输入114.80.*.*:8080(即ip:8080)却无法显示Tomcat默认的首页.因为以前部署在Win Ser ...
- MySQL基础学习之索引
创建新表新索引 CREATE TABLE 表名(数据名 类型,INDEX 索引名称(属性)) 创建存在表的索引 CREATE INDEX 索引名称 ON 表名(属性) 修改索引 ALTER TAB ...
- 001.XE3添加TPerlRegEx
TPerlRegEx 官方下载地址:http://www.regular-expressions.info/download/TPerlRegEx.zip 下载解压,打开pcre.pas文件可看到,直 ...
- WPF中Application.Current的使用
WPF程序对应一个Application对象,当前的Application对象可以通过Application.Current获取,通过获取到的Application对象,我们可以做以下的事情: App ...
- 【转】oracle 针对中文字段进行排序
1)按笔画排序 select * from Table order by nlssort(columnName,'NLS_SORT=SCHINESE_STROKE_M') 2)按部首排序 select ...
- 转载:PCB名詞解釋:通孔、盲孔、埋孔
在[電子製造業]打滾多年,分享 SMT.焊錫.塑膠射出.產品設計.瓦楞包裝…等經驗.請注意文章內容不見得都正確,服用前請三思… 之前有網友提醒我有篇文章把PCB的盲孔(Blind hole).埋孔(B ...
- 【viewResolver】 springmvc jsp
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> < ...
- 一步步学习ASP.NET MVC3 (12)——FileResult
请注明转载地址:http://www.cnblogs.com/arhat 忙了两天,本来老魏昨天就应该写出新的文章,但是由于昨天雨夹雪而且加上昨天晚上加了班,到家都没饭吃了,一看时间都9点了,什么饭店 ...