VB.NET 绘图的问题
我想点击按钮后图像才会绘制,并且图像在Paint里面绘制,因此定义了个全局的布尔型变量判断,初始化false,点击btn后为true,在paint里面判断,但是实际运行时没有反应,求解!!求高手指点如何才能实现我刚才的想法! --------------------编程问答-------------------- 自己顶一下 --------------------编程问答-------------------- 你在按钮里调用Me.Refresh()试试。 --------------------编程问答-------------------- 用控件的.Invalidate .Refresh --------------------编程问答-------------------- 同意3楼的 --------------------编程问答--------------------这样可以绘制出,但是还是最小化之后不能重绘 --------------------编程问答--------------------
可以详细说明一下么 --------------------编程问答-------------------- 窗体也是一个控件啊:Me.Refresh
又如PicturBox,Panel也是一个控件啊。Me.Panel1.Invalidate() --------------------编程问答-------------------- 这个里面有详细介绍方法
http://blog.csdn.net/wl58796351/article/details/7388925 --------------------编程问答--------------------
--------------------编程问答--------------------
Public Class Form1
Dim f As Boolean = False
Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If f Then
e.Graphics.DrawLine(Pens.Red, 0, 0, 100, 100)
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
f = True
Me.Refresh()
End Sub
End Class
我把绘制的代码写到draw方法里,但是在paint里调用的时候就不能实现我的想法,但是不加if判断能行,这是什么原因
Public Class Form1
Dim isPress As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
isPress = True
Me.Refresh()
End Sub
Private Sub draw()
Dim MyGraphic As Graphics
Dim Mypen As New Pen(Color.Red, 2)
MyGraphic = Me.CreateGraphics()
MyGraphic.DrawLine(Mypen, 0, 0, 100, 100)
isPress = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
isPress = False
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If isPress = True Then
draw()
End If
draw1()'该方法直接使用
End Sub
Private Sub draw1()
Dim MyGraphic As Graphics
Dim Mypen As New Pen(Color.Red, 2)
MyGraphic = Me.CreateGraphics()
MyGraphic.DrawLine(Mypen, 0, 0, 500, 100)
isPress = False
End Sub
End Class --------------------编程问答--------------------
--------------------编程问答--------------------
'不明白你要什么效果,如下可行否?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
btnbool = True
isPress = True
Me.Refresh()
End Sub
Dim btnbool As Boolean
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
If btnbool = True Then
isPress = True
btnbool = False
End If
End Sub
Public Class Form1
Dim isPress As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
isPress = True
Me.Refresh()
End Sub
Private Sub draw()
Dim MyGraphic As Graphics
Dim Mypen As New Pen(Color.Red, 2)
MyGraphic = Me.CreateGraphics()
MyGraphic.DrawLine(Mypen, 0, 0, 100, 100)
'isPress = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
isPress = False
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If isPress = True Then
draw()
End If
draw1() '该方法直接使用
End Sub
Private Sub draw1()
Dim MyGraphic As Graphics
Dim Mypen As New Pen(Color.Red, 2)
MyGraphic = Me.CreateGraphics()
MyGraphic.DrawLine(Mypen, 0, 0, 500, 100)
'isPress = False
End Sub
End Class
你在draw1和draw方法里重新设置isPress = False是什么意思?
补充:.NET技术 , VB.NET