c#取项目名称-----和-----根据窗体上的控件名称取控件
2014-03-20 16:55
387 查看
取项目名称:
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#取项目名称-----和-----根据窗体上的控件名称取控件
- C#使用tabcontrol控件可操作多窗体嵌入以及双击窗口名称可关闭
- C# 使用反射实现根据名称动态创建窗体的几种方法
- C# WinForm (笨方法)根据不同的样式配置 设置窗体相关控件的背景 以改变窗体风格
- C#仿QQ皮肤----基窗体FormBase与基用户控件FormBase1的实现
- C# 实现一个窗体调用另一个窗体的控件
- C# 多个窗体之间查找控件
- C#修改项目名称(Solution)
- C#实现控件随窗体拖动而自动缩放其大小
- c#中 一个窗口中需要使用另一个窗口中的控件名称
- C# 遍历窗体上控件方法
- c# winform项目treeview控件绑定本地电脑磁盘信息,浏览磁盘图片,上传本地图片控件
- c#如何将子窗体显示到父窗体的容器(panel)控件中
- C#中通过反射方法获取控件类型和名称
- C#中winform窗体的美化控件 iriskin(一)
- c#程序更改项目名称
- C#WinForm中实现异形窗体/控件
- C#窗体控件-单选按钮控件RadioButton
- C#巧用anchor和dock设计复杂界面(控件随着窗体大小的变化而变化)
- C# winform窗体自动停靠控件