本文介绍了如何更改Windows边框样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我开发新的教育软件。但我不想使用Windows边框样式。所以我需要更改Windows边框样式或者我需要创建新的表单样式。 我将在本月底交付这个项目。因此,有人向我建议简单的方法吗? 受保护 覆盖 void WndProc( ref 消息m) { const UInt32 WM_NCHITTEST = 0x0084; const UInt32 WM_MOUSEMOVE = 0x0200; const UInt32 HTLEFT = 10 ; const UInt32 HTRIGHT = 11 ; const UInt32 HTBOTTOMRIGHT = 17 ; const UInt32 HTBOTTOM = 15 ; const UInt32 HTBOTTOMLEFT = 16 ; const UInt32 HTTOP = 12 ; const UInt32 HTTOPLEFT = 13 ; const UInt32 HTTOPRIGHT = 14 ; const int RESIZE_HANDLE_SIZE = 10 ; bool handling = false ; if (m.Msg == WM_NCHITTEST || m.Msg == WM_MOUSEMOVE) { Size formSize = 此 .Size; Point screenPoint = new Point(m.LParam.ToInt32()); 指向clientPoint = 此 .PointToClient(screenPoint); 字典< UInt32,矩形> boxes = new 字典< UInt32,Rectangle>(){ {HTBOTTOMLEFT, new 矩形( 0 ,formSize.Height - RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTBOTTOM, new 矩形(RESIZE_HANDLE_SIZE,formSize.Height - RESIZE_HANDLE_SIZE,formSize.Width - 2 * RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTBOTTOMRIGHT,矩形(formSize.Width - RESIZE_HANDLE_SIZE,formSize.Height - RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTRIGHT, new 矩形(formSize.Width - RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE,formSize。高度 - 2 * RESIZE_HANDLE_SIZE)}, {HTTOPRIGHT, new 矩形(formSize.Width - RESIZE_HANDLE_SIZE, 0 ,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTTOP, new 矩形(RESIZE_HANDLE_SIZE, 0 ,formSize.Width - 2 * RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTTOPLEFT, new 矩形( 0 , 0 ,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE)}, {HTLEFT, new 矩形( 0 ,RESIZE_HANDLE_SIZE,RESIZE_HANDLE_SIZE,formSize.Height - 2 * RESIZE_HANDLE_SIZE)} }; foreach (KeyValuePair< UInt32,矩形> hitBox 在框中) { if (hitBox.Value.Contains(clientPoint)) { m.Result =( IntPtr的)hitBox.Key; 处理= true ; break ; } } } 如果(!处理) base .WndProc( ref m); } 我发现这个代码块但是效果不好。我的表单必须完全可以调整大小。 我在等你的帮助。谢谢你的答案... 解决方案 这是启用移动和重新调整没有TitleBar,FormBorderStyle设置为'None等的WinForm的典型示例。 此处使用的策略是: 1.定义两个区域:鼠标按住并移动的区域将移动窗体,以及鼠标按住并移动的区域将重新调整表格大小。 2.在MouseDown EventHandler中检查这两个区域中的任何一个区域,并设置布尔标记。 3.在MouseMove EventHandler中采取适当的行动。 4.如果表格已重新调整大小,请重置在t中重新调整区域表格调整大小EventHandler: 使用系统; 使用 System.Drawing; 使用 System.Windows.Forms; 命名空间 ResizableMovableForm { public partial class Form1:Form { public Form1() { InitializeComponent(); } private Rectangle MoveZone; private Rectangle ResizeZone; private const int HitZoneSize = 12 ; private bool isMoving = 假; private bool isResizing = false ; private bool IsMouseUp = false ; private int startWidth,startHeight,startMouseX,startMouseY; private int newWidth,newHeight; private void Form1_Load( object sender,EventArgs e) { MoveZone = new 矩形( 0 , 0 ,HitZoneSize,HitZoneSize); ResizeZone = new 矩形(宽度 - HitZoneSize,高度 - HitZoneSize,HitZoneSize,HitZoneSize); } private void button1_Click( object sender,EventArgs e) {} private void Form1_MouseUp( object sender,MouseEventArgs e) { IsMouseUp = 真; isMoving = false ; isResizing = false ; } private void Form1_MouseDown( object sender,MouseEventArgs e) { startMouseX = eX; startMouseY = e.Y; startWidth = 此 .Width; startHeight = 此 .Height; if (MoveZone.Contains(e.Location)) { isMoving = 真; IsMouseUp = false ; return ; } 如果(ResizeZone.Contains(e.Location)) { isResizing = true ; IsMouseUp = false ; return ; } } 私有 void Form1_MouseMove( object sender,MouseEventArgs e) { if (IsMouseUp)返回; if (isMoving) { this .Left + = eX - startMouseX; this .Top + = e.Y - startMouseY; return ; } else { if (isResizing ) { newWidth = startWidth + eX - startMouseX; if (newWidth < this .MinimumSize.Width || newWidth > this .MaximumSize.Width)返回; 此 .Width = newWidth; newHeight = startHeight + e.Y - startMouseY; if (newHeight < this .MinimumSize.Height || newHeight > this .MaximumSize.Height)返回; 此 .Height = newHeight; } } } private void Form1_Resize( object sender,EventArgs e) { ResizeZone = new 矩形(宽度 - HitZoneSize,高度 - HitZoneSize,HitZoneSize,HitZoneSize); } } } 注意: 1.我强烈建议你设定适当的最低价格表格和设计时的最大尺寸。上面的代码(用于重新调整大小)取决于对这些属性有一些有意义的值。 2.即使使用Form的DoubleBuffer属性设置为'true,可能会有一些重新调整大小的图形副作用,使用SuspendLayout和ResumeLayout无法控制。 Hi everyone,I developing new software for education. But I don't wanna use Windows Border Style. So I need to change Windows Border Style or I need to create new Form Style.I will deliver this project end of this month. Because of this, anyone suggest to me simple way?protected override void WndProc(ref Message m) { const UInt32 WM_NCHITTEST = 0x0084; const UInt32 WM_MOUSEMOVE = 0x0200; const UInt32 HTLEFT = 10; const UInt32 HTRIGHT = 11; const UInt32 HTBOTTOMRIGHT = 17; const UInt32 HTBOTTOM = 15; const UInt32 HTBOTTOMLEFT = 16; const UInt32 HTTOP = 12; const UInt32 HTTOPLEFT = 13; const UInt32 HTTOPRIGHT = 14; const int RESIZE_HANDLE_SIZE = 10; bool handled = false; if (m.Msg == WM_NCHITTEST || m.Msg == WM_MOUSEMOVE) { Size formSize = this.Size; Point screenPoint = new Point(m.LParam.ToInt32()); Point clientPoint = this.PointToClient(screenPoint); Dictionary<UInt32, Rectangle> boxes = new Dictionary<UInt32, Rectangle>() { {HTBOTTOMLEFT, new Rectangle(0, formSize.Height - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)}, {HTBOTTOM, new Rectangle(RESIZE_HANDLE_SIZE, formSize.Height - RESIZE_HANDLE_SIZE, formSize.Width - 2*RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)}, {HTBOTTOMRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, formSize.Height - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE)}, {HTRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, formSize.Height - 2*RESIZE_HANDLE_SIZE)}, {HTTOPRIGHT, new Rectangle(formSize.Width - RESIZE_HANDLE_SIZE, 0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE) }, {HTTOP, new Rectangle(RESIZE_HANDLE_SIZE, 0, formSize.Width - 2*RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE) }, {HTTOPLEFT, new Rectangle(0, 0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE) }, {HTLEFT, new Rectangle(0, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, formSize.Height - 2*RESIZE_HANDLE_SIZE) } }; foreach (KeyValuePair<UInt32, Rectangle> hitBox in boxes) { if (hitBox.Value.Contains(clientPoint)) { m.Result = (IntPtr)hitBox.Key; handled = true; break; } } } if (!handled) base.WndProc(ref m); }I found this code block but it isn't work very well. My form must to be perfectly Resizable.I waiting for your help. Thanks for answers... 解决方案 这篇关于如何更改Windows边框样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-12 14:41