Click here to Skip to main content
15,895,812 members
Articles / Multimedia / GDI+

Custom Button Control with Gradient Colors and Extra Image (VB.NET)

Rate me:
Please Sign up or sign in to vote.
4.91/5 (131 votes)
19 Mar 2015CPOL7 min read 820.5K   46.9K   232  
This is a simple to use custom button control, but with a lot of visual design options.
Public Class dlgCorners
    Private cnrs As CornersProperty = New CornersProperty()
    Public ratio As Single = 1

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        DialogResult = System.Windows.Forms.DialogResult.OK
        Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        TheSample.Corners.UpperLeft = cnrs.UpperLeft
        TheSample.Corners.UpperRight = cnrs.UpperRight
        TheSample.Corners.LowerLeft = cnrs.LowerLeft
        TheSample.Corners.LowerRight = cnrs.LowerRight

        DialogResult = System.Windows.Forms.DialogResult.Cancel
        Close()
    End Sub

    Private Sub tbarUpperLeft_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarUpperLeft.Scroll
        TheSample.Corners.UpperLeft = CShort(tbarUpperLeft.Value)
        lblUL.Text = CStr(CInt(tbarUpperLeft.Value / ratio))
        TheSample.Invalidate()
    End Sub

    Private Sub tbarUpperRight_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarUpperRight.Scroll
        TheSample.Corners.UpperRight = CShort(tbarUpperRight.Value)
        lblUR.Text = CStr(CInt(tbarUpperRight.Value / ratio))
        TheSample.Invalidate()
    End Sub

    Private Sub tbarLowerLeft_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarLowerLeft.Scroll
        TheSample.Corners.LowerLeft = CShort(tbarLowerLeft.Value)
        lblLL.Text = CStr(CInt(tbarLowerLeft.Value / ratio))
        TheSample.Invalidate()
    End Sub

    Private Sub tbarLowerRight_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarLowerRight.Scroll
        TheSample.Corners.LowerRight = CShort(tbarLowerRight.Value)
        lblLR.Text = CStr(CInt(tbarLowerRight.Value / ratio))
        TheSample.Invalidate()
    End Sub

    Private Sub tbarAll_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarAll.Scroll
        tbarUpperLeft.Value = tbarAll.Value
        tbarUpperRight.Value = tbarAll.Value
        tbarLowerLeft.Value = tbarAll.Value
        tbarLowerRight.Value = tbarAll.Value
        UpdateLabels()
        TheSample.Corners.UpperLeft = CShort(tbarAll.Value)
        TheSample.Corners.UpperRight = CShort(tbarAll.Value)
        TheSample.Corners.LowerLeft = CShort(tbarAll.Value)
        TheSample.Corners.LowerRight = CShort(tbarAll.Value)
        TheSample.Invalidate()

    End Sub
    Sub UpdateLabels()
        lblUL.Text = CStr(CInt(tbarUpperLeft.Value / ratio))
        lblUR.Text = CStr(CInt(tbarUpperRight.Value / ratio))
        lblLL.Text = CStr(CInt(tbarLowerLeft.Value / ratio))
        lblLR.Text = CStr(CInt(tbarLowerRight.Value / ratio))

    End Sub
    Private Sub dlgCorners_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cnrs.UpperLeft = TheSample.Corners.UpperLeft
        cnrs.UpperRight = TheSample.Corners.UpperRight
        cnrs.LowerLeft = TheSample.Corners.LowerLeft
        cnrs.LowerRight = TheSample.Corners.LowerRight
        UpdateLabels()
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
I first got hooked on programing with the TI994A. After it finally lost all support I reluctantly moved to the Apple IIe. Thank You BeagleBros for getting me through. I wrote programs for my Scuba buisness during this time. Currently I am a Database manager and software developer. I started with VBA and VB6 and now having fun with VB.NET/WPF/C#...

Comments and Discussions