-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelEx.cs
More file actions
76 lines (70 loc) · 2.36 KB
/
PanelEx.cs
File metadata and controls
76 lines (70 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NotepadSharp
{
//Ref: https://www.cnblogs.com/JiYF/p/9047559.html
//Override the Panel control to add border prop
public partial class PanelEx : Panel
{
public PanelEx()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
}
public PanelEx(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private Color _BorderColor = Color.Black;
[Browsable(true), Description("边框颜色"), Category("自定义分组")]
public Color BorderColor
{
get => _BorderColor;
set
{
_BorderColor = value;
Invalidate();
}
}
private int _BorderSize = 1;
[Browsable(true), Description("边框粗细"), Category("自定义分组")]
public int BorderSize
{
get => _BorderSize;
set
{
_BorderSize = value;
Invalidate();
}
}
/// <summary>
/// 重写OnPaint方法
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
ClientRectangle,
_BorderColor,
_BorderSize,
ButtonBorderStyle.Solid,
_BorderColor,
_BorderSize,
ButtonBorderStyle.Solid,
_BorderColor,
_BorderSize,
ButtonBorderStyle.Solid,
_BorderColor,
_BorderSize,
ButtonBorderStyle.Solid);
}
}
}