locked
Tabcontrol problem(big problem) RRS feed

  • Question

  • Hi

    sorry about my English

    I have a problem with  tabcontrol, i'm coding about lanchat, after i receive packet "Authenticated" I want to add a tabpage into Tabcontrol, but after that the form didn't show any tabpage. When i debug i recognize that the tabcontrol was reseted after completed event receive command Authenticated. The code here

    private void HandleUserAuthenticated(ChatEventArgs cea) //receive command from server
        {
          
          TabPage tabpage = new TabPage("ChatRoom");
    
          _tabControl.Controls.Add(tabpage); //_tabControl is Tabcontrol
        }
    

    I don't know why?

    Have anyone get this problem yet?

    Saturday, May 21, 2011 7:27 AM

Answers

  • I'm not sure about the tabcontrol being reset after receiving a command, however i can see that you are adding a child control to a control that was created on the UI thread from another thread (Message CallBack). You need to check for InvokeRequired -  
     if (_tabControl.InvokeRequired) {
    
       this.Invoke(new MethodInvoker(delegate() {
    
       _tabControl.Controls.Add(new TabPage());
    
       }));
    
      } else {
    
       _tabControl.Controls.Add(new TabPage());
    
      }
    
    
    
    

     


    Please mark this as answer or vote as helpful if it solved your problem
    • Marked as answer by Neddy Ren Friday, May 27, 2011 8:36 AM
    Tuesday, May 24, 2011 12:04 PM

All replies

  • Hi,

    You need to add a tab page on existing tab control right then you need to use

    _tabControl.TabPages.Add(tabpage);

    just try it and let me know


    Regards, Anoop
    Saturday, May 21, 2011 9:32 AM
  • Thank for your reply! I did it, but the result don't change. When I debug, I found out that after it fired events, the tabcontrol(_tabcontrol) was reseted and it's the same when it begin. And when I do it with Listview I have a same problem.

    Saturday, May 21, 2011 12:51 PM
  • Hi,

    Maybe this is not a programming issue. I've run the same code which I put it in the Form.Load. And I added it successfully.

    I use Windows7 enterprise 32bit OS.

    Or can you put a small demon here? I will take some time to have a test with your project!


    Knowledge will change the destiny.
    Monday, May 23, 2011 9:43 AM
  • Hi Nguyen Toan,

    We always use the TabControl.Controls.Add(new TabPage("...")) function to add controls to a tabcontrol and it works fine. Could you please upload a demon for us which shows your issue? We will be appreciate to help you to resolve your issue!

    Best Regards


    Neddy Ren [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 5:30 AM
  • I'm not sure about the tabcontrol being reset after receiving a command, however i can see that you are adding a child control to a control that was created on the UI thread from another thread (Message CallBack). You need to check for InvokeRequired -  
     if (_tabControl.InvokeRequired) {
    
       this.Invoke(new MethodInvoker(delegate() {
    
       _tabControl.Controls.Add(new TabPage());
    
       }));
    
      } else {
    
       _tabControl.Controls.Add(new TabPage());
    
      }
    
    
    
    

     


    Please mark this as answer or vote as helpful if it solved your problem
    • Marked as answer by Neddy Ren Friday, May 27, 2011 8:36 AM
    Tuesday, May 24, 2011 12:04 PM