c#菜单与treeview初始化
来源:互联网 发布:js设置checkbox不可用 编辑:程序博客网 时间:2024/05/19 23:56
-----------------------------------------------------------------------------------
public void GetMenu(TreeView treeV, MenuStrip MenuS)
{for (int i = 0; i < MenuS.Items.Count; i++) //遍历MenuStrip组件中的一级菜单项
{
//将一级菜单项的名称添加到TreeView组件的根节点中,并设置当前节点的子节点newNode1
TreeNode newNode1 = treeV.Nodes.Add(MenuS.Items[i].Text);
//将当前菜单项的所有相关信息存入到ToolStripDropDownItem对象中
ToolStripDropDownItem newmenu = (ToolStripDropDownItem)MenuS.Items[i];
//判断当前菜单项中是否有二级菜单项
if (newmenu.HasDropDownItems && newmenu.DropDownItems.Count > 0)
for (int j = 0; j < newmenu.DropDownItems.Count; j++) //遍历二级菜单项
{
//将二级菜单名称添加到TreeView组件的子节点newNode1中,并设置当前节点的子节点newNode2
TreeNode newNode2 = newNode1.Nodes.Add(newmenu.DropDownItems[j].Text);
//将当前菜单项的所有相关信息存入到ToolStripDropDownItem对象中
ToolStripDropDownItem newmenu2 = (ToolStripDropDownItem)newmenu.DropDownItems[j];
//判断二级菜单项中是否有三级菜单项
if (newmenu2.HasDropDownItems && newmenu2.DropDownItems.Count > 0)
for (int p = 0; p < newmenu2.DropDownItems.Count; p++) //遍历三级菜单项
//将三级菜单名称添加到TreeView组件的子节点newNode2中
newNode2.Nodes.Add(newmenu2.DropDownItems[p].Text);
}
}
}
、、、、、、、、、、、、、、、、、、、、、、、设置按钮不可用
public void Ena_Button(Button B1, Button B2, Button B3, Button B4, int n1, int n2, int n3, int n4)
{
B1.Enabled = Convert.ToBoolean(n1);
B2.Enabled = Convert.ToBoolean(n2);
B3.Enabled = Convert.ToBoolean(n3);
B4.Enabled = Convert.ToBoolean(n4);
}
、、、、、、、、、、、、、、、、、、、清空窗体控件
public void Clear_Control(Control.ControlCollection Con)
{
foreach (Control C in Con){ //遍历可视化组件中的所有控件
if (C.GetType().Name == "TextBox") //判断是否为TextBox控件
if (((TextBox)C).Visible == true) //判断当前控件是否为显示状态
((TextBox)C).Clear(); //清空当前控件
if (C.GetType().Name == "MaskedTextBox") //判断是否为MaskedTextBox控件
if (((MaskedTextBox)C).Visible == true) //判断当前控件是否为显示状态
((MaskedTextBox)C).Clear(); //清空当前控件
if (C.GetType().Name == "ComboBox") //判断是否为ComboBox控件
if (((ComboBox)C).Visible == true) //判断当前控件是否为显示状态
((ComboBox)C).Text = ""; //清空当前控件的Text属性值
if (C.GetType().Name == "PictureBox") //判断是否为PictureBox控件
if (((PictureBox)C).Visible == true) //判断当前控件是否为显示状态
((PictureBox)C).Image = null; //清空当前控件的Image属性
}
/// 文本框只能输入数字型和单精度型的字符串.
/// </summary>
/// <param name="e">KeyPressEventArgs类</param>
/// <param name="s">文本框的字符串</param>
/// <param name="n">标识,判断是数字型还是单精度型</param>
public void Estimate_Key(KeyPressEventArgs e,string s,int n)
{
if (n==0) //只能输入整型
if (!(e.KeyChar <= '9' && e.KeyChar >= '0') && e.KeyChar != '\r' && e.KeyChar != '\b')
{
e.Handled = true; //处理KeyPress事件
}
if (n == 1) //可以输入整型或单精度型
{
if ((!(e.KeyChar <= '9' && e.KeyChar >= '0')) && e.KeyChar != '.' && e.KeyChar != '\r' && e.KeyChar != '\b')
{
e.Handled = true;
}
else
{
if (e.KeyChar == '.') //如果输入“.”
if (s == "") //当前文本框为空
e.Handled = true; //处理KeyPress事件
else
{
if (s.Length > 0) //当文本框不为空时
{
if (s.IndexOf(".") > -1) //查找是否已输入过“.”
e.Handled = true; //处理KeyPress事件
}
}
}
}
}
- c#菜单与treeview初始化
- c# TreeView树形菜单
- c# TreeView树形菜单
- C# treeView与数据库
- C# treeview右键菜单、选中节点
- C# 递归显示 TreeView 树状菜单树!
- C# treeview右键菜单 设置技巧
- C# treeview右键菜单 设置技巧
- C# TreeView菜单,MenuStrip菜单递归动态生成例子
- C#中的TreeView与TreeNode
- treeview初始化
- C# winform treeview node添加右键菜单并选中节点
- C# winform treeview node添加右键菜单并选中节点
- C# Winform 中Treeview右键选择节点弹出上下文菜单
- C#使用TreeView加载系统应用菜单代码
- C# winform treeview node添加右键菜单并选中节点
- C# winform treeview node添加右键菜单并选中节点
- C#中的TreeView与TreeNode,switch
- Win10一周年更新冻屏可能原因解决方案
- 找10个数里面最大数字
- Spring的AOP传统开发方法带切点的切面
- php和lnmp环境下的论坛部署
- 测试小故事39:怎么测?
- c#菜单与treeview初始化
- 接口和内部类
- Collection 关于List和Set 技巧
- AutoScaling技术相关要点
- SQL Assistant简介
- 用c语言链接MySQL数据库出现Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
- opencv学习之 特征检测与匹配
- Android adb.exe程序启动不起来,如何处理
- 文章标题