猪冰龙

导航

c#在panel或groupbox中添加窗体,实现点击不同按钮或combox时panel中窗体切换,在xtratabcontrol中添加窗体

 

参考panel添加窗体:

http://blog.csdn.net/illegalname/article/details/65444249

http://blog.csdn.net/Eastmount/article/details/21461275

 

 

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Threading.Tasks;
  9 using System.Windows.Forms;
 10 
 11 namespace WindowsFormsPanel
 12 {
 13     public partial class Form1 : Form
 14     {
 15         CSUHForm2 win1 = new CSUHForm2();
 16         UHForm2 win2 = new UHForm2();
 17         CamClayForm2 win3 = new CamClayForm2();
 18         //        win1 =new CSUHForm2 ();
 19         //win2=new UHForm2 ();
 20         //win3=new CamClayForm2 ();
 21         public Form1()
 22         {
 23             InitializeComponent();
 24         }
 25 
 26         private void Form1_Load(object sender, EventArgs e)
 27         {
 28 
 29         }
 30 
 31         private void groupBox1_Enter(object sender, EventArgs e)
 32         {
 33 
 34         }
 35 
 36         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 37         {
 38             if (comboBox1.SelectedIndex > -1)
 39             {
 40                 switch (comboBox1.SelectedItem.ToString())
 41                 {
 42                     case "CSUH":
 43                         {
 44                             
 45                             this.groupBox1.Controls.Clear();
 46                             win1.TopLevel = false;
 47                             win1.FormBorderStyle = FormBorderStyle.None;
 48                             win1.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel
 49                             this.groupBox1.Controls.Add(win1);  // 添加w1窗体
 50                             win1.Show();
 51 
 52                             this.panel1.Controls.Clear();  // 清空原有的控件  
 53                             win1.TopLevel = false;  // 非顶级窗口  
 54                             win1.FormBorderStyle = FormBorderStyle.None;  // 不显示标题栏  
 55                             win1.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel  
 56                             this.panel1.Controls.Add(win1);  // 添加w1窗体  
 57                             win1.Show();
 58 
 59                         }
 60 
 61                         break;
 62                     case "UH":
 63                         {
 64                             this.groupBox1.Controls.Clear();
 65                             win2.TopLevel = false;
 66                             win2.FormBorderStyle = FormBorderStyle.None;
 67                             win2.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel
 68                             this.groupBox1.Controls.Add(win2);  // 添加w1窗体
 69                             win2.Show();
 70 
 71                             this.panel1.Controls.Clear();  // 清空原有的控件  
 72                             win2.TopLevel = false;  // 非顶级窗口  
 73                             win2.FormBorderStyle = FormBorderStyle.None;  // 不显示标题栏  
 74                             win2.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel  
 75                             this.panel1.Controls.Add(win2);  // 添加w1窗体  
 76                             win2.Show();
 77                         }
 78 
 79                         break;
 80                     case "CamClay":
 81                         {
 82                             this.groupBox1.Controls.Clear();
 83                             win3.TopLevel = false;
 84                             win3.FormBorderStyle = FormBorderStyle.None;
 85                             win3.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel
 86                             this.groupBox1.Controls.Add(win3);  // 添加w1窗体
 87                             win3.Show();
 88 
 89                             this.panel1.Controls.Clear();  // 清空原有的控件  
 90                             win3.TopLevel = false;  // 非顶级窗口  
 91                             win3.FormBorderStyle = FormBorderStyle.None;  // 不显示标题栏  
 92                             win3.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel  
 93                             this.panel1.Controls.Add(win3);  // 添加w1窗体  
 94                             win3.Show();
 95                         }
 96                         //dataGridView1.BackgroundColor = Color.Red;
 97                         break;
 98                 }
 99             }
100 
101         }
102 
103 
104     }
105 }
panel加载窗体

 


 在groupbox中添加窗体:

 

 

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace LabOpt2
12 {
13     public partial class Form2GASetting : Form
14     {
15         public Form2GASetting()
16         {
17             InitializeComponent();
18 
19             //在Form2GASetting的panel中添加gridcontrol
20             Form3CSUHConstitutiveSetting ModelParaSettingWin = new Form3CSUHConstitutiveSetting();//实例化一个参数设定窗口的实例化                       
21             ModelParaSettingWin.TopLevel = false;  // ModelParaSettingWin设为非顶级窗口  
22             ModelParaSettingWin.FormBorderStyle = FormBorderStyle.None;  // ModelParaSettingWin设定为不显示标题栏  
23             ModelParaSettingWin.Parent = panel1ModelParaSetting;//  将ModelParaSettingWin这个窗体的父容器设定为panel1ModelParaSetting这个panel,有无这句都行
24             ModelParaSettingWin.Dock = System.Windows.Forms.DockStyle.Fill;  // 将窗体铺满这个panel              
25             this.panel1ModelParaSetting.Controls.Add(ModelParaSettingWin);        
26             ModelParaSettingWin.Show();//显示SpreadSheetReadWin窗体在主窗体的panelCtrols1中
27 
28             //在Form2GASetting的groupcontrol组中添加gridcontrol
29             Form3CSUHConstitutiveSetting ModelParaSettingWin2 = new Form3CSUHConstitutiveSetting();//实例化一个参数设定窗口的实例化                       
30             ModelParaSettingWin2.TopLevel = false;  // ModelParaSettingWin设为非顶级窗口  
31             ModelParaSettingWin2.FormBorderStyle = FormBorderStyle.None;  // ModelParaSettingWin设定为不显示标题栏  
32             ModelParaSettingWin2.Parent = groupControl1ModelParaSetting;//  将ModelParaSettingWin这个窗体的父容器设定为panel1ModelParaSetting这个panel,有无这句都行
33             ModelParaSettingWin2.Dock = System.Windows.Forms.DockStyle.Fill;  // 将窗体铺满这个panel              
34             this.groupControl1ModelParaSetting.Controls.Add(ModelParaSettingWin2);        
35             ModelParaSettingWin2.Show();//显示SpreadSheetReadWin窗体在主窗体的panelCtrols1中
36         }
37 
38 
39 
40         private void comboBoxEdit1SelectModel_SelectedIndexChanged(object sender, EventArgs e)
41         {
42             switch (comboBoxEdit1SelectModel.SelectedItem.ToString())
43             {
44                 case "CSUH":
45                     {
46 
47                         MessageBox.Show("选择了CSUH");
48 
49                     }
50                     break;
51                 case "UH": 
52                     {
53                         //Form3CSUHConstitutiveSetting ModelParaSettingWin = new Form3CSUHConstitutiveSetting();//实例化一个参数设定窗口的实例化                       
54                         //ModelParaSettingWin.TopLevel = false;  // ModelParaSettingWin设为非顶级窗口  
55                         //ModelParaSettingWin.FormBorderStyle = FormBorderStyle.None;  // ModelParaSettingWin设定为不显示标题栏  
56                         //ModelParaSettingWin.Parent = panel1ModelParaSetting;//  将ModelParaSettingWin这个窗体的父容器设定为panel1ModelParaSetting这个panel,有无这句都行
57                         //ModelParaSettingWin.Dock = System.Windows.Forms.DockStyle.Fill;  // 将窗体铺满这个panel  
58                         ////Form3CSUHConstitutiveSetting.gridControl1ParaRange             
59                         //this.panel1ModelParaSetting.Controls.Add(ModelParaSettingWin);
60                         //// ModelParaSettingWin.SelectedTabPage = xtraTabPageInputExcel;//在xtraTabControl1Form1这个tabcontrol中显示第一页即xtraTabPageInputExcel
61                         ////xtraTabPageInputExcel.Controls.Add(SpreadSheetReadWin); //在xtraTabPageInputExcel这个page中添加SpreadSheetReadWin窗体          
62                         //ModelParaSettingWin.Show();//显示SpreadSheetReadWin窗体在主窗体的panelCtrols1中
63                         ////Form3CSUHConstitutiveSetting.panel1ModelParaSetting
64                         MessageBox.Show("选择了CSUH");
65                        
66                     } break;
67                 case "ModifiedCamClay":
68                     {
69                         MessageBox.Show("选择了ModifiedCamClay模型");
70                     }
71                     break;
72                 case "CamClay":
73                     {
74                         MessageBox.Show("选择了CamClay模型");
75                     }
76                     break;
77             }
78         }
79 
80         private void panel1ModelParaSetting_Paint(object sender, PaintEventArgs e)
81         {
82 
83         }
84     }
85 }
groupbox中添加form

 

 

 

 

 


 

 怎样切换page呢:

 

