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, ...
随机推荐
- 《APUE》第四章笔记(2)
下面介绍对stat结构的各个成员的操作函数. 先贴个stat结构的图: access函数: #include <unistd.h> int access(const char *pathn ...
- Memcache存储大数据的问题
Memcached存储单个item最大数据是在1MB内,假设数据超过1M,存取set和get是都是返回false,并且引起性能的问题. 我们之前对排行榜的数据进行缓存,因为排行榜在我们全部sql se ...
- http通信协议详解
转载自:http://blog.csdn.net/gueter/article/details/1524447 引言 HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒 ...
- 学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
---恢复内容开始--- 看到同事用unordered_map了所以找个帖子学习学习 http://blog.sina.com.cn/s/blog_4c98b9600100audq.html (一)为 ...
- 关于xcode6打包以及上线前企业部署测试的说明 --转自张诚教授微博
xcode6如何打包 首先clean然后点击归档 点击打包之后保存 点选第一个以后检查相关证书签名 那么我们开发完以后,在上线前如何给别人测试 有2种方法 1.使用299美金的企业开发者账号搭建企业部 ...
- 如何解决jenkins中shell脚本明明执行失败却不自行退出,且构建结果仍然显示success的问题??
首先,需要明确shell命令执行结果$?为0或者非0仅能代表此执行语句是否顺利执行了,例如: 执行语句:adb connect 192.168.XX.XX 执行结果:unable to connect ...
- C++练习题
1. 用面向对象的程序描述员工拥有的股票,股票有公司,价格,数量属性,且拥有展现基本数据,更新价格,买进,卖出操作,并具有比较两个股票对象股值大小的比较方法. 2. 用面向对象的程序描述一个栈的操作, ...
- npm常用命令解析
npm是什么 NPM的全称是Node Package Manager,是随同NodeJS一起安装的包管理和分发工具,它很方便让JavaScript开发者下载.安装.上传以及管理已经安装的包. npm ...
- uva 165 Stamps
题意: 现有k种邮票面额, 一封信上最多贴h张邮票. 求能贴出的最大连续区间,即[1, max_value]这个区间内的所有面额都能贴出来. 并输出k种面额, h + k <= 9. 思路: 这 ...
- 用 Maven 做项目构建
转自:http://www.ibm.com/developerworks/cn/java/j-lo-maven/index.html 本文将介绍基于 Apache Maven 3 的项目构建的基本概念 ...