Probleme avec CreateGraphics() en windowsapplication c#

Résolu
Kbitnik Messages postés 125 Date d'inscription mercredi 15 novembre 2000 Statut Membre Dernière intervention 2 mars 2006 - 20 janv. 2006 à 15:21
Kbitnik Messages postés 125 Date d'inscription mercredi 15 novembre 2000 Statut Membre Dernière intervention 2 mars 2006 - 21 janv. 2006 à 14:13
Bonjour à tous,
j'ai une petit problème avec mon application, en bref je crée une application windows, je saisis 4 valeurs et avec ces valeurs, je souhaite créer un graphique de statistique (camenbert ou histogramme). Mais, lorsque je passe d'une form a la suivante, je ne sais pas ou mettre les instructions ou alors je mets les mauvaises instructions. Moi je mets, dans le form_load , le code suivant :
Graphics g = this.CreateGraphics();
g.DrawRectangle(new pen(Color.Black,2),20,20,30,40);

Mais il ne m'affiche rien du tout ! Commen puis-je faire ??

Kbitnik

6 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
21 janv. 2006 à 00:48
Salut, ça marche bien chez moi aussi, ça dessine un joli damier en pointillés..Pour ma part je ne dispose que les Graphics que j'ai créé avec la méthode CreateGraphics, celui de l'évènement Paint c'est le système qui le créé alors je laisse le system le disposer..

As tu bien abonner ta méthode à l'évènement Paint, sinon utilise directement la méthode protégée OnPaint c'est encore plus simple.
3
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
20 janv. 2006 à 17:09
il faut le metre dans le OnPaint de ta form...

et n'oublie le g.Dispose(); quand tu as fini de dessiner.

Sébastien FERRAND
[MVP Visual C#]
0
Kbitnik Messages postés 125 Date d'inscription mercredi 15 novembre 2000 Statut Membre Dernière intervention 2 mars 2006
20 janv. 2006 à 17:32
Merci pour le g.dispose(), c cool !
par contre pour le OnPaint() jfé come sa mé sa marche pas
private void Form1_OnPaint(object sender, PaintEventArgs e)
{
Graphics g =
this.CreateGraphics();
g.DrawRectangle(
new Pen(Color.Black,1),40,40,420,200);
g.FillRectangle(
new SolidBrush(Color.LightGray),41,41,419,199);
Pen oP =
new Pen(Color.Black,1);
oP.DashStyle = DashStyle.Dot;
g.DrawLine(oP,
new Point(40,200),
new Point(460,200));
g.DrawLine(oP,
new Point(40,160),
new Point(460,160));
g.DrawLine(oP,
new Point(40,120),
new Point(460,120));
g.DrawLine(oP,
new Point(40,80),
new Point(460,80));
g.DrawLine(oP,
new Point(95,40),
new Point(95,240));
g.DrawLine(oP,
new Point(150,40),
new Point(150,240));
g.DrawLine(oP,
new Point(205,40),
new Point(205,240));
g.DrawLine(oP,
new Point(260,40),
new Point(260,240));
g.DrawLine(oP,
new Point(315,40),
new Point(315,240));
g.DrawLine(oP,
new Point(370,40),
new Point(370,240));
g.DrawLine(oP,
new Point(420,40),
new Point(420,240));
g.Dispose();
}


Ne faites pas attention a la multitude de DrawLine, jutiliserai un DrawLines.
0
sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
20 janv. 2006 à 20:20
humm...

private void Form1_OnPaint(object sender, PaintEventArgs e)
{
Graphics g =
e.Graphics;
g.DrawRectangle(
new Pen(Color.Black,1),40,40,420,200);
g.FillRectangle(
new SolidBrush(Color.LightGray),41,41,419,199);
Pen oP =
new Pen(Color.Black,1);
oP.DashStyle = DashStyle.Dot;
g.DrawLine(oP,
new Point(40,200),
new Point(460,200));
g.DrawLine(oP,
new Point(40,160),
new Point(460,160));
g.DrawLine(oP,
new Point(40,120),
new Point(460,120));
g.DrawLine(oP,
new Point(40,80),
new Point(460,80));
g.DrawLine(oP,
new Point(95,40),
new Point(95,240));
g.DrawLine(oP,
new Point(150,40),
new Point(150,240));
g.DrawLine(oP,
new Point(205,40),
new Point(205,240));
g.DrawLine(oP,
new Point(260,40),
new Point(260,240));
g.DrawLine(oP,
new Point(315,40),
new Point(315,240));
g.DrawLine(oP,
new Point(370,40),
new Point(370,240));
g.DrawLine(oP,
new Point(420,40),
new Point(420,240));
g.Dispose();
}

Ne faites

Sébastien FERRAND
[MVP Visual C#]
0

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

Posez votre question
Kbitnik Messages postés 125 Date d'inscription mercredi 15 novembre 2000 Statut Membre Dernière intervention 2 mars 2006
20 janv. 2006 à 21:40
Bin c'est trop bizarre, parce que je fais exactement ça mais ça marche pas. Il passe la compilation et tout, il ne voit pas d'erreur mais il ne que lapplication vide.
0
Kbitnik Messages postés 125 Date d'inscription mercredi 15 novembre 2000 Statut Membre Dernière intervention 2 mars 2006
21 janv. 2006 à 14:13
ahhh j'ai trouvé, c'était bien ça lutinore, je n'avais pas abonné ma méthode a l'événement. La ça marche à présent, je vous remercie a tous les 2 ! C'est cool !
A bientot !

Kbitnik
0
Rejoignez-nous