Follow up to ‘drawing rotated text’

The same programmer who ask for an example of rotated text is back with another interesting request; how to partially fill a circle from the bottom up…

as if it was a glass that you’ve poured water into… so here goes (this is only a snippet of the code, see the original post for the rest);

    Protected Overrides Sub OnPaint( _
            ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim bounds As Rectangle
        Dim g As Graphics
        Dim rotation As Single = 0
        g = e.Graphics
        bounds = New Rectangle(50, 50, _
            Me.Width - 100, Me.Height - 100)
        Dim percentageToFill As Single = 0.75
        Dim fillArea As New Rectangle( _
            50, 50 + ((Me.Height - 100) * (1 - percentageToFill)), _
            Me.Width - 100, ((Me.Height - 100) * percentageToFill))
        Dim oldClip As Region = g.Clip
        g.FillEllipse(Brushes.Red, bounds)
        g.Clip = oldClip
        g.DrawEllipse(Pens.Black, bounds)

There is probably more than one way to do this, but my code just fills the whole circle, but sets the clip region first so that it only draws within the bounds of a certain rectangle…

Author: Duncan Mackenzie

I'm the Developer Lead for the Channel 9 team, formerly worked on MSDN as a developer, content strategist and author.

6 thoughts on “Follow up to ‘drawing rotated text’”

  1. Once, I was under the impression that I excelled at VB. Matter of fact, once, I thought I was ‘pretty good’.
    Can you explain to me what Protected Override does and while you’re at it, what are the functions of the Option <whatever besides Explicit>. My world has just been turned upside down.

  2. Just to try to answer Kerowren’s questions about what Protected Overrides does. The Overrides is a keyword in VB.NET to specify that you would be overriding the default behavior of the OnPaint Method with the one you write in your code. Basically, the Parent Class Form that the code above inherits from has it’s own “default” code for OnPaint. Child classes of the class Form can change the way they paint the screen by specifying their own OnPaint code. You specify that you want to “change” the default code of a Parent Class by specifying the keyword Overrides. Here’s an example of inheritance and overriding:

    Class Man
    Public Overridable Function GetName() as String
    Return “Anonymous Man”
    End Function
    End Class

    Class EmmanuelMan : Inherits Man
    Public Overrides Function GetName() as String
    Return “Emmanuel Man”
    End Function
    End Class

    The keyword Protected and so is Public and Private changes the “visibility” and accessiblity of a method. For example Private will make the method accessible to only the class where the method was defined. Public makes it accessible to everything. Protected is somewhere in between.

  3. Hi there,
    I’m really helped with your example, but I want something more! 😉

    I’m working on a project to use a lpt1 port to steer an antenna rotor around, the compass I want to use to display the current location and the new location with an arrow from the center to the degrees.

    So how can I get a line from the center to the southwest for example?

    Just started with so any help is welcome….


Leave a Reply