WinForm窗体效果

  1. 无边框移动
    [DllImport("user32.dll")]
    public static extern bool ReleaseCapture();
    [DllImport("user32.dll")]
    public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam);
    public const int WM_SYSCOMMAND = 0x0112;
    public const int SC_MOVE = 0xF010;
    public const int HTCAPTION = 0x0002;
    [DllImport("user32")]
    private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, IntPtr lParam);
    private const int WM_SETREDRAW = 0xB;
    private void DoFormMoving()
    {
    if (this.WindowState == FormWindowState.Normal)
    {
    ReleaseCapture();
    SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
    }
    }
    

      

    1. 第二种:
       protected override void WndProc(ref Message m)
              {
                  if (m.Msg == 163 && this.ClientRectangle.Contains(this.PointToClient(new Point(m.LParam.ToInt32()))) && m.WParam.ToInt32() == 2)
                      m.WParam = (IntPtr)1;
                  base.WndProc(ref m);
                  if (m.Msg == 132 && m.Result.ToInt32() == 1)
                      m.Result = (IntPtr)2;
              }
      

        

  2. 窗体圆角:
    1.  第一种:   
       public void SetWindowRegion()
              {
                  System.Drawing.Drawing2D.GraphicsPath FormPath;
                  FormPath = new System.Drawing.Drawing2D.GraphicsPath();
                  Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
                  FormPath = GetRoundedRectPath(rect, 10);//10为圆色半径
                  this.Region = new Region(FormPath);
              }
      
              private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
              {
                  int diameter = radius;
                  Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
                  GraphicsPath path = new GraphicsPath();
      
                  path.AddArc(arcRect, 180, 90);//左上角
      
                  arcRect.X = rect.Right - diameter;//右上角
                  path.AddArc(arcRect, 270, 90);
      
                  arcRect.Y = rect.Bottom - diameter;// 右下角
                  path.AddArc(arcRect, 0, 90);
      
                  arcRect.X = rect.Left;// 左下角
                  path.AddArc(arcRect, 90, 90);
                  path.CloseFigure();
                  return path;
              }
      
       private void frmLogin_Resize(object sender, EventArgs e)
              {
                  if (this.WindowState == FormWindowState.Normal)
                  {
                      SetWindowRegion();
                  }
                  else
                  {
                      this.Region = null;
                  }
              }
      

        

        

 

 

  1. 窗体阴影
  2.    public const int CS_DropSHADOW = 0x20000;
            public const int GCL_STYLE = (-26);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int GetClassLong(IntPtr hwnd, int nIndex);
    
     public frmLogin()
            {
                InitializeComponent();
                SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW); 
            }

     

 

  

 

上一篇:C# 关于打印 - PrintRaw


下一篇:[C#] 使用Win32 API嵌入窗口,键盘、鼠标光标不响应问题解决