c#取项目名称-----和-----根据窗体上的控件名称取控件
2010-11-16 15:52
337 查看
取项目名称:
static string AppName()
{
string fullstr = Assembly.GetExecutingAssembly().FullName;
return fullstr.Substring(0, fullstr.IndexOf(","));
}
根据窗体上的控件名称取控件
public static Control GetControl(Control ctrl, string controlName)
{
Control tempControl = null;
//if the input control's name equals the input controlName,return the control
if (ctrl.Name == controlName)
{
tempControl = ctrl;
}
else if (ctrl.Controls.Count != 0)//if the ctrl is not suitable,get its sub controls
{
foreach (Control subCtrl in ctrl.Controls)
{
Control tb = GetControl(subCtrl, controlName);
if (tb != null)
{
tempControl = tb;
break;
}
}
}
return tempControl;
}
-----------------------------------------------
例:引入代码
比如窗体上有N个Panel, 我想操作名称为"panel2"的Panel控件。
Panel pa = (Panel)GetControl(this, "panel2");
pa.Height = 100;
static string AppName()
{
string fullstr = Assembly.GetExecutingAssembly().FullName;
return fullstr.Substring(0, fullstr.IndexOf(","));
}
根据窗体上的控件名称取控件
public static Control GetControl(Control ctrl, string controlName)
{
Control tempControl = null;
//if the input control's name equals the input controlName,return the control
if (ctrl.Name == controlName)
{
tempControl = ctrl;
}
else if (ctrl.Controls.Count != 0)//if the ctrl is not suitable,get its sub controls
{
foreach (Control subCtrl in ctrl.Controls)
{
Control tb = GetControl(subCtrl, controlName);
if (tb != null)
{
tempControl = tb;
break;
}
}
}
return tempControl;
}
-----------------------------------------------
例:引入代码
比如窗体上有N个Panel, 我想操作名称为"panel2"的Panel控件。
Panel pa = (Panel)GetControl(this, "panel2");
pa.Height = 100;
相关文章推荐
- c#取项目名称-----和-----根据窗体上的控件名称取控件
- 地磅称量系统之(24~26)创建一个名称为WinApp的Windows应用程序作为启动项目并且设置主界面上控件的属性
- 项目中在Android.mk文件中根据项目名称选择不同的AndroidManifest.xml文件 && 如何使用系统设定的日期显示格式
- DevExpress.XtraReports根据窗体控件值来显示打印数据
- Unity3D DFGUI根据名称获取多个子控件代码
- Qt UI设计器中根据字符串的名字,来找匹配的控件名称
- C# 使用反射实现根据名称动态创建窗体的几种方法
- 根据指定的容器和控件名称获得控件
- Flex中如何在Tree控件中指定一个自定义的label函数使其返回的标签名字为叶项目的名称的例子
- 更改工程(项目)名称,对话框资源ID、类名,控件ID、变量名、类名
- C#使用tabcontrol控件可操作多窗体嵌入以及双击窗口名称可关闭
- 使用反射实现根据名称动态创建窗体的几种方法
- 遍历WinForm窗体 根据语言类型设置其控件Text显示
- 使用反射实现根据名称动态创建窗体的几种方法。
- 根据控件名称反射查找控件
- ADP项目:控制子窗体中的Check控件
- 根据控件的名称(name)来获取对控件的操作
- 根据窗体名称动态创建窗体
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- 【开源项目】花密(Flower Password)VB版之窗体控件枚举模块