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. Panel Issues

Panel Issues

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 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.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?

    L A 2 Replies Last reply
    0
    • A aei_totten

      I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?

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

      Hi, Threads (all kinds of them, including ThreadPool threads, and BackgroundWorkers) other than the thread that created a Control (BTW: a Form is also a Control), should not access that Control, except for the very few members explicitly allowed, including InvokeRequired and Invoke. Before .NET 2.0 the app may behave badly, the GUI may freeze, anything can go wrong if you violate the rule. Since 2.0 you get an InvalidOperationException by default; you can disable that by setting Control.CheckForIllegalCrossThreadCalls false, but that is a very bad idea, and it brings you back in the previous situation. Since most if not all Controls are somehow related (they are on a Form, one Form owns another Form, etc), the natural consequence is all Controls get created and accessed exclusively by a single thread, typically your initial or main thread, often also called the "GUI thread". There are lots of examples on InvokeRequired/Invoke available everywhere; a rather advanced article on the subject is here. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      1 Reply Last reply
      0
      • A aei_totten

        I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?

        A Offline
        A Offline
        aei_totten
        wrote on last edited by
        #3

        OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue. Edited to add: Weird I didn't see that last reply until after I posted this. I will check out the link. Thanks

        A 1 Reply Last reply
        0
        • A aei_totten

          OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue. Edited to add: Weird I didn't see that last reply until after I posted this. I will check out the link. Thanks

          A Offline
          A Offline
          aei_totten
          wrote on last edited by
          #4

          OKay I got it.

              static void SetVisible(Control ctrl, bool visible) 
              {
                  if (ctrl.InvokeRequired) 
                  {
                      object\[\] params\_list = new object\[\] { ctrl, visible };
                      ctrl.Invoke(new SetVisibleDelegate(SetVisible), params\_list);
          
                  }
                  else 
                  {
                      ctrl.Visible = visible;
                  }
            }
          
          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