[英]Adding a border color on a form in visual C#
好的,我用以下代碼制作了一個表單: this.FormBorderStyle = FormBorderStyle.None;
好的,我還使用以下代碼添加了邊框半徑:
[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 Form4()
{
InitializeComponent();
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
}
因此,我需要在圍繞邊框半徑彎曲的窗體周圍添加一個小的黑色邊框。 我怎么做?
好的,我添加了它,它可以正常工作,但是它不與邊框配合使用,只是e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));
: e.Graphics.DrawRectangle(Pens.Black, new Rectangle(0, 0, Width - 1, Height - 1));
和這個:
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, ButtonBorderStyle.Solid);
重寫窗體的OnPaintBackground()方法,並使用傳遞的e.Graphics對象,使用Graphics方法簡單地繪制邊框。
請注意,當您使用Region(GraphicsPath)構造函數時,您不必固定電話。 相同的GraphicsPath也會很方便地繪制邊框。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.