日期:2014-05-18  浏览次数:20717 次

一个控件绑定问题--------初学者
小弟自己写了个简单仪表盘控件,代码如下
  int r_hand;
  private void controlPow_Paint(object sender, PaintEventArgs e)
  {
  int r = 0;
  float x1, x2, y1, y2, x3 = 0, y3 = 0;
  Graphics g = e.Graphics;
  Pen mypen = new Pen(Color.Black, 2);
  Pen mypen2 = new Pen(Color.Black, 2);
  Brush mybrush = Brushes.Red;
  Font myfont = new Font(this.Font, FontStyle.Bold);
  g.DrawArc(mypen, 0, 0, base.Width, base.Height * 2, 180, 180);
  for (r = 10; r <= 100; r += 10)
  {
  x1 = (float)(Math.Abs(base.Width / 2 - base.Height * Math.Cos(Math.PI * r / 100.0)));
  x2 = (float)(Math.Abs(base.Width / 2 - (base.Height - 20) * Math.Cos(Math.PI * r / 100.0)));
  y1 = (float)(Math.Abs(base.Height - base.Height * Math.Sin(Math.PI * r / 100.0)));
  y2 = (float)(Math.Abs(base.Height - (base.Height - 20) * Math.Sin(Math.PI * r / 100.0)));
  g.DrawLine(mypen, x1, y1, x2, y2);
  g.DrawString(r.ToString(), myfont, mybrush, x2, y2);
  }
  x3 = (float)(Math.Abs(base.Width / 2 - (base.Height - 20) * Math.Cos(Math.PI * r_hand / 100.0)));
  y3 = (float)(Math.Abs(base.Height - (base.Height - 20) * Math.Sin(Math.PI * r_hand / 100.0)));
  g.DrawLine(mypen2, x3, y3, base.Width / 2, base.Height);
  }

  public int Power //设置属性
  {
  get
  {
  return r_hand;
  }
  set
  {
  this.r_hand = (int)(value);
  }
  }

想将Power属性的值和numericUpDown的值绑定,以实现通过numericUpDown来改变仪表盘的值,请问各位大侠如何绑定啊???已经试过将numericUpDown.Value强制转换成int型了。。。

------解决方案--------------------
numericUpDown值变化时,调用controlPow.Invalidate()