鳕鱼天空

This is Mr Wang's Tech Blog.

None 模式Winform鼠标改变窗口大小

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;
    }
}

 

C#无焦点按钮(非自定义控件)


using System.Reflection  
  
Private void SetButton(Button button)  
{  
  MethodInfo methodinfo = button.GetType().GetMethod("SetStyle",BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);  
  methodinfo.Invoke(button,BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod,null,new object[] {ControlStyles.Selectable,false},Application.CurrentCulture);  
}  

效果:

==============================================

点击后不得到焦点且不影响当前焦点所在位置,类似系统计算器中按钮的效果。

可以实现无焦点的按钮、复选框、单选框、进度条等控件。

==============================================

转载请注明来源。

来源:http://blog.csdn.net/all77889900/article/details/5832415