对应教材2.2.2中的(2)部分
using
System;
using System.Drawing;
using System.Windows.Forms;
public class TwoStatusBarPanels:Form
{
public static void Main()
{
Application.Run(new TwoStatusBarPanels());
}
public TwoStatusBarPanels()
{
//设置窗体属性,这些属性属于基类Form
Text = "Two Status Bar Panels";
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
//动态创建StstusBar控件
StatusBar sb = new StatusBar();
sb.Parent = this;
sb.ShowPanels = true;
//动态创建StatusBarPanel控件
StatusBarPanel sbPanel1 = new StatusBarPanel();
sbPanel1.Text = "Panel 1";
StatusBarPanel sbPanel2 = new StatusBarPanel();
sbPanel2.Text = "Panel 2";
//将StatusBarPanel控件实例添加到StstusBar控件的Panels集合
sb.Panels.Add(sbPanel1);
sb.Panels.Add(sbPanel2);
}
}
完整源代码下载:
TwoStatusBarPanels.rar
using System.Drawing;
using System.Windows.Forms;
public class TwoStatusBarPanels:Form
{
public static void Main()
{
Application.Run(new TwoStatusBarPanels());
}
public TwoStatusBarPanels()
{
//设置窗体属性,这些属性属于基类Form
Text = "Two Status Bar Panels";
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
//动态创建StstusBar控件
StatusBar sb = new StatusBar();
sb.Parent = this;
sb.ShowPanels = true;
//动态创建StatusBarPanel控件
StatusBarPanel sbPanel1 = new StatusBarPanel();
sbPanel1.Text = "Panel 1";
StatusBarPanel sbPanel2 = new StatusBarPanel();
sbPanel2.Text = "Panel 2";
//将StatusBarPanel控件实例添加到StstusBar控件的Panels集合
sb.Panels.Add(sbPanel1);
sb.Panels.Add(sbPanel2);
}
}