void DrawButtonImageAndText(PaintEventArgs e, TabBarButton button, UIControlStatus ucs) { if (button.Icon != null && string.IsNullOrEmpty(button.Text)) { PaintHelper.DrawImageInRange(e.Graphics, button.Icon, button.Bounds); } else if (button.Icon == null && string.IsNullOrEmpty(button.Text)) { DrawButtonText(e, button, ucs); } else { Size size = Size.Ceiling(e.Graphics.MeasureString(button.Text, Bar.Font)); size.Width += button.Icon.Width; Rectangle rect = new Rectangle( button.Bounds.X + (button.Bounds.Width - size.Width) / 2, button.Bounds.Y + (button.Bounds.Height - size.Height) / 2, size.Width, size.Height); e.Graphics.DrawImage(button.Icon, new Rectangle(rect.Left, rect.Top + (rect.Height - button.Icon.Height) / 2, button.Icon.Width, button.Icon.Height), 0, 0, button.Icon.Width, button.Icon.Height, GraphicsUnit.Pixel); rect.X += button.Icon.Width; rect.Width -= button.Icon.Width; e.Graphics.DrawString(button.Text, Bar.Font, new SolidBrush(Bar.ForeColor), rect, PaintHelper.SFCenter); } }
void DrawButtonText(PaintEventArgs e, TabBarButton button, UIControlStatus ucs) { if (Bar != null) { e.Graphics.DrawString(button.Text, Bar.Font, new SolidBrush(Bar.ForeColor), button.Bounds, PaintHelper.SFCenter); } }
protected virtual void DrawButtonBackground(PaintEventArgs e, TabBarButton button, UIControlStatus ucs) { Rectangle rect = button.Bounds; if (rect.Width <= 0 || rect.Height <= 0) { return; } Color backColor; if (button.IsDroppingDown) { //backColor = UITheme.Default.Colors.MenuImageMargin; backColor = Bar.SelectedItemBackColor; } else { switch (ucs) { case UIControlStatus.Hover: backColor = Bar.HoverItemBackColor; break; case UIControlStatus.Selected: backColor = Bar.SelectedItemBackColor; break; default: return; } } e.Graphics.FillRectangle(new SolidBrush(backColor), rect); }
void OnButtonMouseUp(int index) { TabBarButton button = GetButton(index); if (button != null) { button.OnMouseUp(); } }
void OnButtonClick(int index) { TabBarButton button = GetButton(index); if (button != null) { button.OnClick(); } }
public void InitializeButtons() { LeftButtons = new XList <TabBarButton>(); LeftButtons.ItemAdded += new XListEventHandler <TabBarButton>(Buttons_ItemAdded); RightButtons = new XList <TabBarButton>(); RightButtons.ItemAdded += new XListEventHandler <TabBarButton>(Buttons_ItemAdded); DropDownButton = new TabBarButton(); //DropDownButton.OwnerDraw = false; DropDownButton.Icon = Properties.Resources.chevron; DropDownButton.Visible = ShowDropDownButton; DropDownButton.Click += new EventHandler(DropDownButton_Click); //DropDownButton.Paint += new UIPaintEventHandler(DropDownButton_Paint); RightButtons.Add(DropDownButton); // InitializeSpecialTabs(); }
protected override void DrawButton(PaintEventArgs e, TabBarButton button, UIControlStatus ucs) { DrawButtonBackground(e, button, ucs); if (button.DisplayStyle == ToolStripItemDisplayStyle.Image) { if (button.Icon != null) { PaintHelper.DrawImageInRange(e.Graphics, button.Icon, button.Bounds); } } else if (button.DisplayStyle == ToolStripItemDisplayStyle.ImageAndText) { DrawButtonImageAndText(e, button, ucs); } else if (button.DisplayStyle == ToolStripItemDisplayStyle.Text) { DrawButtonText(e, button, ucs); } }
int LayoutRightButtons(int beginPos) { Rectangle rect = ClientRectangle; if (ShowBaseLine) { rect.Height -= BaseLineSize; } int buttonHeight = rect.Height - 4; float pos = beginPos; int index = LeftButtons.Count; for (int i = RightButtons.Count - 1; i >= 0; i--) { TabBarButton button = RightButtons[i]; button.Index = index + i; if (!button.Visible) { continue; } float size = button.CustomSize > 0 ? button.CustomSize : StandardButtonSize; RectangleF bounds; if (IsHorizontal) { bounds = new RectangleF(pos - size, rect.Top + (rect.Height - buttonHeight) / 2, size, buttonHeight); pos = bounds.Left; } else { bounds = new RectangleF(rect.Left + (rect.Width - buttonHeight) / 2, pos - size, buttonHeight, size); pos = bounds.Top; } button.Bounds = Rectangle.Ceiling(bounds); pos -= button.CustomSpace > 0 ? button.CustomSpace : ButtonSpace; } return((int)Math.Floor(rect.Right - pos)); }
protected abstract void DrawButton(PaintEventArgs e, TabBarButton button, UIControlStatus ucs);