Ejemplo n.º 1
0
        private void NotifyCustomDrawMenuBar(ref Message m)
        {
            m.Result = (IntPtr)NativeMethods.CDRF_DODEFAULT;
            NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW)m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW));

            bool hot      = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0);
            bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0);

            if (hot || selected)
            {
                NativeMethods.RECT rect = tbcd.nmcd.rc;

                using (Graphics graphics = Graphics.FromHdc(tbcd.nmcd.hdc))
                {
                    graphics.FillRectangle(SystemBrushes.Highlight, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
                }

                using (TextGraphics textGraphics = new TextGraphics(tbcd.nmcd.hdc))
                {
                    Font   font  = this.Font;
                    string text  = this.items[tbcd.nmcd.dwItemSpec].Text;
                    Size   size  = textGraphics.MeasureText(text, font);
                    Point  point = new Point(rect.left + ((rect.right - rect.left - size.Width) / 2), rect.top + ((rect.bottom - rect.top - size.Height) / 2));
                    textGraphics.DrawText(text, point, font, SystemColors.HighlightText);
                }

                m.Result = (IntPtr)NativeMethods.CDRF_SKIPDEFAULT;
            }
        }
Ejemplo n.º 2
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (!this.Enabled)
            {
                e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds);
            }
            else
            {
                e.DrawBackground();

                string fontName = null;
                if (e.Index == -1)
                {
                    // Text shown in the combobox itself
                    fontName = this.Text;
                }
                else
                {
                    fontName = (string)this.Items[e.Index];
                }

                Font font = null;
                if ((fontName != null) && (fontName.Length != 0))
                {
                    try
                    {
                        FontFamily fontFamily = new FontFamily(fontName);
                        FontStyle fontStyle = FontStyle.Regular;
                        if (!fontFamily.IsStyleAvailable(fontStyle))
                        {
                            fontStyle = FontStyle.Italic;
                            if (!fontFamily.IsStyleAvailable(fontStyle))
                            {
                                fontStyle = FontStyle.Bold;
                                if (!fontFamily.IsStyleAvailable(fontStyle))
                                {
                                    throw new NotSupportedException();
                                }
                            }
                        }

                        font = new Font(fontName, (float)((e.Bounds.Height - 2) / 1.2), fontStyle, GraphicsUnit.Pixel);
                    }
                    catch (Exception)
                    {
                    }
                }

                Rectangle textBounds = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top, e.Bounds.Width - 2, e.Bounds.Height);
                using (TextGraphics textGraphics = new TextGraphics(e.Graphics))
                {
                    textGraphics.DrawText(fontName, textBounds.Location, (font != null) ? font : e.Font, e.ForeColor);
                }

                if (font != null)
                {
                    font.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
            private void DrawText(TextGraphics textGraphics, string text, Point point, bool selected, bool disabled)
            {
                Color color = (disabled ? (selected ? SystemColors.GrayText : SystemColors.ControlDark) : (selected ? SystemColors.HighlightText : SystemColors.MenuText));

                if ((!this.IsFlatMenu) && (disabled) && (!selected))
                {
                    textGraphics.DrawText(text, new Point(point.X + 1, point.Y + 1), font, SystemColors.ControlLightLight);
                }

                textGraphics.DrawText(text, point, font, color);
            }
Ejemplo n.º 4
0
        private void UpdateSize()
        {
            if (this.style == CommandBarStyle.Menu)
            {
                int fontHeight = Font.Height;

                using (Graphics graphics = this.CreateGraphics())
                {
                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        foreach (CommandBarItem item in items)
                        {
                            Size textSize = textGraphics.MeasureText(item.Text, this.Font);
                            if (fontHeight < textSize.Height)
                            {
                                fontHeight = textSize.Height;
                            }
                        }
                    }
                }

                NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONSIZE, 0, (fontHeight << 16) | 0xffff);
            }

            Size size = new Size(0, 0);

            for (int i = 0; i < items.Count; i++)
            {
                NativeMethods.RECT rect = new NativeMethods.RECT();
                NativeMethods.SendMessage(Handle, NativeMethods.TB_GETRECT, i, ref rect);
                int height = rect.bottom - rect.top;
                if (height > size.Height)
                {
                    size.Height = height;
                }

                size.Width += rect.right - rect.left;

                CommandBarComboBox comboBox = items[i] as CommandBarComboBox;
                if ((comboBox != null) && (comboBox.ComboBox != null))
                {
                    if (comboBox.ComboBox.Height > size.Height)
                    {
                        size.Height = comboBox.ComboBox.Height;
                    }

                    this.UpdateComboBoxLocation(comboBox, i);
                }
            }

            this.Size = size;
        }
