پاک شدن picturebox پس از کشیدن دایره
با عرض سلام خدمت استادان عزیز
من یه مشکل دارم هر کس بتونه مشکلمو حل کنه ازش خیلی ممنون می شم
من یک usercontrol نوشتم که توش یه دایره و چند آبجکت گرافیکی دیگر کشیده ام مشکل من اینجاست که وقتی که این user control رو روی یه فرم میارمش و فرم رو دراگ اند دراپ می کنم تمام اجزایی که روی picture box کشیدم پاک میشه . یا بهتر بگم وقتی یک فرم دیگه میاد روی پیکچر باکس هر چی زیر فرم باشه پاک میشه
من برنامه ام رو به صورت زیر نوشتم
public void draw circl()
{
Bitmap buffer = new Bitmap(1024,678);
using (Graphic content=Graphid.drawImage(buffer))
{
content.FillEllipse(.....);
this.picturebox1.CreateGraphics().drawImage(buffer );
buffer1.dispose();
}
}
از تمام شما دوستان فعال ممنونم
نقل قول: پاک شدن پیکچر باکس پس از کشیدن دایره
حالا که از bitmap استفاده کردی تمام اشکال را روی اون بکش و بعد به پیکچرباکس انتساب بده.
public void drawcircl()
{
Bitmap buffer = new Bitmap(1024, 678);
using (Graphics g = Graphics.FromImage(buffer))
{
g.FillEllipse(Brushes.Blue, new RectangleF(0, 0, buffer.Width, buffer.Height));
this.pictureBox1.Image = buffer;
}
}
نقل قول: پاک شدن پیکچر باکس پس از کشیدن دایره
متوجه شدم باید در رویداد OnPaint کار ترسیم رو دوباره انجام بدید.
مشکل شما رو اینجوری گفته:http://msdn.microsoft.com/en-us/libr...l.onpaint.aspx
The following code example enables the user to drag an image or image file onto the form, and have it be displayed at the point on which it is dropped. The OnPaint method is overridden to repaint the image each time the form is painted; otherwise the image would only persist until the next repainting.
private Image picture;
private Point pictureLocation;
public Form1()
{
// Enable drag-and-drop operations and
// add handlers for DragEnter and DragDrop.
this.AllowDrop = true;
this.DragDrop += new DragEventHandler(this.Form1_DragDrop);
this.DragEnter += new DragEventHandler(this.Form1_DragEnter);
}
protected override void OnPaint(PaintEventArgs e)
{
// If there is an image and it has a location,
// paint it when the Form is repainted.
base.OnPaint(e);
if(this.picture != null && this.pictureLocation != Point.Empty)
{
e.Graphics.DrawImage(this.picture, this.pictureLocation);
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
// Handle FileDrop data.
if(e.Data.GetDataPresent(DataFormats.FileDrop) )
{
// Assign the file names to a string array, in
// case the user has selected multiple files.
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
try
{
// Assign the first image to the picture variable.
this.picture = Image.FromFile(files[0]);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// Handle Bitmap data.
if(e.Data.GetDataPresent(DataFormats.Bitmap) )
{
try
{
// Create an Image and assign it to the picture variable.
this.picture = (Image)e.Data.GetData(DataFormats.Bitmap);
// Set the picture location equal to the drop point.
this.pictureLocation = this.PointToClient(new Point(e.X, e.Y) );
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}
// Force the form to be redrawn with the image.
this.Invalidate();
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
// If the data is a file or a bitmap, display the copy cursor.
if (e.Data.GetDataPresent(DataFormats.Bitmap) ||
e.Data.GetDataPresent(DataFormats.FileDrop) )
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
نقل قول: پاک شدن پیکچر باکس پس از کشیدن دایره
تشکر از دوستان عزیز مشکل حل شد ممنون