Bonjour,

Pour expliquer mon problème :

Sur un formulaire, je dessine un repère orthonormé. Le centre de ce repère est bel est bien le centre de la forme.
Ensuite je gradue la partie positive de mon axe des abscisses.
J'essaye de faire 15 trait tout les centimètres mais je n'y suis pas.

Quelqu'un aurait-il une explication ? j'essaye de convertir des pixel en centimètre mais je ne m'en sort pas, dois prendre en compte la taille de ma forme ou par rapport à celle de mon écran ? Existe-t-il une formule pour savoir combien de cm vaut un pixel ?

voici le code actuel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
 
            System.Drawing.Graphics formGraphics = this.CreateGraphics();
            System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
 
            #region Draw exemple
 
            // Draw head with an ellipse.
            //formGraphics.DrawEllipse(myPen, 0, 0, 200, 200);
 
            // Draw winking eye with an arc.
            //formGraphics.DrawArc(myPen, 40, 40, 40, 40, 180, -180);
 
            // Draw open eye with an ellipse.
            //formGraphics.DrawEllipse(myPen, 120, 40, 40, 40);
 
            // Draw nose with a Bezier spline.
            //formGraphics.DrawBezier(myPen, 100, 60, 120, 100, 90, 120, 80, 100);
 
            // Draw mouth with a canonical spline.
            //Point[] apt = new Point[4];
            //apt[0] = new Point(60, 140);
            //apt[1] = new Point(140, 140);
            //apt[2] = new Point(100, 180);
            //apt[3] = new Point(60, 140);
            //formGraphics.DrawCurve(myPen, apt, 0, 3, 0.9f);
            #endregion
 
            formGraphics.DrawLine(myPen, new Point(this.Width / 2, 0), new Point(this.Width / 2, this.Height));
            formGraphics.DrawLine(myPen, new Point(0, this.Height / 2), new Point(this.Width, this.Height / 2));
 
            int nbGraduation = this.Width / 15;
            int resolution = this.Width * this.Height;
 
            int pas = 0;
            for (int i = 0; i < nbGraduation; i++)
            {
                pas += 10;
                formGraphics.DrawLine(myPen, new Point((this.Width / 2)+pas , (this.Height / 2)), new Point((this.Width / 2)+pas , (this.Height / 2)-10));
            }
 
            myPen.Dispose();
            formGraphics.Dispose();
        }
 
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
 
            this.Invalidate();
        }
D'avance je vous remercie.