我有一個橢圓形的圖畫框(下面的代碼)。我想在畫框周圍添加邊框。我已經嘗試添加第二個矩形,但這隻會使我的區域變小。有什麼辦法可以製作邊框嗎?在橢圓形的圖畫框周圍繪製邊框
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class OvalPictureBox : PictureBox
{
public OvalPictureBox()
{
}
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);
}
}
private void InitializeComponent()
{
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
this.SuspendLayout();
//
// OvalPictureBox
//
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
this.ResumeLayout(false);
}
}
編輯
我想通了。我只是在畫箱中畫一個橢圓。
float penWidth = 5F;
Pen myPen = new Pen(Color.FromArgb(242, 141, 1), penWidth);
e.Graphics.DrawEllipse(myPen, new RectangleF(new PointF(0, 0), new
SizeF((float)(portraitPicture.Width - 1), portraitPicture.Height - 1)));
myPen.Dispose();
有沒有更清潔或更好的方法?或者這是最好的方法?
這是我給你的解決方案:) –
哦,所以我確實想念你,哈哈:)謝謝! – Backs