-2
Public Class Form1
    Private _zkouska1 As New Bitmap("C:\Users\w\Desktop\zkouska1.gif")
    Private _zkouska2 As New Bitmap("C:\Users\w\Desktop\zkouska2.gif")

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        e.Graphics.DrawImageUnscaled(New Bitmap(_zkouska1), 0, 0)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MyNewSub()
    End Sub

    Sub MyNewSub()
        BackColor = Color.Red
        TransparencyKey = BackColor
    End Sub
    Private Sub Example_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded

        AddHandler e.Control.MouseClick, AddressOf Example_MouseClick
    End Sub

    Private Sub Example_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        If True Then e.Graphics.DrawImageUnscaled(New Bitmap(_zkouska2), 0, 0) = True
    End Sub
End Class
4

1 回答 1

0

您没有具体指出哪些行导致了问题,但是这一行的问题:

If True Then e.Graphics.DrawImageUnscaled(New Bitmap(_zkouska2), 0, 0) = True

是 MouseEventArgs 没有 Graphics 成员。也许这里要做的事情是使用 Mouse_Clicked 事件来设置一个变量来跟踪鼠标是否被单击(以及单击位置),并使用 Paint 事件来进行实际的绘图。

因此,您将向该类添加一个布尔变量:

Private _clicked As Boolean

将 MouseClicked 事件更改为如下所示:

Private Sub Example_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
    _clicked = True
End Sub

添加一个 Paint 事件并创建该事件,如下所示:

Private Sub Form1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
    If _clicked Then
        e.Graphics.DrawImageUnscaled(New Bitmap(_zkouska2), 0, 0)
    End If
End Sub
于 2013-01-03T13:28:11.257 回答