我制作了一个交互式显示足部压力的程序。 椭圆的较大直径表示较大的压力。 我在标签的Paint事件上工作。 这是事件处理程序:
private void labelGrad2_Paint(object sender, PaintEventArgs e)
{
GraphicsPath gp = new GraphicsPath();
int weight_forefoot_left;
weight_forefoot_left = Convert.ToInt32( l_press05 + l_press06 + l_press07); // summing forefoot pressure sensors
size_pressure_forefootLeft = (weight_forefoot_left * 2 ); //2 is based on trial and error for display only
//protection diameter
if (size_pressure_forefootLeft == 0 ){
size_pressure_forefootLeft = 1;
}
if (size_pressure_forefootLeft > 26) {
size_pressure_forefootLeft = 26; //protection diameter display
}
//---variable sizing---------
labelGrad_forefoot_left.Font = new Font("MS UI Gothic", size_pressure_forefootLeft);
int x_forefoot = (pictureBox_CoP.Location.X - (labelGrad_forefoot_left.Size.Width / 2)) + 58; //location of left x corner in pictureBox_CoP
int y_forefoot = (pictureBox_CoP.Location.Y - (labelGrad_forefoot_left.Size.Height / 2)) + 100; //location of left y corner in pictureBox_CoP
labelGrad_forefoot_left.Location = new Point(x_forefoot, y_forefoot);
labelGrad_forefoot_left.BackColor = Color.White;
gp.AddEllipse(labelGrad_forefoot_left.ClientRectangle);
PathGradientBrush pgb = new PathGradientBrush(gp);
pgb.CenterPoint = new PointF(labelGrad_forefoot_left.ClientRectangle.Width / 2,
labelGrad_forefoot_left.ClientRectangle.Height / 2);
pgb.CenterColor = Color.Red;
pgb.SurroundColors = new Color[] { Color.Blue};
pgb.SetBlendTriangularShape(.5f, 1.0f);
pgb.FocusScales = new PointF(0f, 0f);
e.Graphics.FillPath(pgb, gp);
pgb.Dispose();
gp.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
size_pressure_forefootLeft = trackBar1.Value;
textBox4.Text = Convert.ToString( size_pressure_forefootLeft);
this.Invalidate();
this.Update();
}
我需要不断更改变量“size_pressure_forefootLeft”。
我已尝试使用计时器事件,但计时器事件没有PaintEventArgs,行e.Graphics.FillPath(pgb, gp)
中存在错误。
如何处理?