Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create custom shaped button

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
0
0
GR
Hello, I am new to Vb.net and I have a problem.
I have a button in my application that must be rounded.
I think I have 2 options, either to create a round button if it's possible.
I have created a button with a rounded image. My image is a cicle, it's a game piece.
I have a picture box in my form that I have to place the rounded button onto the picture box.
Is it possible to make my button seem rounded? I tried Button1.BackColor = Color.Transparent with no effect.
Or is it possible to make the rest of background button transparent so that to see the button only in the background image shape? What can I do and how??? Please help me.

Thank you so much in advanced.
 
I found that piece of code. It creates a rounded button but it does'n fit exactly to the dimensions of the background image of button so that some pieces of image are hidden and in some others the circle is bigger than the round image that I don't want this. So how can I adapt this code to the background image dimensions? Any ideas please?

' This method will change the square button to a circular button by
' creating a new circle-shaped GraphicsPath object and setting it
' to the RoundButton objects region.
Private Sub roundButton_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint

Dim buttonPath As New System.Drawing.Drawing2D.GraphicsPath

' Set a new rectangle to the same size as the button's
' ClientRectangle property.
Dim newRectangle As Rectangle = Button1.ClientRectangle

' Decrease the size of the rectangle.
newRectangle.Inflate(-10, -10)

' Draw the button's border.
'e.Graphics.DrawEllipse(System.Drawing.Pens.Black, newRectangle)

'Increase the size of the rectangle to include the border.
newRectangle.Inflate(1, 1)

' Create a circle within the new rectangle.
buttonPath.AddEllipse(newRectangle)
e.Graphics.DrawPath(Pens.Transparent, buttonPath)
' Set the button's Region property to the newly created
' circle region.
Button1.Region = New System.Drawing.Region(buttonPath)

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top