10分问一个Button.click的显象是为什么?
代码如下:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim g As Graphics
Dim brushred As SolidBrush = New SolidBrush(Color.Red)
g = Button1.CreateGraphics
g.FillRectangle(brushred, 0, 0, 282, 112)
End Sub
很简单就是想用Button.Click事件给Button本身全画成红色的
点击按钮代码实现,当鼠标指针从Button上移开时Button又自动变成原来的样子
就象事件里的代码没有被执行一样
这是什么?
[解决办法]
你可以在Paint事件里对它绘制,比如:
Private Sub Button1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
e.Graphics.Clear(Color.Red)
End Sub
[解决办法]
应该分别在MouseUP和MouseLeave中写变色代码和恢复代码