public CommandBarComboBox AddComboBox(string text, ComboBox comboBox) { FlatControl fc = new FlatControl(); fc.Attach(comboBox); flatControl.Add(fc); CommandBarComboBox item = new CommandBarComboBox(text, comboBox); this.Add(item); return(item); }
private void AddItems() { NativeMethods.SendMessage(Handle, NativeMethods.TB_BUTTONSTRUCTSIZE, Marshal.SizeOf(typeof(NativeMethods.TBBUTTON)), 0); int extendedStyle = NativeMethods.TBSTYLE_EX_HIDECLIPPEDBUTTONS | NativeMethods.TBSTYLE_EX_DOUBLEBUFFER; if (style == CommandBarStyle.ToolBar) { extendedStyle |= NativeMethods.TBSTYLE_EX_DRAWDDARROWS; } NativeMethods.SendMessage(Handle, NativeMethods.TB_SETEXTENDEDSTYLE, 0, extendedStyle); this.UpdateImageList(); for (int i = 0; i < items.Count; i++) { NativeMethods.TBBUTTON button = new NativeMethods.TBBUTTON(); button.idCommand = i; NativeMethods.SendMessage(this.Handle, NativeMethods.TB_INSERTBUTTON, i, ref button); NativeMethods.TBBUTTONINFO buttonInfo = this.GetButtonInfo(i); NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONINFO, i, ref buttonInfo); } // Add ComboBox controls. this.Controls.Clear(); for (int i = 0; i < items.Count; i++) { CommandBarComboBox comboBox = this.items[i] as CommandBarComboBox; if (comboBox != null) { NativeMethods.RECT rect = new NativeMethods.RECT(); NativeMethods.SendMessage(this.Handle, NativeMethods.TB_GETITEMRECT, i, ref rect); rect.top = rect.top + (((rect.bottom - rect.top) - comboBox.Height) / 2); comboBox.ComboBox.Location = new Point(rect.left, rect.top); this.Controls.Add(comboBox.ComboBox); } } this.UpdateSize(); }
private NativeMethods.TBBUTTONINFO GetButtonInfo(int index) { CommandBarItem item = items[index]; NativeMethods.TBBUTTONINFO buttonInfo = new NativeMethods.TBBUTTONINFO(); buttonInfo.cbSize = Marshal.SizeOf(typeof(NativeMethods.TBBUTTONINFO)); buttonInfo.dwMask = NativeMethods.TBIF_IMAGE | NativeMethods.TBIF_STATE | NativeMethods.TBIF_STYLE | NativeMethods.TBIF_COMMAND | NativeMethods.TB_DELETEBUTTON; buttonInfo.idCommand = index; buttonInfo.iImage = NativeMethods.I_IMAGECALLBACK; buttonInfo.fsStyle = NativeMethods.BTNS_BUTTON | NativeMethods.BTNS_AUTOSIZE; buttonInfo.fsState = 0; buttonInfo.cx = 0; buttonInfo.lParam = IntPtr.Zero; buttonInfo.pszText = IntPtr.Zero; buttonInfo.cchText = 0; if (!item.IsVisible) { buttonInfo.fsState |= NativeMethods.TBSTATE_HIDDEN; } CommandBarComboBox comboBox = item as CommandBarComboBox; if (comboBox != null) { buttonInfo.cx = (short)(comboBox.Width + 4); buttonInfo.dwMask = NativeMethods.TBIF_SIZE; } if (item is CommandBarSeparator) { buttonInfo.fsStyle |= NativeMethods.BTNS_SEP; } else { if (item.IsEnabled) { buttonInfo.fsState |= NativeMethods.TBSTATE_ENABLED; } CommandBarMenu menu = item as CommandBarMenu; if ((menu != null) && (menu.Items.Count > 0)) { buttonInfo.fsStyle |= NativeMethods.BTNS_DROPDOWN; } if (style == CommandBarStyle.ToolBar) { if (item is CommandBarMenu) { buttonInfo.fsStyle |= NativeMethods.BTNS_WHOLEDROPDOWN; } } CommandBarCheckBox checkBox = item as CommandBarCheckBox; if ((checkBox != null) && (checkBox.IsChecked)) { buttonInfo.fsState |= NativeMethods.TBSTATE_CHECKED; } } if (item is CommandBarSeparator) { buttonInfo.iImage = NativeMethods.I_IMAGENONE; } else if (item.Image != null) { buttonInfo.iImage = index; } if ((this.Style == CommandBarStyle.Menu) && (item.Text != null) && (item.Text.Length != 0)) { buttonInfo.dwMask |= NativeMethods.TBIF_TEXT; buttonInfo.pszText = Marshal.StringToHGlobalUni(item.Text + "\0"); buttonInfo.cchText = item.Text.Length; } return(buttonInfo); }