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. .NET (Core and Framework)
  4. Panel_paint method

Panel_paint method

Scheduled Pinned Locked Moved .NET (Core and Framework)
question
5 Posts 4 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.
  • R Offline
    R Offline
    reshsilk
    wrote on last edited by
    #1

    Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC

    R G 2 Replies Last reply
    0
    • R reshsilk

      Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      reshsilk wrote:

      the paint method is being called over and over again

      This will happen if you put a breakpoint in the paint method, which causes focus to transfer back to Visual Studio, thereby invalidating the panel. The process will repeat ad infinitum. To verify the paint method is being called more times than it should, replace the breakpoint with a Debug.Trace() call and inspect the contents of the Output window. Another reason for the paint method being called repeatedly may be programmer error - eg: invalidating the panel (in code) from within the paint method. Hope this helps! /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      R 1 Reply Last reply
      0
      • R reshsilk

        Hi, I'm trying to use the paint method to draw a table on a panel in a windows form. For some reason, the paint method is being called over and over again (I don't even know how many times!) when the form is opened. Does anybody know why this is happening? I'm fairly new to all this, so any insight is much appreciated. Thanks! RC

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Please don't cross post. --- b { font-weight: normal; }

        1 Reply Last reply
        0
        • R Ravi Bhavnani

          reshsilk wrote:

          the paint method is being called over and over again

          This will happen if you put a breakpoint in the paint method, which causes focus to transfer back to Visual Studio, thereby invalidating the panel. The process will repeat ad infinitum. To verify the paint method is being called more times than it should, replace the breakpoint with a Debug.Trace() call and inspect the contents of the Output window. Another reason for the paint method being called repeatedly may be programmer error - eg: invalidating the panel (in code) from within the paint method. Hope this helps! /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

          R Offline
          R Offline
          reshsilk
          wrote on last edited by
          #4

          hi ravi, i did have a breakpoint in the paint method, which i removed. but it still appears to be firing multiple times. i am trying to redraw a panel in a windows form when a particular button is clicked. here is part of the code... private void srchPlatesBtn_Click(object sender, EventArgs e) { getPlates(); split.Panel2.Invalidate(); } private void split_Panel2_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; drawPlateResults(g); } private void drawPlateResults(Graphics g) { // code to draw the table in the panel goes here } Do you know of any other way to force the panel to redraw? Thanks for all your help, RC

          R 1 Reply Last reply
          0
          • R reshsilk

            hi ravi, i did have a breakpoint in the paint method, which i removed. but it still appears to be firing multiple times. i am trying to redraw a panel in a windows form when a particular button is clicked. here is part of the code... private void srchPlatesBtn_Click(object sender, EventArgs e) { getPlates(); split.Panel2.Invalidate(); } private void split_Panel2_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; drawPlateResults(g); } private void drawPlateResults(Graphics g) { // code to draw the table in the panel goes here } Do you know of any other way to force the panel to redraw? Thanks for all your help, RC

            R Offline
            R Offline
            Robert Rohde
            wrote on last edited by
            #5

            reshsilk wrote:

            Do you know of any other way to force the panel to redraw?

            You are principally doing this right. Put somethin like a Console.WriteLine statement into your drawing code to really check if your Panel gets painted multiple times (which I don`t think seeing your code). Like already stated the Panel might not only redraw when you call Invalidate but for example also whenever you move a window on top of your app.

            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