zoukankan      html  css  js  c++  java
  • MDI弹出唯一窗体和遍历panel中的所有控件

     1 /// <summary>
     2         /// 点击开启学生窗体
     3         /// </summary>
     4         /// <param name="sender"></param>
     5         /// <param name="e"></param>
     6         private void pictureBox6_Click(object sender, EventArgs e)
     7         {
     8             bool Has = false;
     9             Form3 F3 = new Form3();
    10             F3.Tag = "F3";
    11             foreach (Form F in panel1.Controls)
    12             {
    13                 if (F.Tag == F3.Tag)
    14                 {
    15                     F.Show();
    16                     F3.Close();
    17                     Has = true;
    18                 }
    19                 else
    20                 {
    21                     F.Hide();
    22                 }
    23             }
    24             if (Has == false)
    25             {
    26                 F3.WindowState = FormWindowState.Maximized;
    27                 F3.MdiParent = this;
    28                 F3.Parent = panel1;
    29                 F3.Show();
    30             }
    31         }
    32         /// <summary>
    33         /// 点击开启教师窗体
    34         /// </summary>
    35         /// <param name="sender"></param>
    36         /// <param name="e"></param>
    37         private void pictureBox5_Click(object sender, EventArgs e)
    38         {
    39             bool Has = false;
    40             Form4 F4 = new Form4();
    41             F4.Tag = "F4";
    42             foreach (Form F in panel1.Controls)
    43             {
    44                 if (F.Tag == F4.Tag)
    45                 {
    46                     F.Show();
    47                     F4.Close();
    48                     Has = true;
    49                 }
    50                 else
    51                 {
    52                     F.Hide();
    53                 }
    54             }
    55             if (Has == false)
    56             {
    57                 F4.WindowState = FormWindowState.Maximized;
    58                 F4.MdiParent = this;
    59                 F4.Parent = panel1;
    60                 F4.Show();
    61             }
    62         }

    遍历panel中所有控件并操作:

     1  foreach (Control TB in panel1.Controls)//遍历所有控件
     2                 {
     3                     if (TB is TextBox)//根据控件类型操作
     4                     {
     5                         TB.Text = "";
     6                     }
     7                     else if (TB is MaskedTextBox)
     8                     {
     9                         TB.Text = "    -  -";
    10                     }
    11                 }
  • 相关阅读:
    回顾C#3.0新特性(3)
    第五周作业
    第六周基础作业
    第三周syh
    基础作业
    第七周作业
    2019年春季学期第四周作业
    第八周作业
    .Net 反射
    C#中SqlParameter
  • 原文地址:https://www.cnblogs.com/mazhijie/p/5648737.html
Copyright © 2011-2022 走看看