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, ...
随机推荐
- Linux负载均衡概念与实践(一)
根据网上文章整理. 负载均衡软件LVS(Linux Virtual Server)概念篇 lvs是在linux操作系统基础上建立虚拟服务器,实现服务节点之间的负载均衡.它是基于linux内核实现的.2 ...
- Java Web开发之详解JSP
JSP作为Java Web开发中比较重要的技术,一般当作视图(View)的技术所使用,即用来展现页面.Servlet由于其本身不适合作为表现层技术,所以一般被当作控制器(Controller)所使用, ...
- JavaScript事件总结
JavaScript 事件总结 本文总结自<JavaScript高级程序设计>以及自己平时的经验,针对较新浏览器以及 DOM3 级事件标准(2016年8月),对少部分内容作了更正,增加 ...
- CentOS 根据命令查所在的包
在工作中经常会遇到想用某个命令机器没装却又不知道命令在哪个包(源码编译不再本文范围内),下面介绍个比较笨的方法可以帮助我们搞定这个问题. 说明:蓝色=命令名称 浅绿=命令参数 ...
- NodeJS+Express+Socket.io的一个简单例子
关键字:NodeJS,Express,Socket.io. OS:Windows 8.1 with update pro. 1.安装NodeJS:http://nodejs.org/. 2.初始化一个 ...
- socket编程中用到的头文件整理
socket编程中需要用到的头文件 sys/types.h:数据类型定义 sys/socket.h:提供socket函数及数据结构 netinet/in.h:定义数据结构sockaddr_in arp ...
- python 中参数*args, **kwargs
def func(*args, **kwargs): print 'args : ', args print 'kwargs :', kwargs def test(): func(1,2,'x',' ...
- NPOI常用功能工具类
public class NPOIHelper { /// <summary> /// DataTable导出到Excel文件 /// </summary> /// <p ...
- [XJOI NOI02015训练题7] B 线线线 【二分】
题目链接:XJOI - NOI2015-07 - B 题目分析 题意:过一个点 P 的所有直线,与点集 Q 的最小距离是多少?一条直线与点集的距离定义为点集中每个点与直线距离的最大值. 题解:二分答案 ...
- 为tomcat启用nio机制
tomcat的运行模式有3种.修改他们的运行模式.3种模式的运行是否成功,可以看他的启动控制台,或者启动日志.或者登录他们的默认页面http://localhost:8080/查看其中的服务器状态. ...