-----------------------------------------------------------------------------------
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事件
}
}
}
}
}