Circular Bar Graph

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint

        Dim percent As Integer = 60
        e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
        Dim g As Graphics = e.Graphics
        Dim rect As New Rectangle(70, 45, 65, 65)
        Dim Progress_Curve = CSng(187 / 100 * percent)

        Using ProgressPen As New Pen(Color.Green, 15), BackgroundPen As New Pen(Color.LightGray, 15)
            'Dim myPen As New Pen(Color.Azure, 15)
            ProgressPen.Brush = New TextureBrush(New Bitmap("D:\BargraphBack2.jpg"))
            'g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
            g.DrawArc(BackgroundPen, rect, 180, 183)
            g.DrawArc(ProgressPen, rect, -185, Progress_Curve)

        End Using

        Using fnt As New Font(Me.Font.FontFamily, 10)
            Dim text As String = "£" & percent.ToString
            Dim textSize = g.MeasureString(text, fnt)
            Dim textPoint As New Point(CInt(rect.Left + (rect.Width / 2) - (textSize.Width / 2)), CInt(rect.Top + (rect.Height / 2) - (textSize.Height / 2)) - 3)
            g.DrawString(text, fnt, Brushes.Black, textPoint)
        End Using

    End Sub

 

BarGraph Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Call DrawHorizontalBargraph(65, Me, 40, 40, "Title...")

    End Sub


    Public Function DrawHorizontalBargraph(ByVal intPerCent As Integer, ByVal objObject As Object, ByVal x As Integer, ByVal y As Integer, ByVal strTitle As String) As Boolean
        On Error GoTo Err_Fail

        DrawHorizontalBargraph = False

        'Point Graphics To Object Passed
        Dim hwnd As IntPtr = objObject.Handle
        Dim myGraphics As Graphics
        myGraphics = Graphics.FromHwnd(hwnd)

        'Load Background Image
        Dim strBMPBack As String = System.AppDomain.CurrentDomain.BaseDirectory()
        Dim strBMPFront As String = System.AppDomain.CurrentDomain.BaseDirectory()

        'Load Images & Set Dimensions To Suit Loaded (Background) Image
        Dim intBackWidth, intBackLength As Integer
        Dim ImageBack As Image = Image.FromFile(strBMPBack & "BarGraphBack.jpg")
        Dim ImageFront As Image = Image.FromFile(strBMPBack & "BarGraphFront.jpg")
        intBackWidth = ImageBack.Width
        intBackLength = ImageBack.Height

        'Calculate Percentage Of Image Width
        intPerCent = (intBackWidth / 100) * intPerCent

        'Draw Bargraph
        myGraphics.DrawImage(ImageBack, x, y, intBackWidth, intBackLength)
        myGraphics.DrawImage(ImageFront, x, y, intPerCent, intBackLength)

        'Setup Writing Style
        Dim semiTransBrush As New SolidBrush(Color.FromArgb(200, 255, 255, 255))
        Dim style As FontStyle = FontStyle.Bold + FontStyle.Italic

        'Draw Title
        myGraphics.DrawString(strTitle, New Font("Calibri", 12, style), semiTransBrush, New RectangleF(x, y, intBackWidth, intBackLength))

        DrawHorizontalBargraph = True
        Exit Function
Err_Fail:
        DrawHorizontalBargraph = False
        MsgBox("Error Creating Bargraph...", MsgBoxStyle.Critical, "Error")
    End Function

 

 

SpaceFooter
Website_Design_NetObjects_FusionWeb
 Counter

www.CarlsPlace.co.uk

This Is A United Kingdom Site...