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 }

 

转载于:https://www.cnblogs.com/jieliu726/p/4674360.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值