带标题的图片框 VB.NET

Picturebox with Caption in VB.NET

我怎样才能拥有带标题的图片框(控件)?我已经可以在此图片框上添加文本,但我希望它位于图片框下方。但是如果文本的位置超出 Picturebox 的大小,它将不可见。如果文本也有边框和背景色就更好了。

请帮忙。

代码如下:

Public Class neoPic
   Inherits PictureBox
   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       MyBase.OnPaint(e)
       e.Graphics.DrawString("Caption ", New Font("Cambria", 10), Brushes.Black, New PointF(0, 60))
   End Sub
End Class

我最终创建了一个 UserControl。我将工作代码放在这里以防它节省其他开发人员的时间。我在我的项目中添加了一个 UserControl(名为 PicTitled)并添加了一个 Picturebox(名为 PTPicturebox)和一个 Label(名为 PTLabel)相互堆叠。 然后我为 PicTitled 添加了文本和图像 属性,并为鼠标单击添加了事件处理程序。

Public Class PicTitled
    Public Shadows Event MouseClick As MouseEventHandler


    Overrides Property Text As String
        Get
            Return PTLabel.Text
        End Get
        Set(ByVal Value As String)
            PTLabel.Text = Value
        End Set
    End Property

    Property Image As Image
        Get
            Return PTPicturebox.Image
        End Get
        Set(ByVal Value As Image)
            PTPicturebox.Image = Value
        End Set
    End Property

    Private Sub PicTitled_MouseClick(sender As Object, e As MouseEventArgs) Handles MyBase.MouseClick, PTPicturebox.MouseClick, PTLabel.MouseClick
        RaiseEvent MouseClick(Me, e)
    End Sub


End Class

在主窗体中,我添加了如下代码:

    Private Sub CreateObj()
        Dim pbPicture As New PicTitled
        pbPicture.Name = "Object"
        pbPicture.Location = New System.Drawing.Point(40, 40)
        pbPicture.Text = "Object"
        pbPicture.Image = My.Resources.IMG
        pbPicture.Size = New System.Drawing.Size(50, 50)
        AddHandler pbPicture.MouseClick, AddressOf PictureBox_MouseClick

        Panel1.Controls.Add(pbPicture)
    End Sub

    Private Sub PictureBox_MouseClick(sender As Object, e As MouseEventArgs)
        'Do stuff when mouse click happens...
    End Sub