Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Refreshing a drawing

Refreshing a drawing

Scheduled Pinned Locked Moved Visual Basic
graphicshelpdotnet
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    twsted f8
    wrote on last edited by
    #1

    Hi everyone I got a small problem I have devloped hotel software and I am trying to draw achart that shows %age occupancy. I would like to draw a pie chart on a form. I have managed to do this so far,the chart is being drawn when the form loads. I would like the form to be able to redraw when a user specifies a different date such that you can view the past occupancy. The code I am using is shown below. I hope you will be able to help me. twisted F8 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim TotalCount As Single Dim rect As Rectangle = New Rectangle(100, 105, 150, 150) For Each gd As GraphData In occupancy TotalCount += gd.percentageocc Next Dim g As Graphics = e.Graphics ' Create variables to hold the changing values of Angles g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality Dim StartAngle As Single = 0 Dim SweepAngle As Single = 0 For Each gd As GraphData In occupancy SweepAngle = 360 * gd.percentageocc / TotalCount g.FillPie(New SolidBrush(gd.Clr), rect, StartAngle, SweepAngle) StartAngle += SweepAngle Next ' g.DrawPie(New Pen(Color.Brown), rect, StartAngle, SweepAngle) ' Create a Brush to draw the text Dim TextBrsh As Brush = New SolidBrush(Color.Black) ' Create a Font object instance for text display Dim TextFont As New Font("Arial", 12, FontStyle.Bold) g.DrawString("Chart Key", TextFont, TextBrsh, 310, 100) Dim pxFromTop As Integer = 135 For Each gd As GraphData In occupancy ' Draw bullet g.FillEllipse(New SolidBrush(gd.Clr), 310, pxFromTop, 15, 15) ' Draw line round bullet. g.DrawEllipse(New Pen(Color.Black), 310, pxFromTop, 15, 15) ' Draw the text - color coded g.DrawString(gd.Description & " (" & gd.percentageocc & "%)", TextFont, TextBrsh, 360, pxFromTop) ' Increase gap from Top for next line pxFromTop += 30 Next End Sub

    A L 2 Replies Last reply
    0
    • T twsted f8

      Hi everyone I got a small problem I have devloped hotel software and I am trying to draw achart that shows %age occupancy. I would like to draw a pie chart on a form. I have managed to do this so far,the chart is being drawn when the form loads. I would like the form to be able to redraw when a user specifies a different date such that you can view the past occupancy. The code I am using is shown below. I hope you will be able to help me. twisted F8 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim TotalCount As Single Dim rect As Rectangle = New Rectangle(100, 105, 150, 150) For Each gd As GraphData In occupancy TotalCount += gd.percentageocc Next Dim g As Graphics = e.Graphics ' Create variables to hold the changing values of Angles g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality Dim StartAngle As Single = 0 Dim SweepAngle As Single = 0 For Each gd As GraphData In occupancy SweepAngle = 360 * gd.percentageocc / TotalCount g.FillPie(New SolidBrush(gd.Clr), rect, StartAngle, SweepAngle) StartAngle += SweepAngle Next ' g.DrawPie(New Pen(Color.Brown), rect, StartAngle, SweepAngle) ' Create a Brush to draw the text Dim TextBrsh As Brush = New SolidBrush(Color.Black) ' Create a Font object instance for text display Dim TextFont As New Font("Arial", 12, FontStyle.Bold) g.DrawString("Chart Key", TextFont, TextBrsh, 310, 100) Dim pxFromTop As Integer = 135 For Each gd As GraphData In occupancy ' Draw bullet g.FillEllipse(New SolidBrush(gd.Clr), 310, pxFromTop, 15, 15) ' Draw line round bullet. g.DrawEllipse(New Pen(Color.Black), 310, pxFromTop, 15, 15) ' Draw the text - color coded g.DrawString(gd.Description & " (" & gd.percentageocc & "%)", TextFont, TextBrsh, 360, pxFromTop) ' Increase gap from Top for next line pxFromTop += 30 Next End Sub

      A Offline
      A Offline
      AliAmjad
      wrote on last edited by
      #2

      I think Form.Refresh() method will do the job for you.

      AliAmjad(MCP)

      1 Reply Last reply
      0
      • T twsted f8

        Hi everyone I got a small problem I have devloped hotel software and I am trying to draw achart that shows %age occupancy. I would like to draw a pie chart on a form. I have managed to do this so far,the chart is being drawn when the form loads. I would like the form to be able to redraw when a user specifies a different date such that you can view the past occupancy. The code I am using is shown below. I hope you will be able to help me. twisted F8 Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) Dim TotalCount As Single Dim rect As Rectangle = New Rectangle(100, 105, 150, 150) For Each gd As GraphData In occupancy TotalCount += gd.percentageocc Next Dim g As Graphics = e.Graphics ' Create variables to hold the changing values of Angles g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality Dim StartAngle As Single = 0 Dim SweepAngle As Single = 0 For Each gd As GraphData In occupancy SweepAngle = 360 * gd.percentageocc / TotalCount g.FillPie(New SolidBrush(gd.Clr), rect, StartAngle, SweepAngle) StartAngle += SweepAngle Next ' g.DrawPie(New Pen(Color.Brown), rect, StartAngle, SweepAngle) ' Create a Brush to draw the text Dim TextBrsh As Brush = New SolidBrush(Color.Black) ' Create a Font object instance for text display Dim TextFont As New Font("Arial", 12, FontStyle.Bold) g.DrawString("Chart Key", TextFont, TextBrsh, 310, 100) Dim pxFromTop As Integer = 135 For Each gd As GraphData In occupancy ' Draw bullet g.FillEllipse(New SolidBrush(gd.Clr), 310, pxFromTop, 15, 15) ' Draw line round bullet. g.DrawEllipse(New Pen(Color.Black), 310, pxFromTop, 15, 15) ' Draw the text - color coded g.DrawString(gd.Description & " (" & gd.percentageocc & "%)", TextFont, TextBrsh, 360, pxFromTop) ' Increase gap from Top for next line pxFromTop += 30 Next End Sub

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, some remarks: 1. You can force a redraw by calling Invalidate() on the Control that does the drawing, in your case a Form. 2. Please, please publish code snippets inside PRE tags; it reads much better. 3. You must call Dispose() on those objects that you create and havre such a class, as in SolidBrush and Pen. 4. For predefined colors there also exist predefined objects (Pen, Brush), see Pens class and Brushes class. You should not try to dispose these, since you did not create them! :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        this months tips: - use PRE tags to preserve formatting when showing multi-line code snippets - before you ask a question here, search CodeProject, then Google


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups