/// <include file='doc\ToolBar.uex' path='docs/doc[@for="ToolBar.InternalSetButton"]/*' />
/// <devdoc>
/// Changes the data for a button in the ToolBar, and then does the appropriate
/// work to update the ToolBar control.
/// </devdoc>
/// <internalonly/>
internal void InternalSetButton(int index, ToolBarButton value, bool recreate, bool updateText) {
// tragically, there doesn't appear to be a way to remove the
// string for the button if it has one, so we just have to leave
// it in there.
//
buttons[index].parent = null;
buttons[index].stringIndex = (IntPtr)(-1);
buttons[index] = value;
buttons[index].parent = this;
if (IsHandleCreated) {
NativeMethods.TBBUTTONINFO tbbi = value.GetTBBUTTONINFO(updateText, index);
UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), NativeMethods.TB_SETBUTTONINFO, index, ref tbbi);
if (tbbi.pszText != IntPtr.Zero) {
Marshal.FreeHGlobal(tbbi.pszText);
}
if (recreate) {
UpdateButtons();
}
else {
// after doing anything with the comctl ToolBar control, this
// appears to be a good idea.
//
SendMessage(NativeMethods.TB_AUTOSIZE, 0, 0);
ForceButtonWidths();
this.Invalidate();
}
}
}