Ejemplo n.º 5
0
            protected override void OnDrawItem(DrawItemEventArgs e)
            {
                base.OnDrawItem(e);

                Graphics  graphics = e.Graphics;
                Rectangle bounds   = e.Bounds;

                bool selected = ((e.State & DrawItemState.Selected) != 0);
                bool disabled = ((e.State & DrawItemState.Disabled) != 0);

                if (item is CommandBarSeparator)
                {
                    Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height);
                    ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top);
                }
                else
                {
                    this.DrawImage(graphics, bounds, selected, disabled);

                    int width = 6 + imageSize.Width;
                    this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected);

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        if ((this.Text != null) && (this.Text.Length != 0))
                        {
                            Size  size  = textGraphics.MeasureText(this.Text, font);
                            Point point = new Point();
                            point.X = bounds.X + 3 + imageSize.Width + 6;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, this.Text, point, selected, disabled);
                        }

                        CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                        if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                        {
                            string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);

                            Size size = textGraphics.MeasureText(text, font);

                            Point point = new Point();
                            point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, text, point, selected, disabled);
                        }
                    }
                }
            }
Ejemplo n.º 6
0
            protected override void OnMeasureItem(MeasureItemEventArgs e)
            {
                base.OnMeasureItem(e);
                Graphics graphics = e.Graphics;

                if (item is CommandBarSeparator)
                {
                    e.ItemWidth  = 0;
                    e.ItemHeight = SystemInformation.MenuHeight / 2;
                }
                else
                {
                    Size size = new Size(0, 0);
                    size.Width  += 3 + imageSize.Width + 3 + 3 + 1 + 3 + imageSize.Width + 3;
                    size.Height += 3 + imageSize.Height + 3;

                    string text = item.Text;

                    CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                    if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                    {
                        text += TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);
                    }

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        Size textSize = textGraphics.MeasureText(text, font);
                        size.Width      += textSize.Width;
                        textSize.Height += 8;
                        if (textSize.Height > size.Height)
                        {
                            size.Height = textSize.Height;
                        }
                    }

                    e.ItemWidth  = size.Width;
                    e.ItemHeight = size.Height;
                }
            }
Ejemplo n.º 7
0
		private void NotifyCustomDrawMenuBar(ref Message m)		
		{
			m.Result = (IntPtr) NativeMethods.CDRF_DODEFAULT;
			NativeMethods.LPNMTBCUSTOMDRAW tbcd = (NativeMethods.LPNMTBCUSTOMDRAW) m.GetLParam(typeof(NativeMethods.LPNMTBCUSTOMDRAW));

			bool hot = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_HOT) != 0);
			bool selected = ((tbcd.nmcd.uItemState & NativeMethods.CDIS_SELECTED) != 0);

			if (hot || selected)
			{
				NativeMethods.RECT rect = tbcd.nmcd.rc;

				using (Graphics graphics = Graphics.FromHdc(tbcd.nmcd.hdc))
				{
					graphics.FillRectangle(SystemBrushes.Highlight, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
				}

				using (TextGraphics textGraphics = new TextGraphics(tbcd.nmcd.hdc))
				{
					Font font = this.Font;
					string text = this.items[tbcd.nmcd.dwItemSpec].Text;
					Size size = textGraphics.MeasureText(text, font);
					Point point = new Point(rect.left + ((rect.right - rect.left - size.Width) / 2), rect.top + ((rect.bottom - rect.top - size.Height) / 2));
					textGraphics.DrawText(text, point, font, SystemColors.HighlightText);
				}

				m.Result = (IntPtr) NativeMethods.CDRF_SKIPDEFAULT;
			}
		}
Ejemplo n.º 8
0
		private void UpdateSize()
		{
			if (this.style == CommandBarStyle.Menu)
			{
				int fontHeight = Font.Height;

				using (Graphics graphics = this.CreateGraphics())
				{
					using (TextGraphics textGraphics = new TextGraphics(graphics))
					{
						foreach (CommandBarItem item in items)
						{
							Size textSize = textGraphics.MeasureText(item.Text, this.Font);
							if (fontHeight < textSize.Height)
							{
								fontHeight = textSize.Height;
							}
						}
					}
				}

				NativeMethods.SendMessage(this.Handle, NativeMethods.TB_SETBUTTONSIZE, 0, (fontHeight << 16) | 0xffff);
			}

			Size size = new Size(0, 0);
			for (int i = 0; i < items.Count; i++)
			{
				NativeMethods.RECT rect = new NativeMethods.RECT();
				NativeMethods.SendMessage(Handle, NativeMethods.TB_GETRECT, i, ref rect);
				int height = rect.bottom - rect.top;
				if (height > size.Height)
				{
					size.Height = height;
				}

				size.Width += rect.right - rect.left;
			}

			this.Size = size;
		}
Ejemplo n.º 9
0
			private void DrawText(TextGraphics textGraphics, string text, Point point, bool selected, bool disabled)
			{
				Color color = (disabled ? (selected ? SystemColors.GrayText : SystemColors.ControlDark) : (selected ? SystemColors.HighlightText : SystemColors.MenuText));	
				
				if ((!this.IsFlatMenu) && (disabled) && (!selected))
				{
					textGraphics.DrawText(text, new Point(point.X + 1, point.Y + 1), font, SystemColors.ControlLightLight);
				}

				textGraphics.DrawText(text, point, font, color);
			}
Ejemplo n.º 10
0
			protected override void OnDrawItem(DrawItemEventArgs e)
			{
				base.OnDrawItem(e);
				
				Graphics graphics = e.Graphics;
				Rectangle bounds = e.Bounds;

				bool selected = ((e.State & DrawItemState.Selected) != 0);
				bool disabled = ((e.State & DrawItemState.Disabled) != 0);

				if (item is CommandBarSeparator)
				{
					Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height);
					ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top);
				}
				else
				{
					this.DrawImage(graphics, bounds, selected, disabled);

					int width = 6 + imageSize.Width;
					this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected);

					using (TextGraphics textGraphics = new TextGraphics(graphics))
					{
						if ((this.Text != null) && (this.Text.Length != 0))
						{
							Size size = textGraphics.MeasureText(this.Text, font);
							Point point = new Point();
							point.X = bounds.X + 3 + imageSize.Width + 6;
							point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
							this.DrawText(textGraphics, this.Text, point, selected, disabled);
						}

						CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
						if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
						{
							string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);

							Size size = textGraphics.MeasureText(text, font);

							Point point = new Point();
							point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width;
							point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
							this.DrawText(textGraphics, text, point, selected, disabled);
						}
					}
				}
			}
Ejemplo n.º 11
0
			protected override void OnMeasureItem(MeasureItemEventArgs e)
			{
				base.OnMeasureItem(e);
				Graphics graphics = e.Graphics;

				if (item is CommandBarSeparator)
				{
					e.ItemWidth = 0;
					e.ItemHeight = SystemInformation.MenuHeight / 2;
				}
				else
				{
					Size size = new Size(0, 0);
					size.Width += 3 + imageSize.Width + 3 + 3 + 1 + 3 + imageSize.Width + 3;
					size.Height += 3 + imageSize.Height + 3;

					string text = item.Text;

					CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
					if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
					{
						text += TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);
					}

					using (TextGraphics textGraphics = new TextGraphics(graphics))
					{
						Size textSize = textGraphics.MeasureText(text, font);
						size.Width += textSize.Width;
						textSize.Height += 8;
						if (textSize.Height > size.Height)
						{
							size.Height = textSize.Height;
						}
					}

					e.ItemWidth = size.Width;
					e.ItemHeight = size.Height;
				}
			}