vb.net的窗体实际上是个坐标系,我想在这个窗体上动态显示点. 我的方法是这样一来的,用两个文本框,一个用于输入X坐标,一个用于输入Y坐标,当(x,y)值输好以后,窗体中会显示这个点,用什么方法可以办到? 如果还要同时在点的上面显示点的坐标,应该怎么做? 给点建议吧和具体的做法。(学C#的朋友也许有这方面的经验,特把此帖发到这里)

解决方案 »

  1.   

    Graphics _Graphics = Graphics.FromHwnd(this.Handle);            Rectangle _Rect=new Rectangle();
                _Rect.X=int.Parse(textBox1.Text);
                _Rect.Y = int.Parse(textBox2.Text);            _Rect.Width=1;
                _Rect.Height=1;
                _Graphics.FillRectangle(Brushes.Blue,_Rect);
    C#的
      

  2.   

    参考如下代码 int x;
    int y;
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    int t=-1;
    if (int.TryParse((sender as TextBox).Text, out t))
    {
    x = t;
    }
    this.Invalidate();
    } private void textBox2_TextChanged(object sender, EventArgs e)
    {
    int t = -1;
    if (int.TryParse((sender as TextBox).Text, out t))
    {
    y = t;
    }
    this.Invalidate();
    }
    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);
    Rectangle dotRect = Rectangle.FromLTRB(x - 1, y - 1, x + 1, y + 1);
    e.Graphics.DrawEllipse(SystemPens.WindowText, dotRect);
    e.Graphics.FillEllipse(SystemBrushes.ControlText, dotRect);
    e.Graphics.DrawString(string.Format("({0}, {1})", x, y), this.Font, SystemBrushes.ControlText, new Point(x, y));
    }