Dessin effacé par un form avec la class Graphics

Résolu
cs_metos Messages postés 168 Date d'inscription vendredi 18 janvier 2002 Statut Membre Dernière intervention 19 octobre 2009 - 13 juin 2008 à 09:48
cs_metos Messages postés 168 Date d'inscription vendredi 18 janvier 2002 Statut Membre Dernière intervention 19 octobre 2009 - 13 juin 2008 à 11:08
Bonjour,

    J'utilise la classe graphic pour dessiner des traits, le problème c'est que si une Form passe devant les traits sont effacé, comment puis-je rafraichir ou evite qu'il s'efface?
merci d'avance

metos

7 réponses

lemmingperceval Messages postés 128 Date d'inscription mardi 18 décembre 2007 Statut Membre Dernière intervention 2 août 2009 6
13 juin 2008 à 10:52
public






partial



class



Form1
:

Form

{







private



LineCollection
myLineCollection;


public
Form1(){



#region



InitializeComponent


this
.pictureHardware =

new
System.Windows.Forms.

PictureBox
();((System.ComponentModel.


ISupportInitialize
)(

this
.pictureHardware)).BeginInit();


this
.SuspendLayout();


//






// pictureHardware






//






this
.pictureHardware.Dock = System.Windows.Forms.

DockStyle
.Fill;


this
.pictureHardware.Location =

new
System.Drawing.

Point
(0, 0);


this
.pictureHardware.Name =

"pictureHardware"
;


this
.pictureHardware.Size =

new
System.Drawing.

Size
(292, 273);


this
.pictureHardware.TabIndex = 0;


this
.pictureHardware.TabStop =

false
;


this
.pictureHardware.Paint +=

new
System.Windows.Forms.

PaintEventHandler
(

this
.pictureHardware_Paint);


//






// Form1






//






this
.AutoScaleDimensions =

new
System.Drawing.

SizeF
(6F, 13F);


this
.AutoScaleMode = System.Windows.Forms.

AutoScaleMode
.Font;


this
.ClientSize =

new
System.Drawing.

Size
(292, 273);


this
.Controls.Add(

this
.pictureHardware);


this
.Name =

"Form1"
;


this
.Text =

"Form1"
;


this
.Load +=

new
System.

EventHandler
(

this
.Form1_Load);((System.ComponentModel.


ISupportInitialize
)(

this
.pictureHardware)).EndInit();


this
.ResumeLayout(

false
);


#endregion









this
.myLineCollection =

new



LineCollection
();}


private



void
pictureHardware_Paint(

object
sender,

PaintEventArgs
e){


Pen
myPen =

new



Pen
(

new



SolidBrush
(

Color
.Red));


foreach
(

Line
l

in



this
.myLineCollection)e.Graphics.DrawLine(myPen, l.StartX, l.StartY, l.StopX, l.StopY);

}


private



void
Form1_Load(

object
sender,

EventArgs
e){


this
.myLineCollection.Add(

new



Line
(10, 10, 20, 20));


this
.myLineCollection.Add(

new



Line
(10, 60, 20, 70));


this
.myLineCollection.Add(

new



Line
(10, 110, 20, 120));


this
.myLineCollection.Add(

new



Line
(10, 160, 20, 170));}

}


public



class



LineCollection
:

List
<

Line
>{

}


public



class



Line

{







private



int
startX;


public



int
StartX{


get
{

return
startX; }


set
{ startX =

value
; }}


private



int
startY;


public



int
StartY{


get
{

return
startY; }


set
{ startY =

value
; }}


private



int
stopX;


public



int
StopX{


get
{

return
stopX; }


set
{ stopX =

value
; }}


private



int
stopY;


public



int
StopY{


get
{

return
stopY; }


set
{ stopY =

value
; }}


public
Line(

int
startX,

int
startY,

int
stopX,

int
stopY){


this
.startX = startX;


this
.startY = startY;


this
.stopX = stopX;


this
.stopY = stopY;}

}
3
lemmingperceval Messages postés 128 Date d'inscription mardi 18 décembre 2007 Statut Membre Dernière intervention 2 août 2009 6
13 juin 2008 à 10:01
Peux-tu poster ton code s'il te plait, je n'arrive pas à reproduire ton problème.
0
cs_metos Messages postés 168 Date d'inscription vendredi 18 janvier 2002 Statut Membre Dernière intervention 19 octobre 2009
13 juin 2008 à 10:09
            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
            myPen.Width = 4;
           
            PictureHardware.Refresh();
            Graphics graph = PictureHardware.CreateGraphics();
            graph.DrawLine(myPen, new Point(startX, startY), new Point(startX, startY+Height));
            graph.DrawLine(myPen, new Point(startX, startY + Height), new Point(startX+Width, startY + Height));
            graph.DrawLine(myPen, new Point(startX + Width, startY + Height), new Point(startX + Width, startY));
            graph.DrawLine(myPen, new Point(startX + Width, startY), new Point(startX, startY));
            graph.Flush();

pictureHardware et une pictureBox avec une image et je dessine au dessus de l'image.
merci

metos
0
lemmingperceval Messages postés 128 Date d'inscription mardi 18 décembre 2007 Statut Membre Dernière intervention 2 août 2009 6
13 juin 2008 à 10:17
Poste tout le code de ta classe, c'est dans quel événement que tu peint?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
lemmingperceval Messages postés 128 Date d'inscription mardi 18 décembre 2007 Statut Membre Dernière intervention 2 août 2009 6
13 juin 2008 à 10:20
Je pense comprendre ton problème.
Le code que tu as posté plus haut, il ne s'exécute pas sur l'événement Paint de ta pictureBox, vria?
0
cs_metos Messages postés 168 Date d'inscription vendredi 18 janvier 2002 Statut Membre Dernière intervention 19 octobre 2009
13 juin 2008 à 10:38
Ce code est execturé dans une fonction drawpicture, apparement il faut que j'utilise comme tu le dis l'event paint, je dois déclare dans l'initialize l'event ?

metos
0
cs_metos Messages postés 168 Date d'inscription vendredi 18 janvier 2002 Statut Membre Dernière intervention 19 octobre 2009
13 juin 2008 à 11:08
merci

metos
0
Rejoignez-nous