示例#1
0
        // This is necessary to get the width of the buttons in the toolbar,
        // including the width of separators, so that we can accurately position the tooltip adjacent
        // to the currently hot button when the user uses keyboard navigation to access the toolbar.
        internal int GetButtonWidth()
        {
            // Assume that this button is the same width as the parent's ButtonSize's Width
            int buttonWidth = Parent.ButtonSize.Width;

            var button = new ComCtl32.TBBUTTONINFOW
            {
                cbSize = (uint)Marshal.SizeOf <ComCtl32.TBBUTTONINFOW>(),
                dwMask = ComCtl32.TBIF.SIZE
            };

            int buttonID = (int)User32.SendMessageW(Parent, (User32.WindowMessage)ComCtl32.TB.GETBUTTONINFOW, (IntPtr)commandId, ref button);

            if (buttonID != -1)
            {
                buttonWidth = button.cx;
            }

            return(buttonWidth);
        }
示例#2
0
        /// <summary>
        ///  Returns a TBBUTTONINFOW object that represents this ToolBarButton.
        /// </summary>
        internal ComCtl32.TBBUTTONINFOW GetTBBUTTONINFO(bool updateText, int newCommandId)
        {
            var button = new ComCtl32.TBBUTTONINFOW
            {
                cbSize = (uint)Marshal.SizeOf <ComCtl32.TBBUTTONINFOW>(),
                dwMask = ComCtl32.TBIF.IMAGE | ComCtl32.TBIF.STATE | ComCtl32.TBIF.STYLE
            };

            // Older platforms interpret null strings as empty, which forces the button to
            // leave space for text.
            // The only workaround is to avoid having comctl update the text.
            if (updateText)
            {
                button.dwMask |= ComCtl32.TBIF.TEXT;
            }

            button.iImage = ImageIndexer.ActualIndex;

            if (newCommandId != commandId)
            {
                commandId        = newCommandId;
                button.idCommand = newCommandId;
                button.dwMask   |= ComCtl32.TBIF.COMMAND;
            }

            // set up the state of the button
            button.fsState = 0;
            if (enabled)
            {
                button.fsState |= ComCtl32.TBSTATE.ENABLED;
            }

            if (partialPush && style == ToolBarButtonStyle.ToggleButton)
            {
                button.fsState |= ComCtl32.TBSTATE.INDETERMINATE;
            }

            if (pushed)
            {
                button.fsState |= ComCtl32.TBSTATE.CHECKED;
            }

            if (!visible)
            {
                button.fsState |= ComCtl32.TBSTATE.HIDDEN;
            }

            // set the button style
            switch (style)
            {
            case ToolBarButtonStyle.PushButton:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.BUTTON;
                break;

            case ToolBarButtonStyle.ToggleButton:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.CHECK;
                break;

            case ToolBarButtonStyle.Separator:
                button.fsStyle = (byte)ComCtl32.TBSTYLE.SEP;
                break;
            }

            if (text == null)
            {
                button.pszText = Marshal.StringToHGlobalAuto("\0\0");
            }
            else
            {
                string textValue = text;
                PrefixAmpersands(ref textValue);
                button.pszText = Marshal.StringToHGlobalAuto(textValue);
            }

            return(button);
        }