Public Class Form1
Dim g As Graphics = Me.PictureBox1.CreateGraphics
Dim myBrush As New TextureBrush(New Bitmap("C:\我的程序\下箭头.bmp"))
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
g.FillEllipse(myBrush, New RectangleF(0, 0, 150, 150))
End Sub
End Class
运行后显示
“System.NullReferenceException”类型的异常在 WindowsApplication1.exe 中发生,但未在用户代码中进行处理
其他信息: 未将对象引用设置到对象的实例。
求大神解决
vb.net“System.NullReferenceException”类型的异常
答案:2 悬赏:20 手机版
解决时间 2021-03-11 15:20
- 提问者网友:却不属于对方
- 2021-03-11 11:12
最佳答案
- 五星知识达人网友:青灯有味
- 2021-03-11 12:36
Public Class Form1
Dim g As Graphics
Dim myBrush As New TextureBrush(New Bitmap("C:\我的程序\下箭头.bmp"))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
g = Me.PictureBox1.CreateGraphics
g.FillEllipse(myBrush, New RectangleF(0, 0, 150, 150))
End Sub
End Class 也可以
Public Class Form1
Dim myBrush As New TextureBrush(New Bitmap("C:\我的程序\下箭头.bmp"))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.FillEllipse(myBrush, New RectangleF(0, 0, 150, 150))
End Sub
End Class
Dim g As Graphics
Dim myBrush As New TextureBrush(New Bitmap("C:\我的程序\下箭头.bmp"))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
g = Me.PictureBox1.CreateGraphics
g.FillEllipse(myBrush, New RectangleF(0, 0, 150, 150))
End Sub
End Class 也可以
Public Class Form1
Dim myBrush As New TextureBrush(New Bitmap("C:\我的程序\下箭头.bmp"))
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
PictureBox1.Refresh()
End Sub
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
e.Graphics.FillEllipse(myBrush, New RectangleF(0, 0, 150, 150))
End Sub
End Class
全部回答
- 1楼网友:酒醒三更
- 2021-03-11 12:51
运行了一段由代码动态生成控件的程序,可以正常运行,但即时窗口有三行提示:在 system.nullreferenceexception 中第一次偶然出现的“windowsapplication1.exe”类型的异常。
不是没有人理睬,是没有人浪费时间在这里,看到头都晕
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