Csharp/C Sharp by API/System.Windows.Forms/StatusBarPanel — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:09, 26 мая 2010
Содержание
StatusBarPanel.BorderStyle
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class FormWithStatusBar : System.Windows.Forms.Form
{
private StatusBar statusBar = new StatusBar();
private StatusBarPanel sbPnlPrompt = new StatusBarPanel();
private StatusBarPanel sbPnlTime = new StatusBarPanel();
private Timer timer1 = new Timer();
private MainMenu mainMenu;
private System.ruponentModel.Container components;
public FormWithStatusBar()
{
InitializeComponent();
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
this.MenuComplete += new EventHandler(StatusForm_MenuDone);
BuildMenuSystem();
BuildStatBar();
}
private void InitializeComponent()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
[STAThread]
static void Main()
{
Application.Run(new FormWithStatusBar());
}
private void FileExit_Clicked(object sender, EventArgs e)
{
this.Close();
}
private void HelpAbout_Clicked(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Help";
}
private void FileExit_Selected(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Terminates this app";
}
private void HelpAbout_Selected(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Displays app info";
}
private void StatusForm_MenuDone(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Ready";
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime t = DateTime.Now;
string s = t.ToLongTimeString() ;
sbPnlTime.Text = s ;
}
private void BuildMenuSystem()
{
mainMenu = new MainMenu();
MenuItem miFile = mainMenu.MenuItems.Add("&File");
miFile.MenuItems.Add(new MenuItem("E&xit", new EventHandler(this.FileExit_Clicked),Shortcut.CtrlX));
miFile.MenuItems[0].Select += new EventHandler(FileExit_Selected);
MenuItem miHelp = mainMenu.MenuItems.Add("Help");
miHelp.MenuItems.Add(new MenuItem("&About",new EventHandler(this.HelpAbout_Clicked),Shortcut.CtrlA));
miHelp.MenuItems[0].Select += new EventHandler(HelpAbout_Selected);
this.Menu = mainMenu;
}
private void BuildStatBar()
{
statusBar.ShowPanels = true;
statusBar.Panels.AddRange(new StatusBarPanel[] {sbPnlPrompt, sbPnlTime});
sbPnlPrompt.BorderStyle = StatusBarPanelBorderStyle.None;
sbPnlPrompt.AutoSize = StatusBarPanelAutoSize.Spring;
sbPnlPrompt.Width = 62;
sbPnlPrompt.Text = "Ready";
sbPnlTime.Alignment = HorizontalAlignment.Right;
sbPnlTime.Width = 76;
this.Controls.Add(statusBar);
}
}
StatusBarPanel.Icon
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace StatusBarExample
{
public class StatusBarExample : System.Windows.Forms.Form
{
internal System.Windows.Forms.StatusBar statusBar;
private System.ruponentModel.Container components = null;
public StatusBarExample()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.statusBar = new System.Windows.Forms.StatusBar();
this.SuspendLayout();
this.statusBar.Location = new System.Drawing.Point(0, 138);
this.statusBar.Name = "statusBar";
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(292, 24);
this.statusBar.SizingGrip = false;
this.statusBar.TabIndex = 1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(292, 162);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.statusBar});
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Name = "StatusBarExample";
this.Text = "StatusBar Example";
this.Load += new System.EventHandler(this.StatusBarExample_Load);
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new StatusBarExample());
}
private void StatusBarExample_Load(object sender, System.EventArgs e)
{
StatusBarPanel pnlStatus = new StatusBarPanel();
pnlStatus.Text = "Ready";
pnlStatus.Icon = new Icon(Application.StartupPath + "\\active.ico");
pnlStatus.AutoSize = StatusBarPanelAutoSize.Contents;
StatusBarPanel pnlConnection = new StatusBarPanel();
pnlConnection.Text = "Connected to " + "localhost";
pnlConnection.AutoSize = StatusBarPanelAutoSize.Spring;
statusBar.Panels.Add(pnlStatus);
statusBar.Panels.Add(pnlConnection);
}
}
}
StatusBarPanel.Text
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class FormWithStatusBar : System.Windows.Forms.Form
{
private StatusBar statusBar = new StatusBar();
private StatusBarPanel sbPnlPrompt = new StatusBarPanel();
private StatusBarPanel sbPnlTime = new StatusBarPanel();
private Timer timer1 = new Timer();
private MainMenu mainMenu;
private System.ruponentModel.Container components;
public FormWithStatusBar()
{
InitializeComponent();
timer1.Interval = 1000;
timer1.Enabled = true;
timer1.Tick += new EventHandler(timer1_Tick);
this.MenuComplete += new EventHandler(StatusForm_MenuDone);
BuildMenuSystem();
BuildStatBar();
}
private void InitializeComponent()
{
this.ruponents = new System.ruponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
[STAThread]
static void Main()
{
Application.Run(new FormWithStatusBar());
}
private void FileExit_Clicked(object sender, EventArgs e)
{
this.Close();
}
private void HelpAbout_Clicked(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Help";
}
private void FileExit_Selected(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Terminates this app";
}
private void HelpAbout_Selected(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Displays app info";
}
private void StatusForm_MenuDone(object sender, EventArgs e)
{
sbPnlPrompt.Text = "Ready";
}
private void timer1_Tick(object sender, EventArgs e)
{
DateTime t = DateTime.Now;
string s = t.ToLongTimeString() ;
sbPnlTime.Text = s ;
}
private void BuildMenuSystem()
{
mainMenu = new MainMenu();
MenuItem miFile = mainMenu.MenuItems.Add("&File");
miFile.MenuItems.Add(new MenuItem("E&xit", new EventHandler(this.FileExit_Clicked),Shortcut.CtrlX));
miFile.MenuItems[0].Select += new EventHandler(FileExit_Selected);
MenuItem miHelp = mainMenu.MenuItems.Add("Help");
miHelp.MenuItems.Add(new MenuItem("&About",new EventHandler(this.HelpAbout_Clicked),Shortcut.CtrlA));
miHelp.MenuItems[0].Select += new EventHandler(HelpAbout_Selected);
this.Menu = mainMenu;
}
private void BuildStatBar()
{
statusBar.ShowPanels = true;
statusBar.Panels.AddRange(new StatusBarPanel[] {sbPnlPrompt, sbPnlTime});
sbPnlPrompt.BorderStyle = StatusBarPanelBorderStyle.None;
sbPnlPrompt.AutoSize = StatusBarPanelAutoSize.Spring;
sbPnlPrompt.Width = 62;
sbPnlPrompt.Text = "Ready";
sbPnlTime.Alignment = HorizontalAlignment.Right;
sbPnlTime.Width = 76;
this.Controls.Add(statusBar);
}
}
StatusBarPanel.ToolTipText
using System;
using System.Drawing;
using System.Windows.Forms;
class DateAndTimeStatus: Form
{
StatusBarPanel sbpMenu, sbpDate, sbpTime;
public static void Main()
{
Application.Run(new DateAndTimeStatus());
}
public DateAndTimeStatus()
{
StatusBar sb = new StatusBar();
sb.Parent = this;
sb.ShowPanels = true;
sbpMenu = new StatusBarPanel();
sbpMenu.Text = "Reserved for menu help";
sbpMenu.BorderStyle = StatusBarPanelBorderStyle.None;
sbpMenu.AutoSize = StatusBarPanelAutoSize.Spring;
sbpDate = new StatusBarPanel();
sbpDate.AutoSize = StatusBarPanelAutoSize.Contents;
sbpDate.ToolTipText = "The current date";
sbpTime = new StatusBarPanel();
sbpTime.AutoSize = StatusBarPanelAutoSize.Contents;
sbpTime.ToolTipText = "The current time";
sb.Panels.AddRange(new StatusBarPanel[]
{ sbpMenu, sbpDate, sbpTime });
Timer timer = new Timer();
timer.Tick += new EventHandler(TimerOnTick);
timer.Interval = 1000;
timer.Start();
}
void TimerOnTick(object obj, EventArgs ea)
{
DateTime dt = DateTime.Now;
sbpDate.Text = dt.ToShortDateString();
sbpTime.Text = dt.ToShortTimeString();
}
}