Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
How can we rounded the corner to System.Windows.Forms.Control? When We write a class And use this code:

VB
Inherits System.Windows.Forms.Control




Like this sample:


http://up9.iranblog.com/images/b2xr3xtp4btdl093kf1y.jpg
Posted

Use following Code :
VB
Imports System.Drawing.Drawing2D

Public Class UserControl1
    Private _radius As Int32 = 20
    Private _opacity As Int32 = 125
    Private _backColor As System.Drawing.Color = Color.Black

    Private Sub UserControl1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim rect As Rectangle = Me.ClientRectangle
        rect.X = rect.X + 1
        rect.Y = rect.Y + 1
        rect.Width -= 2
        rect.Height -= 2
        Using bb As GraphicsPath = GetPath(rect, _radius)
            Using br As Brush = New SolidBrush(Color.FromArgb(_opacity, _backColor))
                e.Graphics.FillPath(br, bb)
            End Using
        End Using
    End Sub

    Protected Function GetPath(ByVal rc As Rectangle, ByVal r As Int32) As GraphicsPath
        Dim x As Int32 = rc.X, y As Int32 = rc.Y, w As Int32 = rc.Width, h As Int32 = rc.Height
        r = r << 1
        Dim path As GraphicsPath = New GraphicsPath()
        If r > 0 Then
            If (r > h) Then r = h
            If (r > w) Then r = w
            path.AddArc(x, y, r, r, 180, 90)
            path.AddArc(x + w - r, y, r, r, 270, 90)
            path.AddArc(x + w - r, y + h - r, r, r, 0, 90)
            path.AddArc(x, y + h - r, r, r, 90, 90)
            path.CloseFigure()
        Else
            path.AddRectangle(rc)
        End If
        Return path
    End Function
End Class

It create Rounded User Control.I hope it will help you.
 
Share this answer
 
Comments
sara.solati68 24-Nov-11 12:31pm    
It was very good.I have some questions.

Can you explain more about this code?
1-Color.FromArgb(_opacity, _backColor)
2-Me.ClientRectangle

Thank you very much.


Manoj K Bhoir 25-Nov-11 8:23am    
Color.FromArgb() is the custome color used for the Control.In that i passed two parameters.
_opacity : To set Transparancy of the Control.
_backColor : Set Background Color of Control.
ClientRectangle : It is the Property which returns Rectangle to represent Client Area of the Control.
Well I have never done this before but these links might help you
c-sharp-how-to-add-round-corner-to-button[^]
rounded button windows form c#[^]
My Google Search[^]
I think maybe you should look into doing a WPF app instead as I believe all this would be a lot easier to accomplish for you.
 
Share this answer
 
You have to use (or create) a custom control. Google is your friend.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900