12

このコードを使用して、角が丸いフォーム (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 Form1()
{
    InitializeComponent();
    Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
}

そして、これは Paint イベントにカスタム境界線を設定します:

    ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid, Color.Black, 5, ButtonBorderStyle.Solid);

しかし、これを見てくださいスクリーンショット

内側のフォームの四角形には、丸みを帯びたエッジがありません。

スクリーンショットのように見えないように、フォームの長方形の内側の青いエッジも丸くするにはどうすればよいですか?

4

2 に答える 2

9

Region プロパティは単純に角を切り取ります。角を真に丸くするには、角の丸い長方形を描く必要があります。

角丸四角形の描画

好きな形のイメージを描いて、透明なフォームに貼り付けると簡単かもしれません。描くのは簡単ですが、サイズを変更することはできません。

于 2011-02-23T14:40:37.510 に答える