【发布时间】:2020-12-02 19:40:11
【问题描述】:
是否可以创建具有圆形边框并具有边框颜色的表单? 我尝试了以下方法:
protected override void OnPaint(PaintEventArgs e) {
ControlPaint.DrawBorder(e.Graphics, ClientRectangle, Color.NavajoWhite,
ButtonBorderStyle.Solid);
}
和
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
public Main() {
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 18, 18));
}
这是结果:
我也试过了:
protected override void OnPaint(PaintEventArgs e) {
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.White, 1, ButtonBorderStyle.Solid, Color.White, 1, ButtonBorderStyle.Solid, Color.White, 2, ButtonBorderStyle.Solid, Color.White, 2, ButtonBorderStyle.Solid);
}
这是结果:
我离第二个太近了,但是如何扩展圆边上的颜色边框?
【问题讨论】:
-
我希望您需要绘制一条与圆角相匹配的路径。