我在表单上绘制卡片,但是当我点击它时没有任何反应。为什么呢?
这是一个简单的例子来弄清楚如何做到这一点
Public Class Form1
Private WithEvents Carta As Card
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Carta = New Card("s", "5")
AddHandler Carta.Paint, AddressOf Carta.Card_Paint
AddHandler Carta.Click, AddressOf Carta.Card_Click
AddHandler Carta.MouseClick, AddressOf Carta.Card_MouseClick
End Sub
End Class
我创建了Card Class
Friend Class Card
Inherits Control
Private suit As String
Private face As String
Private card_image As Bitmap
Public Sub New(ByVal s As String, ByVal f As String)
suit = s
face = f
card_image = New Bitmap(Path.Combine(Application.StartupPath, "Cards", s & f & ".gif"))
Card_Paint()
End Sub
Public Sub Card_Click(sender As Object, e As EventArgs) Handles Me.Click
MsgBox(suit & face)
End Sub
Public Sub Card_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
MsgBox(suit & face)
End Sub
Public Sub Card_Paint()
Form1.CreateGraphics.DrawImage(card_image, New Point(10, 30))
End Sub
End Class
当我点击按钮卡正确显示但如果我点击它没有任何反应!错误是什么?