12

ピクチャーボックスコントロールでエッジを丸める方法。楕円のような角度を取得したいのですが、その方法がわかりません。私はC#を使用しています。ありがとう!

4

4 に答える 4

17

はい、問題ありません。Region プロパティを使用して、コントロールに任意の形状を与えることができます。プロジェクトに新しいクラスを追加し、以下に示すコードを貼り付けます。コンパイル。ツールボックスの上部から新しいコントロールをフォームにドロップします。

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

class OvalPictureBox : PictureBox {
    public OvalPictureBox() {
        this.BackColor = Color.DarkGray;
    }
    protected override void OnResize(EventArgs e) {
        base.OnResize(e);
        using (var gp = new GraphicsPath()) {
            gp.AddEllipse(new Rectangle(0, 0, this.Width-1, this.Height-1));
            this.Region = new Region(gp);
        }
    }
}
于 2011-10-11T20:19:33.403 に答える
11

を丸くするようにエッジを丸めますか?

もしそうなら、 http://social.msdn.microsoft.com/forums/en-US/winforms/thread/603084bb-1aae-45d1-84ae-8544386d58fdをチェックしてください

Rectangle r = new Rectangle(0, 0, pictureBox1.Width, pictureBox1.Height);
System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
int d = 50;
gp.AddArc(r.X, r.Y, d, d, 180, 90);
gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
pictureBox1.Region = new Region(gp);
于 2011-10-11T20:16:58.750 に答える