ǰλãҳ > 用C#制作 个性化窗体 winform 界面 - 百度文库
{
x = hitX; y = hitY; }
public override void Action(int ScreenX, int ScreenY, System.Windows.Forms.Form form) {
form.Location = new Point(ScreenX - x, ScreenY - y); } }
ǿʼд¼Ĵ룬ȶ弸
private int LEFT = 5, RIGHT = 5, BOTTOM = 5, TOP = 5, TITLE_WIDTH = 45;//߿ͱĴС private int x = 0, y = 0;//ʱ private MouseAction mouse;//¼Ӧ
ȻFormMouseDown¼м¼ĵǰ꣺ x = e.X; y = e.Y;
eΪSystem.Windows.Forms.MouseEventArgs Ȼٸ궨¼Ӧ //ϱ߿
if((e.X <= LEFT + 10 && e.Y <= TOP) || (e.Y <= TOP + 10 && e.X <= LEFT)) ...{
mouse = new MouseSizeTopLeft(Location.X, Location.Y, Width, Height); return; }
//Ȼе¼ҲֱӦ //ϵͳرհŦ
if(e.X > Width - 20 && e.Y > 6 && e.X < Width - 20 + SysButton_Min.Width && e.Y < 6 + SysButton_Min.Height) ...{ Close(); return; }
//ֵ¼ӦʵMouseMove¼ɵģ
private void Form_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) ...{
this.Parent.Cursor = CheckCursorType(e.X, e.Y);//ıָ״ if(mouse != null) ...{
mouse.Action(Control.MousePosition.X, Control.MousePosition.Y, this);//ִʱӦ //עControl.MousePosition̬ģֵΪϵȫ } }
//ÿͬλָ״ private Cursor CheckCursorType(int X, int Y) ...{
if(((X <= LEFT + 10 && Y <= TOP) || (Y <= TOP + 10 && X <= LEFT)) || ((X >= Width - RIGHT - 10 && Y >= Height - BOTTOM) || (Y >= Height - BOTTOM - 10 && X >= Width - RIGHT))) ...{
return Cursors.SizeNWSE; }
else if(((Y <= TOP + 10 && X >= Width - RIGHT) || (Y <= TOP && X >= Width - RIGHT - 10)) || ((X <= LEFT && Y >= Height - BOTTOM - 10) || (Y >= Height - BOTTOM && X <= LEFT + 10))) ...{
return Cursors.SizeNESW; }
else if(X >= Width - RIGHT || X <= LEFT) ...{
return Cursors.SizeWE; }
else if(Y >= Height - BOTTOM || Y <= TOP) ...{
return Cursors.SizeNS; } else
...{
return Cursors.Arrow; } }
//MouseUp¼нmouseͷŵ
private void Form_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) ...{
mouse = null; }
//Ϊ˸ӱ棬Լϱ˫ԭ¼ private void Form_DoubleClick(object sender, System.EventArgs e) ...{
if(y > TOP && y < TITLE_WIDTH) ...{
if(WindowState == FormWindowState.Normal) ...{
WindowState = FormWindowState.Maximized; SysButton = SysButton_Restore; Invalidate(); }
else if(WindowState == FormWindowState.Maximized) ...{
WindowState = FormWindowState.Normal; SysButton = SysButton_Max; Invalidate(); } } }
ֹ屻Сһ㣬øڵMinimumSizeһʵֵ200,200 ܽ
ڱijԣĴѾӵӵеȫܣһڲۣͬһӻ²ôŪģˣ˱˻֪Ͽóȥҫһ°
ʵʩУôҲҪƸıСmouseMoveϸcontrolPaintĻϻ
µʱҲһ˸ǿһļУû˸ɷ֪Ϊʲô
[0]
ש[0]
Ĺؼָʾ100 #6¥ ÷֣0ظڣ2008-03-27 13:55:48 Ĵڹ캯µͲˣ es.ResizeRedraw, true); ʱҪԴлơ this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | Ctlhx ) ѫ [0] ש[0] ٱ TOP #7¥ ÷֣0ظڣ2008-03-27 14:04:25 οһĴ룬һޱߵĴлƣ
92ƪĵ