积极答复者
请教一个窗口界面的问题

问题
-
我的想窗口的boder使用None这种平面的方式,但又需要可以使用鼠标更改窗体大小. 如果使用sizable则,窗口四周会有一个边框
请问如何如何none这种无边框的窗口,并且可以改变窗口大小- 已移动 Sheng Jiang 蒋晟Moderator 2010年3月27日 19:08 System.Windows.Forms (发件人:Visual C#)
答案
-
你好!下面是我以前回复的帖子,包含了拖动与改变大小。
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2010年3月19日 5:47
全部回复
-
使用API
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ExportQuestion { public partial class Form8 : Form { public Form8() { InitializeComponent(); } private bool isMouseDown = false; private Point FormLocation; //form的location private Point mouseOffset; //鼠标的按下位置 private void Form8_MouseMove(object sender, MouseEventArgs e) { int _x = 0; int _y = 0; if (isMouseDown) { Point pt = Control.MousePosition; _x = mouseOffset.X - pt.X; _y = mouseOffset.Y - pt.Y; this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y); } } private void Form8_MouseUp(object sender, MouseEventArgs e) { isMouseDown = false; } private void Form8_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { isMouseDown = true; FormLocation = this.Location; mouseOffset = Control.MousePosition; } } const int WM_NCHITTEST = 0x0084; const int HTLEFT = 10; const int HTRIGHT = 11; const int HTTOP = 12; const int HTTOPLEFT = 13; const int HTTOPRIGHT = 14; const int HTBOTTOM = 15; const int HTBOTTOMLEFT = 0x10; const int HTBOTTOMRIGHT = 17; protected override void WndProc(ref Message m) { base.WndProc(ref m); switch (m.Msg) { case WM_NCHITTEST: Point vPoint = new Point((int)m.LParam & 0xFFFF, (int)m.LParam >> 16 & 0xFFFF); vPoint = PointToClient(vPoint); if (vPoint.X <= 5) if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOPLEFT; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOMLEFT; else m.Result = (IntPtr)HTLEFT; else if (vPoint.X >= ClientSize.Width - 5) if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOPRIGHT; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOMRIGHT; else m.Result = (IntPtr)HTRIGHT; else if (vPoint.Y <= 5) m.Result = (IntPtr)HTTOP; else if (vPoint.Y >= ClientSize.Height - 5) m.Result = (IntPtr)HTBOTTOM; break; } } } }
努力+方法=成功 -
你好!下面是我以前回复的帖子,包含了拖动与改变大小。
知识改变命运,奋斗成就人生!- 已标记为答案 KeFang Chen 2010年3月19日 5:47