如何将.Image添加到UserControl的属性?

时间:2014-07-02 18:58:06

标签: vb.net properties user-controls

我想稍微设计一下我的应用程序。我通过使用标签和更改图像以及一些其他内容将丑陋的标准按钮更改为更漂亮的按钮。为了获得点击/鼠标悬停反馈,我开始这样做(将鼠标悬停的按钮着色为灰色,并将onClick和onMove上的颜色更改为例如绿色[My.Settings.ColorDark]):

Private Sub rotate_left_MouseOver(ByVal sender As Object, _
                               ByVal e As System.Windows.Forms.MouseEventArgs) _
                           Handles rotate_left.MouseMove, rotate_left.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Left _
        AndAlso e.X > 0 _
        AndAlso e.X < rotate_left.Width _
        AndAlso e.Y > 0 _
        AndAlso e.Y < rotate_left.Height Then 
        rotate_left.BackColor = My.Settings.ColorDark
    Else
        If Not e.Button = Windows.Forms.MouseButtons.Left Then
            rotate_left.BackColor = Color.FromArgb(211, 211, 211)  
        Else
            rotate_left.BackColor = Color.FromArgb(229, 229, 229) 
        End If
    End If
End Sub

Private Sub rotate_left_MouseLeave(sender As Object, e As EventArgs) Handles rotate_left.MouseLeave, FilterOn.MouseLeave
    rotate_left.BackColor = Color.FromArgb(240, 240, 240)
End Sub

(我不知道为什么我使用了4种不同的颜色 - 我可能要改变它......)
这很好用,但每次我需要一个新按钮时我都需要创建这个代码(我试图使用发送者,但这不起作用)。

所以我使用相同的代码创建了一个UserControl。这项工作也很有效,但我无法在Visual Studio的属性窗口(右下角)中更改图像。我已经添加了以下属性,但它没有显示:/

Public WriteOnly Property Image As Bitmap
    Set(ByVal value As Bitmap)
        Lbl.Image = value
    End Set
End Property

有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:0)

这是一个quickfix - 只需删除WriteOnly属性,它就会显示出来。您还需要添加Get End Get然后...
(不要忘记在Create-&gt; Rebuild Project下重建项目)

Public Property [Image] As Bitmap
    Set(ByVal value As Bitmap)
        Lbl.Image = value
    End Set
    Get
        Return CType(Lbl.Image, Bitmap)
    End Get
End Property

@Plutonix的所有道具

相关问题