2012-03-13 5 views
1

丸い四角形を作成しようとしていますが、この場合は少し楕円で始めることにしました。残念ながら、カスタムコントロールをFprm1.cs [デザイン]にドラッグしてサイズを変更しようとすると、実際の楕円は何も起こりません。私がusercontrol [design]に入ってサイズを変更したときだけ、変更されます。誰かが私が間違っているところを指摘できるなら、私はそれを感謝します。ありがとう。ユーザーコントロールのサイズを変更する

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Drawing; 
using System.Drawing.Drawing2D; 

namespace CustomPbar 
{ 
    public partial class Pbar : UserControl 
    { 
     GraphicsPath path = new GraphicsPath(); 

     public Pbar() 
     { 
      InitializeComponent(); 
      path.AddEllipse(0, 0, this.ClientSize.Width, this.ClientSize.Height); 
      this.Region = new Region(path); 

      this.BackColor = SystemColors.ControlDarkDark; 
     } 

     private void MyForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e) 
     { 
      if (this.Region != null) 
      { 
       this.Region.Dispose(); 
       this.Region = null; 
      } 

      path.AddEllipse(0, 0, this.Width, this.Height); 
      this.Region = new Region(path); 
     } 
    } 
} 

答えて

1

Resizeイベントからそれを呼び出してみてください非常に

protected override void OnResize(EventArgs e) { 
    using (GraphicsPath gp = new GraphicsPath()) { 
    gp.AddEllipse(this.ClientRectangle); 
    this.Region = new Region(gp); 
    } 

    base.OnResize(e); 
} 
+0

感謝を。 –

関連する問題