I'm trying to make a ToolStripTextBox that will take up all available space (like the address bar in IE). I tried to translate the C# code found in another thread to C++. Here is what I came up with:
private: System::Void toolStrip1_Layout(System::Object^ sender, System::Windows::Forms::LayoutEventArgs^ e)
{
int width = toolStrip1->DisplayRectangle.Width;
for (int index = 0; index < toolStrip1->Items->Count; ++index)
{
ToolStripItem ^curItem = toolStrip1->Items[index];
if (curItem != txtURL)
{
width -= curItem->Width;
width -= curItem->Margin.Horizontal;
}
}
txtURL->Width = Math::Max(0, width - txtURL->Margin.Horizontal);
}
It seems like it TRIES to work, but it never sticks. I traced through the method and at the end txtURL->Width does change. However, the next time into the loop, it's back to the default of 100. Visually, the toolstrip flickers as if it's drawing it at the correct size and then changing its mind (the fact that it happens when typing in the text box is a little strange, too). Here is a screenshot of what I mean
Any input would be appreciated.
private: System::Void toolStrip1_Layout(System::Object^ sender, System::Windows::Forms::LayoutEventArgs^ e)
{
int width = toolStrip1->DisplayRectangle.Width;
for (int index = 0; index < toolStrip1->Items->Count; ++index)
{
ToolStripItem ^curItem = toolStrip1->Items[index];
if (curItem != txtURL)
{
width -= curItem->Width;
width -= curItem->Margin.Horizontal;
}
}
txtURL->Width = Math::Max(0, width - txtURL->Margin.Horizontal);
}
It seems like it TRIES to work, but it never sticks. I traced through the method and at the end txtURL->Width does change. However, the next time into the loop, it's back to the default of 100. Visually, the toolstrip flickers as if it's drawing it at the correct size and then changing its mind (the fact that it happens when typing in the text box is a little strange, too). Here is a screenshot of what I mean
Any input would be appreciated.