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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A truly Circular Control?

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
I need a circular control. While I can draw an ellipse on a control I can't seem to clip off the corners. Does anyone know if/how this can be done? The circle needs to be about the size of a radio button and you need to see where you are placing it. I need it to mark points (and have a few different properties) to mark out certain regions that are not square/rectangular. Think connect the dots. I need these as controls so they can be placed on forms at design time.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Here's an example of creating a circular control.
Code:
Public Class CircularControl

    Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.BackColor = Color.Red
        Dim path As New Drawing2D.GraphicsPath
        path.AddEllipse(New RectangleF(0, 0, 50, 50))
        Dim circle As New Region(path)
        Me.Region = circle

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        'Add your custom paint code here

    End Sub

End Class
 
Thanks for the help. That is almost perfect. There is one little problem though. It works fine except when you move the control. Then the background shows again then disappears when you stop. I've tried taking out all the parts of my code piece by piece, but they do not change this behavior. I tried also overriding the OnMove in various ways, but that didn't help. Here is how the code looks right now.

Code:
Public Class DialogPoint
    Private FixedWidth As Integer = 50
    Private FixedHeight As Integer = 50

    Public Sub New()
        Me.SetStyle(Windows.Forms.ControlStyles.AllPaintingInWmPaint, True)
        Me.SetStyle(Windows.Forms.ControlStyles.UserPaint, True)
        Me.SetStyle(Windows.Forms.ControlStyles.OptimizedDoubleBuffer, True)
        Me.SetStyle(Windows.Forms.ControlStyles.ResizeRedraw, True)
        Me.SetStyle(Windows.Forms.ControlStyles.FixedHeight, True)
        Me.SetStyle(Windows.Forms.ControlStyles.FixedWidth, True)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.BackColor = Color.Red
        Dim path As New Drawing2D.GraphicsPath
        path.AddEllipse(New RectangleF(0, 0, FixedWidth, FixedHeight))
        Dim circle As New Region(path)
        Me.Region = circle

    End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        Dim brush As SolidBrush = New SolidBrush(Color.Yellow)
        e.Graphics.FillEllipse(Brushes.Yellow, New RectangleF(0, 0, FixedWidth, FixedHeight))

    End Sub

    Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
        MyBase.SetBoundsCore(x, y, FixedWidth, FixedHeight, specified)
    End Sub
End Class


-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Sorry, in the designer.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
There has to be a way...I'm thinking I may have seen this in the past. I'll let you know if I find anything.
 
Thanks. I appreciate the help. :)

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Do you need to set the BackColor?
[tt]Me.BackColor = Color.Red[/tt]

Would [tt]Me.BackColor = Color.Transparent[/tt] do what you need?
 
No, if you set it to tansparent then it cause any part of the form behind it to be tansparent as well.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
When I first saw your reply, I thought you were meaning the background of the form was showing through onto the control. But it's simply a matter of the control background filling the entire rectangular portion of the designer's selection of the control. Which, to me, isn't really a big deal. Since the control remains circular at runtime, why worry about what it looks like when dragged around the form?
 
It isn't a big problem because it does become normal after seeing so I can see if it has been placed in the "right spot" then, but it would just be better if I could see that while I or someone else is placing it.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top