📄 formbar.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace BufferedUploadWin
{
/// <summary>
/// Summary description for FormBar.
/// </summary>
public class FormBar : System.Windows.Forms.UserControl
{
public System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private System.Windows.Forms.StatusBarPanel statusBarPanel2;
public System.Windows.Forms.ProgressBar progressBar;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ImageList imageListStatusbar;
private StringFormat format; // a formatter for the status bar messages
public FormBar()
{
InitializeComponent();
InitFormatter();
}
/// <summary>
/// The status par panel should be set to owner draw.
/// This method draws a wait cursor in the status bar,
/// if the progress bar is visible.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void statusBar_DrawItem(object sender, System.Windows.Forms.StatusBarDrawItemEventArgs e)
{
Graphics g = e.Graphics;
RectangleF bounds = new RectangleF(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
// display a busy icon if currently busy (displaying the progress bar)
if(e.Index == 0)
{
if(this.progressBar.Visible)
{
// draw the icon
this.imageListStatusbar.Draw(g, (int)bounds.Left + 2, (int)bounds.Top + (((int)bounds.Height - imageListStatusbar.ImageSize.Height)) / 2, 0);
// adjust the drawing area to make room for the icon
bounds.X += this.imageListStatusbar.ImageSize.Width + 5;
bounds.Width -= this.imageListStatusbar.ImageSize.Width + 5;
}
}
// display the status bar text, display ellipsis for long strings
g.DrawString(e.Panel.Text, statusBar1.Font, SystemBrushes.ControlText, bounds, format);
}
private void progressBar_VisibleChanged(object sender, System.EventArgs e)
{
this.statusBar1.Refresh();
}
/// <summary>
/// Used to specify the strings used in the status bar
/// </summary>
private void InitFormatter()
{
format = new StringFormat();
format.FormatFlags = StringFormatFlags.NoWrap;
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;
}
private delegate void updateMessageDel(string msg);
public void UpdateStatusBarMessage(string msg)
{
if(this.InvokeRequired)
{
// switch to UI thread
updateMessageDel del = new updateMessageDel(this.UpdateStatusBarMessage);
BeginInvoke(del, new object[]{msg});
return;
}
this.statusBar1.Panels[0].Text = msg;
}
private delegate void updateProgressBarDel(int newValue);
public void UpdateProgressBar(int newValue)
{
if(this.InvokeRequired)
{
// switch to UI thread
updateProgressBarDel del = new updateProgressBarDel(this.UpdateProgressBar);
BeginInvoke(del, new object[]{newValue});
return;
}
if(newValue <= this.progressBar.Maximum)
this.progressBar.Value = newValue;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormBar));
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel();
this.progressBar = new System.Windows.Forms.ProgressBar();
this.imageListStatusbar = new System.Windows.Forms.ImageList(this.components);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).BeginInit();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, -1);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(640, 22);
this.statusBar1.TabIndex = 4;
this.statusBar1.DrawItem += new System.Windows.Forms.StatusBarDrawItemEventHandler(this.statusBar_DrawItem);
//
// statusBarPanel1
//
this.statusBarPanel1.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
this.statusBarPanel1.Text = "Ready";
this.statusBarPanel1.Width = 300;
//
// statusBarPanel2
//
this.statusBarPanel2.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.statusBarPanel2.Width = 324;
//
// progressBar
//
this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar.Location = new System.Drawing.Point(307, 4);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(312, 15);
this.progressBar.Step = 1;
this.progressBar.TabIndex = 5;
this.progressBar.Visible = false;
this.progressBar.VisibleChanged += new System.EventHandler(this.progressBar_VisibleChanged);
//
// imageListStatusbar
//
this.imageListStatusbar.ImageSize = new System.Drawing.Size(9, 14);
this.imageListStatusbar.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageListStatusbar.ImageStream")));
this.imageListStatusbar.TransparentColor = System.Drawing.Color.Lime;
//
// FormBar
//
this.Controls.Add(this.progressBar);
this.Controls.Add(this.statusBar1);
this.Name = "FormBar";
this.Size = new System.Drawing.Size(640, 21);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
this.ResumeLayout(false);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -