Exemplo n.º 1
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case NativeMethods.TB_SETBUTTONINFO:
                NativeMethods.TBBUTTONINFO tbrInfo = default(NativeMethods.TBBUTTONINFO);
                tbrInfo = (NativeMethods.TBBUTTONINFO)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.TBBUTTONINFO));

                if ((tbrInfo.dwMask & NativeMethods.TBIF_SIZE) == NativeMethods.TBIF_SIZE)
                {
                    // If the .net wrapper is trying to set the size, then prevent this
                    tbrInfo.dwMask = tbrInfo.dwMask ^ NativeMethods.TBIF_SIZE;
                }

                if ((tbrInfo.dwMask & NativeMethods.TBIF_STYLE) == NativeMethods.TBIF_STYLE)
                {
                    if ((tbrInfo.fsStyle & NativeMethods.BTNS_AUTOSIZE) != NativeMethods.BTNS_AUTOSIZE)
                    {
                        // Make sure that the autosize style is set for all buttons, and doesn't
                        // get inadvertantly unset at any point by the .net wrapper
                        tbrInfo.fsStyle = (byte)(tbrInfo.fsStyle | NativeMethods.BTNS_AUTOSIZE);
                    }
                }

                Marshal.StructureToPtr(tbrInfo, m.LParam, true);
                break;
            }

            base.WndProc(ref m);
        }
Exemplo n.º 2
0
        public void SetWholeDropDown(ToolBarButton button)
        {
            if (button == null)
            {
                throw new ArgumentNullException("button");
            }

            if (!this.wholeDropDownButtons.Contains(button))
            {
                this.wholeDropDownButtons.Add(button);

                if (!OsUtils.Windows())
                {
                    // Append a down arrow as BTNS_WHOLEDROPDOWN is only supported under Windows
                    button.Text += " ▾";
                }
            }

            NativeMethods.TBBUTTONINFO buttonInfo = default(NativeMethods.TBBUTTONINFO);

            buttonInfo.cbSize  = Marshal.SizeOf(buttonInfo);
            buttonInfo.dwMask  = NativeMethods.TBIF_STYLE | NativeMethods.TBIF_BYINDEX;
            buttonInfo.fsStyle = NativeMethods.BTNS_WHOLEDROPDOWN | NativeMethods.BTNS_AUTOSIZE;

            NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONINFO, (IntPtr)this.Buttons.IndexOf(button), ref buttonInfo);
        }