1. 窗体的opacity属性可以实现窗体的渐显效果,窗体的TopMost属性this.TopMost=True可以是程序始终在前面.
2. 通过设置PictureBox的Dock属性和添加spliter控件可以实现窗体的分割.
3. C#中添加API函数的方法,以SetMenuItemBitmaps为例子
[System..Runtime.Interopservices.DllImport(“user 32” )]
Private static extern int SetMenItemBitmaps{Intptr hMenu,int nPosition,int wFlags,IntPtr hBitmapUnchecked,IntPtr hBitmapChecked };
Const int MF_BYPOSITION=0x0400;
4. 实现渐变窗口背景的方法
添加System.Drawing.Drawing2D空间的引用
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g=e.Graphics ;
Color fcolor=Color.Blue ;
Color Tcolor=Color.Yellow ;
Brush b=new LinearGradientBrush (this.ClientRectangle ,fcolor,Tcolor,LinearGradientMode.ForwardDiagonal );
g.FillRectangle (b,this.ClientRectangle );
}
private void Form1_Resize(object sender, System.EventArgs e)
{
this.Invalidate ();
}
5.通过添加NotifyIcon、ContestMenu组件可以实现状态栏的状态区的使用.
参考代码:
static void Main ()
{
Form 1 f 1=new Form1 ();
f1.notifyIcon1 .Icon =new System .Drawing .Icon ("..//..//BICYCLE.ICO");
f1.notifyIcon1 .Visible =true;
f1.notifyIcon1 .Text ="BICYCLE";
Application.Run ();
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
Application.Exit ();
}
private void timer1_Tick(object sender, System.EventArgs e)
{
if(notifyIcon1.Text =="BICYCLE")
{
notifyIcon1.Icon =new System .Drawing .Icon ("..//..//CARS.ICO");
notifyIcon1.Text ="CARS";
}
else
{
notifyIcon1.Icon =new System .Drawing .Icon ("..//..//BICYCLE.ICO");
notifyIcon1.Text ="BICYCLE";
}
}
6.使用StatusBar控件实现状态栏信息的更新
参考代码:
private void Form1_Load(object sender, System.EventArgs e)
{
statusBar1.Panels .Add ("one");
statusBar1.Panels [0].AutoSize =StatusBarPanelAutoSize.Spring ;
statusBar1.Panels [0].Icon =new System .Drawing .Icon ("..//..//app.ico");
statusBar1.Panels [0].BorderStyle =StatusBarPanelBorderStyle.Sunken;
statusBar1.ShowPanels =true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
statusBar1.Panels [0].Text =DateTime.Now .ToString ();
}
}
7.在C#中使用动画光标的方法
使用SetCursor和LoadCursorFromFile二个API函数,
参考代码:
[DllImport("user32")]
private static extern IntPtr SetCursor(IntPtr hCursor);
[DllImport("user32")]
private static extern IntPtr LoadCursorFromFile(string lpFileName);
const int WM_SETCURSOR=0X0020;
protected override void WndProc(ref System.Windows .Forms .Message m)
{
switch(m.Msg )
{
case WM_SETCURSOR:
IntPtr hCursor;
hCursor=LoadCursorFromFile("..//..//1.ani");
SetCursor(hCursor);
break;
default:
base.WndProc (ref m);
break;
}
}