2

I have the bindingnavigator control with 5 items including a toolstripdownbutton. I programmatically add a toolstripcontrolhost that contains a panel to the toolstripdownbutton. When I open the dropdown first time, it shows in the location (0,0).During second and third times of dropdown opening the correct position. How do I fix this error?

FormTest formTest = new FormTest(); 
formTest.TopLevel = false; 
tsddbFormControl.DropDownItems.Clear(); 
formTest.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 
ToolStripControlHost host = new ToolStripControlHost(formTest);     
tsddbFormControl.DropDownItems.Add(host); 
formTest.Show();
King King
  • 61,710
  • 16
  • 105
  • 130
Albert
  • 51
  • 5
  • 2
    Please show your code – Vahid Nateghi Nov 18 '13 at 10:00
  • @VahidNateghi, sorry, I am not adding the panel control, I am adding the form. – Albert Nov 18 '13 at 10:08
  • it's strange that it happens only the first time, so I doubt your code **does** locate the toolstripcontrolhost but it's a little wrong so that the first time it's failed to do its job. – King King Nov 18 '13 at 10:08
  • @Albert anyway you need to post some code, it's hard to tell what the problem exactly is. – King King Nov 18 '13 at 10:09
  • We need to know exactly where you have tried to add the `toolstrpcontrolhost` ... – Vahid Nateghi Nov 18 '13 at 10:11
  • FormTest formTest = new FormTest(); formTest.TopLevel = false; tsddbFormControl.DropDownItems.Clear(); formTest.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; ToolStripControlHost host = new ToolStripControlHost(formTest); tsddbFormControl.DropDownItems.Add(host); formTest.Show(); – Albert Nov 18 '13 at 10:28
  • 2
    I can repro this problem. It is quite specific to embedding a Form with TopLevel = false, it doesn't go wrong with a control. Impossible to debug this and find the exact reason, it quacks like a subtle initialization order issue. Get ahead by actually using a UserControl instead of a Form. – Hans Passant Nov 18 '13 at 13:47

0 Answers0