PDA

View Full Version : آموزش: فرم دایره ای برای فرم



alexmcse
دوشنبه 14 بهمن 1392, 11:22 صبح
private void Form1_Load(object sender, EventArgs
e)
{
this.Height = 550;
this.Width = 350;
//Creating circle path
System.Drawing.Drawing2D.GraphicsPath path
= new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(0, 0, 600, 300);
//Creating the region from the circle path
this.Region = new Region(path);
this.Show();
}

MMR_1234
دوشنبه 14 بهمن 1392, 16:16 عصر
با سپاس از آموزش

اگر بخوام این فرم رو بصورت فرم مادر دربیارم و دیگر فرمها با ارث بری از این فرم تشکیل بشن چه روشی داره؟

alexmcse
چهارشنبه 16 بهمن 1392, 14:22 عصر
با سپاس از آموزش

اگر بخوام این فرم رو بصورت فرم مادر دربیارم و دیگر فرمها با ارث بری از این فرم تشکیل بشن چه روشی داره؟

کد نمونه
//کلاس اصلی
class MainForm : System.Windows.Forms.Form
{
public MainForm()
{
this.StartPosition = FormStartPosition.CenterScreen;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Class1 _Paint);
System.Windows.Forms.Button b = new Button();
b.Location = new Point(115,120);
b.Size = new System.Drawing.Size(40, 23);
b.Text = "close";
b.BackColor = Color.Red;
this.Controls.Add(b);
b.Click +=new System.EventHandler (b_Click);
}
private void b_Click(object sender, EventArgs e)
{
this.Close();
}
private void Class1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
shape.AddEllipse (0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(shape);
}

}
//کلاس مشتق شده از کلاس اصلی
class DeriveForm1 : MainForm
{
public DeriveForm1()
{
MainForm c = new MainForm();
c.BackColor = Color.Gold ;
c.ShowDialog();
}

}
//کلاس مشتق شده از کلاس اصلی
class DeriveForm3:MainForm
{
public DeriveForm3()
{
MainForm c = new MainForm();
c.BackColor = Color.GreenYellow ;
c.ShowDialog();
}
}
//طریقه استفاده
private void Form1_Load(object sender, EventArgs e)
{
DeriveForm1 c2 = new DeriveForm1();
DeriveForm3 c3 = new DeriveForm3();
}

دکمه کلوز را برای فرم گذاشتم