• Winform 无边框窗口移动自定义边框粗细颜色


     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Data;
     5 using System.Drawing;
     6 using System.Linq;
     7 using System.Text;
     8 using System.Threading.Tasks;
     9 using System.Windows.Forms;
    10 
    11 namespace WinGPChat.master
    12 {
    13     public partial class formBase : Form
    14     {
    15         public formBase()
    16         {
    17             InitializeComponent();            
    18         }
    19         private Point mPoint = new Point();
    20         private void formBase_Load(object sender, EventArgs e)
    21         {
    22             this.MouseDown+=formBase_MouseDown;
    23             this.MouseMove+=formBase_MouseMove;            
    24         }
    25 
    26         protected void formBase_MouseMove(object sender, MouseEventArgs e)
    27         {
    28             if (e.Button == MouseButtons.Left)
    29             {
    30                 Point myPosittion = MousePosition;
    31                 myPosittion.Offset(-mPoint.X, -mPoint.Y);
    32                 this.FindForm().Location = myPosittion;
    33             }
    34         }
    35 
    36         protected void formBase_MouseDown(object sender, MouseEventArgs e)
    37         {
    38             mPoint.X = e.X;
    39             mPoint.Y = e.Y;
    40         }
    41 
    42         /// <summary>
    43         /// 重写Paint实现细边框
    44         /// </summary>
    45         /// <param name="e"></param>
    46         protected override void OnPaint(PaintEventArgs e)
    47         {
    48             Pen pen = new Pen(Color.Gray,1);
    49             e.Graphics.DrawLine(pen, new Point(0, 0), new Point(this.Width-1, 0));   //
    50             e.Graphics.DrawLine(pen, new Point(0, 0), new Point(0, this.Height-1));  //
    51             e.Graphics.DrawLine(pen, new Point(this.Width-1, 0), new Point(this.Width-1, this.Height-1));//
    52             e.Graphics.DrawLine(pen, new Point(0, this.Height-1), new Point(this.Width-1, this.Height-1));//
    53             base.OnPaint(e);
    54         }
    55 
    56         /// <summary>
    57         /// 无边框重写点击icon实现窗体最大化和最小化
    58         /// </summary>
    59         protected override CreateParams CreateParams
    60         {
    61             get
    62             {
    63                 CreateParams cp = base.CreateParams;
    64                 cp.Style = cp.Style | 0x20000;//允许最小化操作
    65                 return cp;
    66             }
    67         }
    68 
    69            
    70     }
    71 }
  • 相关阅读:
    前端一些词汇的缩写
    github上值得关注的前端项目
    window注册表
    注册表删除chrome插件
    js二维码扫描
    git push --no-thin
    mac下app store 无法完成您的购物操作
    git终端提示符
    mac 下 apache设置
    windows 下 apache设置
  • 原文地址:https://www.cnblogs.com/jieliu726/p/4674360.html
Copyright © 2020-2023  润新知