Custom shaped buttons

I've made a form that has a custom shape and now I'm wondering if I wanted say a round button, do I have to do the same thing or is there a proper vb way


Answer this question

Custom shaped buttons

  • kkmick

    You can simply draw your custom shape on the designer surface of a User Control and have the UC inherit from the button...one way to go about it

  • jpimentel

    hey thnx for the info but i really didnt understand what should i do i use VWD express edition to make a web application with VB i did what was req. in the example 2 buttons but here is the timer i cant find it in the toolbox


    please help me iam really a new comer and i want to get myself going


  • Quirk

    Thx for that talldude i got the oval shape button thing showing, I didnt get the heart one working though, but is there a more simple way, like can't I use an image and transparency to get a custom shaped button

  • Kevin Rodgers

    DMan1 wrote:
    You can simply draw your custom shape on the designer surface of a User Control and have the UC inherit from the button...one way to go about it

    Whats the designer surface of a user control

  • LamptonWorm

    Anyone know

  • Pramy

    nice one tall dude

    I like the heart



  • stswordman

    Public Class Form1

    ' Example uses 2 buttons , 1 named heartbutton,

    ' 1 named roundbutton, and 1 timer, Timer1.

    ' Suggest a form background image of someone

    ' whom you can place the heart button over

    ' their heart.

    Dim beat As Boolean = True

    Private Sub HeartButton_Paint(ByVal sender As Object, _

    ByVal e As System.Windows.Forms.PaintEventArgs) _

    Handles HeartButton.Paint

    Dim buttonPath As New System.Drawing.Drawing2D.GraphicsPath

    Dim newRectangle As Rectangle = HeartButton.ClientRectangle

    ' You may not want to use any 'inflate' statements

    newRectangle.Inflate(1, 1)

    Dim f As Font = New System.Drawing.Font("Symbol", 8.25!, _

    System.Drawing.FontStyle.Regular, _

    System.Drawing.GraphicsUnit.Point, CType(2, Byte))

    Dim sf As System.Drawing.StringFormat = _

    System.Drawing.StringFormat.GenericTypographic

    Dim fs As FontStyle = FontStyle.Bold

    Dim s As String = "c"

    Dim ff As FontFamily = f.FontFamily

    If beat Then

    buttonPath.AddString(s, ff, fs, 65.0!, New PointF(3, 3), sf)

    Else

    buttonPath.AddString(s, ff, fs, 60.0!, New PointF(3, 3), sf)

    End If

    HeartButton.Region = New System.Drawing.Region(buttonPath)

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles Me.Load

    Dim g As Graphics = RoundButton.CreateGraphics

    Dim buttonPath As New System.Drawing.Drawing2D.GraphicsPath

    Dim newRectangle As Rectangle = RoundButton.ClientRectangle

    newRectangle.Inflate(-5, -5)

    buttonPath.AddEllipse(newRectangle)

    ' Create a circle within the new rectangle.

    g.DrawPath(Pens.Black, buttonPath)

    ' Set the button's Region property to the newly created

    ' circle region.

    RoundButton.Region = New System.Drawing.Region(buttonPath)

    End Sub

    Private Sub Form1_Shown(ByVal sender As Object, _

    ByVal e As System.EventArgs) Handles Me.Shown

    Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles Timer1.Tick

    beat = beat Xor True

    HeartButton.Invalidate()

    End Sub

    Private Sub RoundButton_Click(ByVal sender As System.Object, _

    ByVal e As System.EventArgs) Handles HeartButton.Click

    MsgBox("Yes, my heart is still beating!")

    End Sub

    End Class



  • jmurray_mi

    Well, despite limited computer time and

    constant interruptions from my wife.

    I was able to come up with some code to

    make really cool button shapes from images.

    I had hoped to refine, test, perfect the code a little

    more before posting, but I give up, my dear wife

    is winning the battle to keep my programming skills

    diminished.

    Code is at http://users.adelphia.net/~gcumbia/MakeGrPath.zip

    Rule 1: Images can only have 2 colors max. ('Monochrome bitmap'

    if using MS Paint.)

    Rule 2: Outside color must completely surround the shape.

    (Inside color cannot touch the edge.)

    Rule 3: Image format must be lossless (No JPGs)

    Rule 4: The button will be the size of the shape.

    (A 150 X 100 pixel image will make a button slightly

    smaller than that size.)



  • Custom shaped buttons