想要合适的form1尺寸绘制曲线 [英] want the suitable size of form1 to draw curve

查看:74
本文介绍了想要合适的form1尺寸绘制曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在form1上绘制曲线
为了完全在form1的高度和宽度上拟合曲线
我必须知道form1的宽度和高度的大小
但是我不知道应该从哪里获得form1的高度和宽度
因为除非更改数据,否则曲线不会出现在form1上

曲线的数据是

double qad[360]沿x(水平)
vesus
double d[360]沿y(垂直)

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;

推荐答案

重新绘制控件时,使用CreateGraphics所做的绘图会丢失.如果要保留行,则应在OnPaint(或Paint事件处理程序)中绘制它.

如果在Form1内,则应使用this.ClientSize.
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.


这篇关于想要合适的form1尺寸绘制曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