渐显的窗体
private
void
Form1_Load(
object
sender, System.EventArgs e)
... {
this.timer1.Enabled=true;
this.Opacity=0;
}
private void timer1_Tick( object sender, System.EventArgs e)
... {
if(this.Opacity<1)
...{
this.Opacity=this.Opacity+0.05;
}
else
...{
this.timer1.Enabled=false;
}
}
... {
this.timer1.Enabled=true;
this.Opacity=0;
}
private void timer1_Tick( object sender, System.EventArgs e)
... {
if(this.Opacity<1)
...{
this.Opacity=this.Opacity+0.05;
}
else
...{
this.timer1.Enabled=false;
}
}
这个实在没有什么新奇的,改透明度而已.
渐变的窗口背景
using
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();
}
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();
}
一般般,没有什么新意.
窗体总在最顶
this
.TopMost
=
true
;
一些朋友老问,所以贴出来.
后面的是我个人比较喜欢用的效果:
多边型窗体
using
System.Runtime.InteropServices;
//
用API的都知道
[DllImport( " gdi32 " )]
private static extern IntPtr CreatePolygonRgn(Point[] lpPoint, int nCount, int nPolyFillMode);
[DllImport( " user32 " )]
private static extern IntPtr SetWindowRgn(IntPtr hWnd,IntPtr hRgn, bool bRedraw);
const int WINDING = 2 ;
private void Form1_Load( object sender, System.EventArgs e)
... {
Point[] pt=...{
new Point(this.Width /2,0),
new Point(0,this.Height/2),
new Point(this.Width/2,this.Height),
new Point(this.Width,this.Height/2),
new Point(this.Width,0)
};
IntPtr m_rgn;
m_rgn=CreatePolygonRgn(pt,5,WINDING);
SetWindowRgn(this.Handle,m_rgn,true);
[DllImport( " gdi32 " )]
private static extern IntPtr CreatePolygonRgn(Point[] lpPoint, int nCount, int nPolyFillMode);
[DllImport( " user32 " )]
private static extern IntPtr SetWindowRgn(IntPtr hWnd,IntPtr hRgn, bool bRedraw);
const int WINDING = 2 ;
private void Form1_Load( object sender, System.EventArgs e)
... {
Point[] pt=...{
new Point(this.Width /2,0),
new Point(0,this.Height/2),
new Point(this.Width/2,this.Height),
new Point(this.Width,this.Height/2),
new Point(this.Width,0)
};
IntPtr m_rgn;
m_rgn=CreatePolygonRgn(pt,5,WINDING);
SetWindowRgn(this.Handle,m_rgn,true);
看看下面的,可能喜欢的人多些.
动画效果
using
System.Runtime.InteropServices;
[System.Runtime.InteropServices.DllImport("user32" )]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
const int AW_HOR_POSITIVE = 0x0001 ;
const int AW_HOR_NEGATIVE = 0x0002 ;
const int AW_VER_POSITIVE = 0x0004 ;
const int AW_VER_NEGATIVE = 0x0008 ;
const int AW_CENTER = 0x0010 ;
const int AW_HIDE = 0x10000 ;
const int AW_ACTIVATE = 0x20000 ;
const int AW_SLIDE = 0x40000 ;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
const int AW_BLEND = 0x80000 ;
private void Form1_Load(object sender, System.EventArgs e)
... {
AnimateWindow(this.Handle,1000, AW_CENTER | AW_ACTIVATE);
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
... {
AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_HIDE | AW_VER_NEGATIVE);
}
[System.Runtime.InteropServices.DllImport("user32" )]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
const int AW_HOR_POSITIVE = 0x0001 ;
const int AW_HOR_NEGATIVE = 0x0002 ;
const int AW_VER_POSITIVE = 0x0004 ;
const int AW_VER_NEGATIVE = 0x0008 ;
const int AW_CENTER = 0x0010 ;
const int AW_HIDE = 0x10000 ;
const int AW_ACTIVATE = 0x20000 ;
const int AW_SLIDE = 0x40000 ;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
const int AW_BLEND = 0x80000 ;
private void Form1_Load(object sender, System.EventArgs e)
... {
AnimateWindow(this.Handle,1000, AW_CENTER | AW_ACTIVATE);
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
... {
AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_HIDE | AW_VER_NEGATIVE);
}
这个可以实现像QQ那样的上拉效果,当然需要把窗体关闭改为鼠标离开事件了,呵呵.