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. C#
  4. Paint Method C#

Paint Method C#

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
3 Posts 2 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

    Hello, I'm making a windows form app using c#. In one form, I am "Painting" a table in a panel. When a button on the form is clicked, I would like to repaint the panel using specified parameters. Does anybody know how to do this? Here is some of the code: private void goBtn_Click(object sender, EventArgs e) { pltNum = pltList.SelectedIndex; tblPanel_Paint(object sender, PaintEventArgs e); } I guess I'm not sure what parameters I should pass to the tblPanel_Paint method. Thanks for your help! RC

    A 1 Reply Last reply
    0
    • R reshsilk

      Hello, I'm making a windows form app using c#. In one form, I am "Painting" a table in a panel. When a button on the form is clicked, I would like to repaint the panel using specified parameters. Does anybody know how to do this? Here is some of the code: private void goBtn_Click(object sender, EventArgs e) { pltNum = pltList.SelectedIndex; tblPanel_Paint(object sender, PaintEventArgs e); } I guess I'm not sure what parameters I should pass to the tblPanel_Paint method. Thanks for your help! RC

      A Offline
      A Offline
      Alexander Wiseman
      wrote on last edited by
      #2

      RC, To force the Windows Form to redraw, you should use the Invalidate function, rather than calling the paint event handler directly. For information on that function, have a look at Control.Invalidate[^] from MSDN. The important thing to note about the Invalidate function in that article is this sentence: "Calling the Invalidate method does not force a synchronous paint; to force a synchronous paint, call the Update method after calling the Invalidate method. When this method is called with no parameters, the entire client area is added to the update region." This simply means that when the Invalidate function returns, the control has not necessarily been redrawn yet. Thus it is possible that, after the user has clicked your "Go" button, the form does not redraw itself (although in normal usage, you won't really be able to tell). Nevertheless, as the MSDN documentation says, to force the redraw immediately, simply call the Update function after you call Invalidate. Here is how your code would look:

      private void goBtn_Click(object sender, EventArgs e)
      {
      pltNum = pltList.SelectedIndex;
      this.Invalidate();
      this.Update()
      }

      Let me know if that works for you, or if you still have a difficulty, I will try to help you as best I can. Sincerely, Alexander Wiseman

      R 1 Reply Last reply
      0
      • A Alexander Wiseman

        RC, To force the Windows Form to redraw, you should use the Invalidate function, rather than calling the paint event handler directly. For information on that function, have a look at Control.Invalidate[^] from MSDN. The important thing to note about the Invalidate function in that article is this sentence: "Calling the Invalidate method does not force a synchronous paint; to force a synchronous paint, call the Update method after calling the Invalidate method. When this method is called with no parameters, the entire client area is added to the update region." This simply means that when the Invalidate function returns, the control has not necessarily been redrawn yet. Thus it is possible that, after the user has clicked your "Go" button, the form does not redraw itself (although in normal usage, you won't really be able to tell). Nevertheless, as the MSDN documentation says, to force the redraw immediately, simply call the Update function after you call Invalidate. Here is how your code would look:

        private void goBtn_Click(object sender, EventArgs e)
        {
        pltNum = pltList.SelectedIndex;
        this.Invalidate();
        this.Update()
        }

        Let me know if that works for you, or if you still have a difficulty, I will try to help you as best I can. Sincerely, Alexander Wiseman

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

        Hi Alexander, The invalidate method worked! Thanks for your help!! RC

        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