PDA

View Full Version : zoom کردن در فرم اصلی



mahan123
پنج شنبه 03 اردیبهشت 1388, 13:55 عصر
:متفکر::گریه:سلام من چه جوری می تونم یک شکلی که لر روی فرم رسم شده است رو تغییر اندازه بدم(ZoomInو Zoom Out)

prankster
پنج شنبه 03 اردیبهشت 1388, 15:53 عصر
public partial class Form1 : Form
{
Graphics myGraphics;

public Form1()
{
InitializeComponent();
this.Shown += new EventHandler(Form1_Shown);
}

void Form1_Shown(object sender, EventArgs e)
{
Button ButtonZoomIn = new Button();
ButtonZoomIn.Text = "Zoom In";
ButtonZoomIn.Location = new Point(0, 0);
Controls.Add(ButtonZoomIn);

Button ButtonZoomOut = new Button();
ButtonZoomOut.Text = "Zoom Out";
ButtonZoomOut.Location = new Point(100, 0);
Controls.Add(ButtonZoomOut);

ButtonZoomIn.Click += (s, args) =>
{
drawRectangle();
myGraphics.ScaleTransform(2.0F, 2.0F);
drawRectangle();
};

ButtonZoomOut.Click += (s, args) =>
{
drawRectangle();
myGraphics.ScaleTransform(0.5F, 0.5F);
drawRectangle();
};

myGraphics = this.CreateGraphics();
drawRectangle();
}

void drawRectangle()
{
myGraphics.Clear(this.BackColor);
Rectangle rect = new Rectangle(50, 50, 100, 100);
SolidBrush brush = new SolidBrush(Color.Black);
myGraphics.FillRectangle(brush, rect);
}
}