Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I want to draw curve on form1
In order to fit the curve fully across the height and width of form1
I have to know the size of both width and hieght of the form1
But I am diturbed from where should I get the height and width of form1
Because the curve did not appeared on form1 unless I changed the data

The data of curve are

double qad[360] along x(horizontaly)
vesus
double d[360] along y (vertically)

double wid,hi,Rax,Ray, maxValue_X, maxValue_Y;
int x1,y1,x2,y2,i;
 Pen pen0 = new Pen(Color.Red);
 Graphics Mye = base.CreateGraphics();
 //Graphics Mye = this.CreateGraphics();//may be I should use this
 Graphics Mye = base.CreateGraphics();
            Rax = wid / maxValue_X ;
            Ray = hi / maxValue_Y ;
            for (i = 0; i < 360-1; i++)
            {
                x1 = (int)(Rax * qad[i]);     y1 = (int)(Ray*d[i]);
                x2 = (int)(Rax * qad[i + 1]); y2 = (int)(Ray*d[i + 1]);
Mye.DrawLine(pen0, x1, y1, x2, y2);
            }

Should I use
this.WindowState = FormWindowState.Maximized;
wid= Form1.ActiveForm.ClientSize.Width-2*fontx;
hi=Form1.ActiveForm.ClientSize.Height-2*fontx;

Or

this.WindowState = FormWindowState.Maximized;
wid = this.ClientSize.Width - 2* fontx;
hi = this.ClientSize.Height - 2* fontx;
Posted
Updated 2-Jun-11 2:40am
v5
Comments
BobJanova 2-Jun-11 8:40am    
edited for code/pre blocks

1 solution

Drawing you do with CreateGraphics will get lost when the control is repainted. If you want your line to persist, you should draw it in OnPaint (or a Paint event handler).

If this is within Form1 you should use this.ClientSize.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900