2011-10-11 174 views

回答

14

好的,沒問題,你可以給一個控制其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); 
     } 
    } 
} 
+0

啊,謝謝你!它確實爲您提供延伸課程時所具備的可能性的圖像。在工具箱中獲得修改組件是多麼容易。 :) – Arndroid

9

回合邊緣在回合中角落

如果是退房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); 
10

把表格1張圖片框和編寫代碼 也可以改變寬度的旁邊的負號和高度,以獲得最好的結果

System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath(); 
      gp.AddEllipse(0, 0, pictureBox1.Width - 3, pictureBox1.Height - 3); 
      Region rg = new Region(gp); 
      pictureBox1.Region = rg; 

enter image description here

+0

謝謝,這是必要的語法量的一個很好的解決方案。我還沒有測試過這個畫的資源,但我現在喜歡它。另外,不錯的圖片:P – soulshined

0

謝謝,漢斯。但我也需要一個光滑的外觀。我在這個主題上做了一些研究,但是我找不到解決方案。然後我嘗試自己做,並找到下面的解決方案。也許別人需要它。

protected override void OnPaint(PaintEventArgs e) 
    { 
     base.OnPaint(e); 
     using (GraphicsPath gp = new GraphicsPath()) 
     { 
      gp.AddEllipse(0, 0, this.Width - 1, this.Height - 1); 
      Region = new Region(gp); 
      e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; 
      e.Graphics.DrawEllipse(new Pen(new SolidBrush(this.BackColor), 1), 0, 0, this.Width - 1, this.Height - 1); 
     } 
    }