【发布时间】:2016-04-19 21:28:07
【问题描述】:
为什么我可以在按钮下运行以下代码,但在表单加载下却不能运行?
For Each line As String In System.IO.File.ReadAllLines("c:\pos.xml")
If line.Contains("<POS>") = True Then
Dim tagless As String = StripTags(line)
Dim parts As String() = tagless.Split(New Char() {","})
Dim XVAL As Decimal = parts(0)
Dim YVAL As Decimal = parts(1)
'paint markers...
Dim myBrush As New SolidBrush(Color.FromArgb(128, Color.Red))
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.PictureBox1.CreateGraphics()
formGraphics.FillEllipse(myBrush, New Rectangle(XVAL - 35, YVAL - 35, 70, 70))
myBrush.Dispose()
formGraphics.Dispose()
End If
Next
如果需要,这里是 striptag 函数...
Function StripTags(ByVal html As String) As String
' Remove HTML tags.
Return Regex.Replace(html, "<.*?>", "")
End Function
【问题讨论】:
-
您是否收到错误消息?发生什么了?您绘制的内容不会以这种方式持续存在:将某些内容拖过表单或最小化,它会消失
-
如果有错误,您会遇到什么错误?它在哪里不起作用?
-
您应该在表单的绘制事件中完成所有绘图。在表单加载时,表单仍在加载,因此即使在加载后会出现油漆,也会删除您绘制的所有内容
-
你也应该开启 Option Strict
-
当我尝试使用表单加载事件触发它时,它没有任何错误。
标签: vb.net buttonclick form-load