Problem control in tabcontrol

Unanswered Problem control in tabcontrol

  • Sunday, August 19, 2012 9:53 AM
     
      Has Code

    I have created usercontrol.It contains RichTextBox and listbox.After the user presses the new button, SaveFileDialog will ask where to save the file.The UserControl is added to tabpage.Listbox appears when I enter dot in RTB.It works.I add tabpage (new button again).I get a problem when entering text.Listbox does not appear in the selected RichTextBox.Listbox always appears in the latest tabpage.
    for example:
    New button-> add tabpage
    I enter text in tabpage 1
    Listbox appears in tabpage2
    I need it to appear in tabapge1

    New button:

                SaveFileDialog savedlg = new SaveFileDialog();
                string filename = "";
                InitSaveDlg(savedlg);
                if (savedlg.ShowDialog() == DialogResult.OK && savedlg.FileName.Length > 0)
                {
                    filename = savedlg.FileName;
                    using (StreamWriter writer = new StreamWriter(savedlg.FileName))
                    {
                    }
                    filename = getFileName(filename);
                }
                if (filename.Length > 0)
                {
                    TabPage newTab = new TabPage(filename);
                    UserControl1 uc = new UserControl1();
                    uc.Name = "uc";
                    uc.Dock = DockStyle.Fill;
                    uc.BorderStyle = BorderStyle.None;
                    uc.rtb.LoadFile(filename, RichTextBoxStreamType.PlainText);
                    newTab.Controls.Add(uc);
                    tabControl1.TabPages.Add(newTab);
                    tabControl1.SelectedTab = newTab;
                }


    • Edited by tuanhp_1605 Sunday, August 19, 2012 12:18 PM
    •  

All Replies

  • Sunday, August 19, 2012 1:00 PM
     
     

    Probably the problem is in the fragment that deals with keyboard events and displays the listbox. Show some details.

  • Monday, August 20, 2012 4:51 AM
     
      Has Code

    //RTB_KeyDown
    if (e.KeyData == Keys.OemPeriod && dotcounter==0) { lblTooltip.Hide(); SetLstLocation(); listBox1.Items.Clear(); //add Item
    loadXML(listBox1, "do1"); listBox1.Focus(); //List.List.AutoSelect(textBox1.Text.Trim()); Key="do1"; } if (e.KeyData == Keys.OemPeriod && dotcounter == 1) { lblTooltip.Hide(); List.List.SetLstLocation(); listBox1.Items.Clear(); loadXML(listBox1, "do2"); listBox1.Focus(); //List.List.AutoSelect(textBox1.Text.Trim()); Key="do2"; }

    SetLstLocation:

            public static void SetLstLocation()
            {
                Point point = richTextBox1.GetPositionFromCharIndex(richTextBox1.SelectionStart);
                point.Y += (int)Math.Ceiling(richTextBox1.Font.GetHeight()) + richTextBox1.Location.Y; 
                point.X += richTextBox1.Location.X; 
                lst.Location = point;
                lst.Show();
            }


    • Edited by tuanhp_1605 Monday, August 20, 2012 4:52 AM
    •  
  • Monday, August 20, 2012 6:51 PM
     
     

    Use the Debugger and check if the code that fills and shows the list box is executed when you press keys. Then make sure the list box is visible and is not covered by other controls. Sometimes listBox1.BringToFront() helps. Also check if SetLstLocation and List.List.SetLstLocation correctly set the position of list box based on right Rich text box.

  • Tuesday, August 21, 2012 3:38 AM
    Moderator
     
     

    Hi tuanhp_1605,

    In the button click event handler, the code will set the new created tabpage as select tab. Are you sure that you enter the RichTextBox in the tabpage1.

    Base on my understanding, since both the RichTextBox and ListBox is a member of usercontrol, I think your current code will not display the ListBox in another control, could you please share a demo through SkyDrive?

    By the way, what is "lst" in the SetLstLocation method?

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, August 21, 2012 9:22 AM
     
     
     I added BringToFront.But not improve results.Listbox appears correctly in latest tabpage.If I enter text in the newest tabpage,everything is good.I open the tabpage1.Next,Enter text.I am just found listbox after re-open the latest tabpage.Listbox cannot be displayed in currently tabpage.
  • Tuesday, August 21, 2012 9:26 AM
     
     
    lst is public Listbox lst in My class.I get good results when only one tabpage.
  • Wednesday, August 22, 2012 10:15 AM
    Moderator
     
     

    Hi tuanhp_1605,

    If lst is public ListBox, so what's ListBox1?

    Would you mind share a demo through SkyDrive? It would be help us to understand your issue clearly.

    Thanks.

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us