47 votes

Image claire sur la boîte à images

Comment puis-je effacer l'image dessinée sur la boîte à images ? Ce qui suit ne m'aide pas :

pictbox.Image = null;
pictbox.Invalidate();

Aidez-moi, s'il vous plaît.

EDIT

private void pictbox_Paint(object sender, PaintEventArgs e) 
{ 
     Graphics g = e.Graphics; 
     vl.Draw(g, ref tran.realListForInsert); 
} 

public void Draw(Graphics g, ref List<double> arr) 
{ 
    g.DrawRectangle(new Pen(Brushes.Red, 3), nodeArr[Convert.ToInt32(templstName)].pict.Location.X, nodeArr[Convert.ToInt32(templstName)].pict.Location.Y, 25, 25); 
    g.DrawRectangle(new Pen(Brushes.Green, 3), nodeArr[Convert.ToInt32(templstArgName)].pict.Location.X, nodeArr[Convert.ToInt32(templstArgName)].pict.Location.Y, 25, 25); 
    nodeArr[Convert.ToInt32(templstName)].text.Text = arr[Convert.ToInt32(templstArgName)].ToString(); 
    arr[Convert.ToInt32(templstName)] = arr[Convert.ToInt32(templstArgName)]; 
}

-1voto

C'est si simple ! Vous pouvez y aller avec votre événement de clic de bouton, Je l'ai utilisé avec un bouton propriété Nom : "btnClearImage"

// Note 1a:
// after clearing the picture box 
// you can also disable clear button 
// by inserting follwoing one line of code:

btnClearImage.Enabled = false   

// Note 1b:
// you should set your button Enabled property
// to "False"
// after that you will need to Insert 
// the following line to concerned event or button
// that load your image into picturebox1 
// code line is as follows:

btnClearImage.Enabled = true;

-2voto

Vous devriez essayer. Lorsque vous effacez vos graphiques, vous devez choisir une couleur. SystemColors.Control est la couleur native du formulaire.

Graphics g = pB.CreateGraphics();
g.Clear(SystemColors.Control);

-2voto

effacer pictureBox en c# winform Application Méthode simple pour effacer une pictureBox en c# winform Application

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X