按下按钮时创建图片框

Create a Picturebox when a button was press

我正在创建一个名为 KernalOS 的 OS 系统,它具有全功能桌面但我的问题是我希望能够在单击按钮时添加图标。我想让图标检测鼠标按钮是否按下/单击。

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim newPictureBox As New PictureBox
    newPictureBox.Visible = True
    newPictureBox.Top = 20
    newPictureBox.Width = 100
    newPictureBox.Height = 50
    newPictureBox.Left = 10
    'add control to form
    Controls.Add(newPictureBox)
    newPictureBox.Location = New Point(100, 100)
End Sub

此代码无法正常工作,请了解发生了什么或为何无法正常工作。请提出问题,我会为您填写详细信息。谢谢大家

使用AddHandler事件:

newPictureBox.AddHandler, AddressOf newPictureBox_Click

newPictureBox.AddHandler, AddressOf newPictureBox_MouseDown

现在我不确定那有多精确;你现在必须写一个

Private Sub newPictureBox_Click.

这可能不是完整的正确语法,但您明白了。