积极答复者
窗体中显示画出点的坐标

问题
-
窗体中显示画出点的坐标,代码如下:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim x As Integer = 8
Dim y As Integer = 8Dim rect As Rectangle = Rectangle.FromLTRB(x - 4, y - 4, x + 4, y + 4)
e.Graphics.DrawEllipse(SystemPens.ControlText, rect)
e.Graphics.FillEllipse(SystemBrushes.ControlText, rect)End Sub
End Class
画出点的坐标为(8,8),怎样把“(8,8)”显示在点的右下方一点。用什么语句可以实现这种功能?
visual studio 2008
答案
-
e.Graphics.DrawString(String.Format("{0},{1}", x, y), Me.Font, Brushes.Red, x + 4, y + 4)
http://feiyun0112.cnblogs.com/- 已标记为答案 liunain021 2009年3月5日 14:35
-
楼主,你好
你是想在窗体中建立自己的坐标系,然后在新坐标系中绘图。
但是无论你的新坐标系怎么建立,计算机默认的始终是它的默认的坐标系,即y轴向下。
你干脆自己建立一个函数,专门用来把新坐标系的值转换为计算机默认的坐标值进行绘图。
网上的例子你可以参考下。
http://bbs.pfan.cn/post-173703.html
Microsoft Online Community Support- 已标记为答案 liunain021 2009年3月5日 14:34
全部回复
-
e.Graphics.DrawString(String.Format("{0},{1}", x, y), Me.Font, Brushes.Red, x + 4, y + 4)
http://feiyun0112.cnblogs.com/- 已标记为答案 liunain021 2009年3月5日 14:35
-
feiyun0112 说:
e.Graphics.DrawString(String.Format("{0},{1}", x, y), Me.Font, Brushes.Red, x + 4, y + 4)
http://feiyun0112.cnblogs.com/
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim t As Single
Try
t = DirectCast(sender, System.Windows.Forms.TextBox).Text
x = t
Catch
End Try
Me.Invalidate()
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
Dim t As Single
Try
t = DirectCast(sender, System.Windows.Forms.TextBox).Text
y = t
Catch
End Try
Me.Invalidate()
End Sub
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias '消除锯齿
e.Graphics.TranslateTransform(0, Me.ClientRectangle.Height) '平移变换,将Y坐标下移Form的高度
e.Graphics.ScaleTransform(1, -1) '缩放变换,Y坐标缩放比例为-1以完成Y的反向
e.Graphics.TranslateTransform(0, 60) '把坐标原点放在(0,60)
e.Graphics.DrawString(String.Format("{0},{1}", x, y), Me.Font, Brushes.Black, x + 4, y +4)
End Sub
可以显示,但是坐标值倒过来了。
End Class
visual studio 2008 -
下面的图像也会倒置 ,我下面的代码是正确的,为什么画出的函数图像也是倒立,这肯定跟转移的坐标系有关系,但是我也是按照规定来转移坐标系的,为什么画出的函数图像会倒置呢?能不能帮我解答下啊 ?
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
e.Graphics.TranslateTransform(0, Me.ClientRectangle.Height) '平移变换,将Y坐标下移Form的高度e.Graphics.ScaleTransform(1, -1) '缩放变换,Y坐标缩放比例为-1以完成Y的反向
e.Graphics.TranslateTransform(0, 60) '把坐标原点放在(0,60)
Dim pen1 As Pen
pen1 = New Pen(Color.Black, 2)
Dim i As Integer
Dim x1, x2, y1, y2 As Integer
e.Graphics.DrawLine(pen1, 50, 150, 350, 150)
e.Graphics.DrawLine(pen1, 50, 250, 50, 60)
e.Graphics.DrawLine(pen1, 350, 150, 345, 145)
e.Graphics.DrawLine(pen1, 350, 150, 345, 155)
e.Graphics.DrawLine(pen1, 50, 60, 45, 65)
e.Graphics.DrawLine(pen1, 50, 60, 55, 65)
x1 = 50
y1 = 150
For i = 1 To 100
x2 = 50 + i * 2
y2 = 150 - Sin(3.1415926 / 50 * i) * 100
e.Graphics.DrawLine(pen1, x1, y1, x2, y2)
x1 = x2
y1 = y2
If (i Mod 5 = 0) Then
e.Graphics.DrawLine(pen1, x1, y1, x1, 150)
End If
Next
End Sub
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
Me.Invalidate()
End Sub
End Class
visual studio 2008 -
-
当然 遵从新坐标系的坐标, 你这样画就明白了
e.Graphics.DrawLine(pen1, 0, 0, 100, 0)
e.Graphics.DrawLine(pen1, 0, 0, 0, 100)
e.Graphics.DrawLine(pen1, 0, 0, 100, 100)
http://feiyun0112.cnblogs.com/ -
feiyun0112 说:
当然 遵从新坐标系的坐标, 你这样画就明白了
e.Graphics.DrawLine(pen1, 0, 0, 100, 0)
e.Graphics.DrawLine(pen1, 0, 0, 0, 100)
e.Graphics.DrawLine(pen1, 0, 0, 100, 100)
http://feiyun0112.cnblogs.com/
我能够明白,为什么我上面的坐标值(x,y)在窗体中的显示会倒过来呢?
visual studio 2008 -
liunain021 说:
既然新坐标系中画直线是正常的,为什么坐标值(x,y)的显示不正常?
visual studio 2008
所有的点都翻转了,当然文字也一样
http://feiyun0112.cnblogs.com/ -
feiyun0112 说:liunain021 说:
既然新坐标系中画直线是正常的,为什么坐标值(x,y)的显示不正常?
visual studio 2008
所有的点都翻转了,当然文字也一样
http://feiyun0112.cnblogs.com/
点可以,线也可以,图形就不可以了,这样不矛盾了吗?有解决的办法吗?
visual studio 2008 -
楼主,你好
你是想在窗体中建立自己的坐标系,然后在新坐标系中绘图。
但是无论你的新坐标系怎么建立,计算机默认的始终是它的默认的坐标系,即y轴向下。
你干脆自己建立一个函数,专门用来把新坐标系的值转换为计算机默认的坐标值进行绘图。
网上的例子你可以参考下。
http://bbs.pfan.cn/post-173703.html
Microsoft Online Community Support- 已标记为答案 liunain021 2009年3月5日 14:34