带有右侧图片的标签控件不可见

时间:2019-02-23 04:20:47

标签: vb.net

我尝试用左侧的图像构建自定义标签。 但是在构建并插入我的表单并设置所有配置后, 我只有文字在场。 为什么在我的表单上没有出现图片框,而我在表单上插入的只有标签可见。 我该如何解决。 提前给你加油 这是我的代码

Public Class label_picture

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()
    Label1.ForeColor = Color.Black
    Me.ForeColor = Color.DeepSkyBlue

    ' Add any initialization after the InitializeComponent() call.

End Sub
Public Property image As Image
    Get
        Return image
    End Get
    Set(image As Image)
        PictureBox1.BackgroundImage = image
        PictureBox1.BackgroundImageLayout = ImageLayout.Stretch
        Me.Invalidate()
    End Set
End Property
Public Property text_labelpic_text As String
    Get
        Return text_labelpic_text
    End Get
    Set(text_labelpic_text As String)
        Label1.Text = text_labelpic_text
        Me.Invalidate()
    End Set
End Property

Private Sub Label1_TextChanged(sender As Object, e As EventArgs) Handles Label1.TextChanged
    Label1.Text = text_labelpic_text
    Me.Invalidate()
End Sub

Private Sub label_picture_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
    Label1.Location = New Point(CInt(Me.Width / 2 - Label1.Width / 2), CInt(Me.Height / 2 - Label1.Height))
    Label1.Top = (Label1.Parent.Height \ 2) - (Label1.Height \ 2)
    PictureBox1.Location = New Point(CInt(Me.Width / 2 - PictureBox1.Width / 2), CInt(Me.Height / 2 - PictureBox1.Height))
    PictureBox1.Top = (PictureBox1.Parent.Height \ 2) - (PictureBox1.Height \ 2)
    PictureBox1.Left = (PictureBox1.Parent.Width \ 2) - (PictureBox1.Width \ 2)
End Sub
End Class

0 个答案:

没有答案