xtraTabControl1.SelectedTabPage = xtraTabPage2;
xtraTabControl3.SelectedTabPage = xtraTabPage7;

 1         private void barButtonItem10_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 2         {
 3 
 4             Form2GASetting GaSettingWin = new Form2GASetting();
 5             //this.panelControl1.Controls.Clear();  // 清空主窗体panelCtrols1内原有的控件
 6             //SpreadSheetReadWin.Hide ();//这一句可以代替上面的清除语句
 7             GaSettingWin.TopLevel = false;  // SpreadSheetReadWin非顶级窗口
 8             GaSettingWin.FormBorderStyle = FormBorderStyle.None;  // 不显示标题栏  
 9             GaSettingWin.Dock = System.Windows.Forms.DockStyle.Fill;  // 填充panel  
10             //this.panelControl1.Controls.Add(GaSettingWin);  // 添加SpreadSheetReadWin窗体
11             this.panelControl1.Controls.Add(xtraTabControl1Form1);//用这个选项卡填充panel
12             xtraTabControl1Form1.SelectedTabPage = xtraTabPageSetting;//在Form1中的xtraTabControl1Form1这个tabcontrol中显示第二页即xtraTabPageSetting
13             xtraTabPageSetting.Controls.Add(GaSettingWin);  
14             GaSettingWin.Show();//显示SpreadSheetReadWin窗体在主窗体的panelCtrols1中
15         }
在tabpage中添加窗体

 

在xtratabcontrol中添加窗体:

http://www.cnblogs.com/w2011/archive/2013/02/18/2915794.html

 

posted on 2018-01-16 14:39  猪冰龙  阅读(996)  评论(0编辑  收藏  举报