protected override void WndProc(ref Message msg) { if (msg.Msg == (int)Win32.Msg.WM_LBUTTONDOWN) { Point p = tabControl.PointToClient(Cursor.Position); StiTabPage page = tabControl.GetTabPageAtPoint(p); if (page != null) { tabControl.SelectedTab = page; var controls = new ArrayList(); controls.Add(page); ISelectionService service = ((ISelectionService)this.GetService(typeof(ISelectionService))); service.SetSelectedComponents(controls); } } if (msg.Msg == (int)Win32.Msg.WM_MOUSEMOVE) { tabControl.Invalidate(); } if (msg.Msg == (int)Win32.Msg.WM_MOUSELEAVE) { tabControl.Invalidate(); } base.WndProc(ref msg); }
private void OnAddControl(object sender, EventArgs e) { IDesignerHost host = ((IDesignerHost)base.GetService(typeof(IDesignerHost))); DesignerTransaction transaction = host.CreateTransaction("Add Page"); StiTabPage control = ((StiTabPage)host.CreateComponent(typeof(StiTabPage))); this.tabControl.Controls.Add(control); control.Dock = DockStyle.Fill; this.tabControl.Invalidate(); transaction.Commit(); }
private int GetPageWidth(Graphics g, StiTabPage page) { int imageWidth = 0; if (ImageList != null && ImageList.Images.Count > this.Controls.IndexOf(page)) { imageWidth = ImageList.ImageSize.Width; } if (page.Image != null) { imageWidth = page.Image.Width; } return((int)(g.MeasureString(page.Text, Font, 1000, sfTabs).Width) + 10 + imageWidth); }
private Rectangle GetPageRectangle(Graphics g, StiTabPage page) { int startPos = GetPanelStartPos(); int width = 10; int allWidth = GetPagesWidth(g); double k = 1; if (allWidth + startPos * 2 + 5 > Width) { k = (double)Width / ((double)allWidth + (double)startPos * 2 + 5); } int index = 0; foreach (StiTabPage pg in this.Controls) { if ((!pg.Invisible) || DesignMode) { if (pg != page) { startPos += (int)(widthPages[index] * k); } else { width = (int)(widthPages[index] * k); break; } } index++; } Rectangle controlRect = Rectangle.Empty; if (PositionAtBottom) { controlRect = new Rectangle(startPos, Height - titleHeight - 1, width, titleHeight - 2); } else { controlRect = new Rectangle(startPos, 2, width, titleHeight - 2); } return(controlRect); }
protected override bool GetHitTest(Point point) { Rectangle rect; if (tabControl.PositionAtBottom) { rect = new Rectangle( 0, tabControl.ClientRectangle.Height - 22, tabControl.ClientRectangle.Width, 22); } else { rect = new Rectangle( 0, 0, tabControl.ClientRectangle.Width, 22); } StiTabPage page = tabControl.GetTabPageAtPoint(tabControl.PointToClient(point)); return(page != null); }
protected override void OnMouseDown(MouseEventArgs e) { Point pt = new Point(e.X, e.Y); using (Graphics g = Graphics.FromHwnd(this.Handle)) { CalculatePagesWidth(g); } StiTabPage tabPage = GetTabPageAtPoint(pt); if (tabPage != null && tabPage.Enabled) { SelectedTab = tabPage; InvokeTitleClick(this, e); if ((e.Button & MouseButtons.Right) > 0 && SelectedTab.TitleContextMenu != null) { SelectedTab.TitleContextMenu.Show(tabPage, tabPage.PointToClient(Cursor.Position)); } } base.OnMouseDown(e); }
public StiColorBoxPopupForm(Control colorBox, Color selectedColor, IWindowsFormsEditorService edSrv) : base(colorBox) { try { SuspendLayout(); #region InitializeComponent TabControl = new StiTabControl(); TabControl.SuspendLayout(); TabControl.Dock = DockStyle.Fill; TabControl.Paint += new System.Windows.Forms.PaintEventHandler(TabControl_Paint); this.Controls.Add(TabControl); tbCustom = new StiTabPage(); tbCustom.SuspendLayout(); tbCustom.Text = "Custom"; tbCustom.DockPadding.All = 4; TabControl.Controls.Add(tbCustom); tbWeb = new StiTabPage(); tbWeb.SuspendLayout(); tbWeb.Text = "Web"; tbWeb.DockPadding.All = 4; TabControl.Controls.Add(tbWeb); tbSystem = new StiTabPage(); tbSystem.SuspendLayout(); tbSystem.DockPadding.All = 4; tbSystem.Text = "System"; TabControl.Controls.Add(tbSystem); lbWeb = new ListBox(); lbWeb.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; lbWeb.Dock = DockStyle.Fill; lbWeb.IntegralHeight = false; lbWeb.TabStop = false; lbWeb.MouseMove += new System.Windows.Forms.MouseEventHandler(lbWeb_MouseMove); lbWeb.DrawItem += new System.Windows.Forms.DrawItemEventHandler(lbWeb_DrawItem); tbWeb.Controls.Add(lbWeb); lbSystem = new ListBox(); lbSystem.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable; lbSystem.Dock = DockStyle.Fill; lbSystem.IntegralHeight = false; lbSystem.TabStop = false; lbSystem.MouseMove += new System.Windows.Forms.MouseEventHandler(lbWeb_MouseMove); lbSystem.DrawItem += new System.Windows.Forms.DrawItemEventHandler(lbSystem_DrawItem); tbSystem.Controls.Add(lbSystem); btOther = new StiButton(); btOther.Location = new System.Drawing.Point(58, 216); btOther.Name = "Other..."; btOther.Size = new System.Drawing.Size(80, 23); btOther.Click += new System.EventHandler(btOther_Click); tbCustom.Controls.Add(btOther); TabControl.ResumeLayout(false); tbCustom.ResumeLayout(false); tbWeb.ResumeLayout(false); tbSystem.ResumeLayout(false); ResumeLayout(false); #endregion this.edSrv = edSrv; this.colorBox = colorBox; #region InitColors this.SelectedColor = selectedColor; InitColors(); this.lbSystem.SelectedIndex = -1; this.lbWeb.SelectedIndex = -1; bool stop = false; int index = 0; string colorName = selectedColor.ToString(); foreach (Color color in StiColors.SystemColors) { if (color.ToString() == colorName) { this.TabControl.SelectedIndex = 2; this.lbSystem.SelectedIndex = index; stop = true; break; } index++; } if (!stop) { index = 0; int sc = selectedColor.ToArgb(); foreach (Color color in StiColors.Colors) { if (color.ToArgb() == sc) { this.TabControl.SelectedIndex = 1; this.lbWeb.SelectedIndex = index; stop = true; break; } index++; } } if (!stop) { this.TabControl.SelectedIndex = 0; } #endregion if (!this.DesignMode) { Localize(); } } catch { } }
private void DrawPage(Graphics g, StiTabPage page) { if ((!page.Invisible) || DesignMode) { var rect = GetPageRectangle(g, page); if (rect.Width != 0 && rect.Height != 0) { #region Calculate Path var pts = new Point [] {}; #region Office2013 if (ControlStyle == StiControlStyle.Office2013Blue) { pts = new Point[] { new Point(rect.X, rect.Y), new Point(rect.X, rect.Bottom), new Point(rect.Right, rect.Bottom), new Point(rect.Right, rect.Y) }; } #endregion #region Flat else { if (!PositionAtBottom) { pts = new Point[] { new Point(rect.X, rect.Y), new Point(rect.X, rect.Bottom), new Point(rect.Right + 5, rect.Bottom), new Point(rect.Right - 5, rect.Y) }; } else { pts = new Point[] { new Point(rect.X, rect.Y), new Point(rect.X, rect.Bottom), new Point(rect.Right - 5, rect.Bottom), new Point(rect.Right + 5, rect.Y) }; } } #endregion #endregion using (var path = new GraphicsPath(FillMode.Alternate)) { path.AddPolygon(pts); #region Draw page header #region Office2013 if (ControlStyle == StiControlStyle.Office2013Blue) { if (SelectedTab == page) { using (var pathSelected = new GraphicsPath()) { pathSelected.AddPolygon(new[] { new Point(pts[0].X - 1, pts[0].Y - 1), new Point(pts[1].X - 1, pts[1].Y), new Point(pts[2].X + 1, pts[2].Y), new Point(pts[3].X + 1, pts[3].Y) }); using (var br = new SolidBrush(Color.White)) { g.FillPath(br, pathSelected); } } } else { using (var br = new SolidBrush(Color.White)) { g.FillPath(br, path); } } } #endregion #region Flat else { if (SelectedTab == page) { var tabPage = GetTabPageAtPoint(this.PointToClient(Cursor.Position)); if (tabPage == page) { using (var br = StiBrushes.GetControlLightBrush(rect, 90)) { g.FillPath(br, path); } } else { using (var br = StiBrushes.GetControlBrush(rect, 90)) { g.FillPath(br, path); } } } else { var tabPage = GetTabPageAtPoint(this.PointToClient(Cursor.Position)); if (tabPage == page) { using (var br = new SolidBrush(StiColorUtils.Light(StiColors.Content, 15))) { g.FillPath(br, path); } } else { g.FillPath(StiBrushes.Content, path); } } } #endregion #endregion } Color textColor = ForeColor; if (page != this.SelectedTab) { textColor = SystemColors.ControlDark; } #region Paint Image SizeF imageSize = SizeF.Empty; if (ImageList != null || page.Image != null) { int pageIndex = this.Controls.IndexOf(page); if (ImageList != null || page.Image != null) { if (page.Image != null) { imageSize = page.Image.Size; } else { imageSize = ImageList.ImageSize; } Rectangle imageRect = new Rectangle(rect.X + 2, (int)(rect.Y + (rect.Height - imageSize.Height) / 2), (int)imageSize.Width, (int)imageSize.Height); if (imageSize.Width != 0) { if (imageList != null && ImageList.Images.Count > pageIndex) { ImageList.Draw(g, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, pageIndex); } else if (page.Image != null) { g.DrawImage(page.Image, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height); } } } } #endregion #region Paint text var textRect = new Rectangle(rect.X + (int)imageSize.Width, rect.Y, rect.Width - (int)imageSize.Width, rect.Height); using (var brush = new SolidBrush(textColor)) { g.DrawString(page.Text, Font, brush, textRect, sfTabs); } #endregion #region Draw header lines #region Office2013 Style if (ControlStyle == StiControlStyle.Office2013Blue) { using (var pen = new Pen(StiStyleOffice2013Blue.ColorLineGray)) { if (SelectedTab == page) { if (!PositionAtBottom) { g.DrawLine(pen, new Point(pts[0].X - 1, pts[0].Y - 1), new Point(pts[1].X - 1, pts[1].Y)); g.DrawLine(pen, new Point(pts[0].X - 1, pts[0].Y - 1), new Point(pts[3].X + 1, pts[3].Y - 1)); g.DrawLine(pen, new Point(pts[2].X + 1, pts[2].Y), new Point(pts[3].X + 1, pts[3].Y)); } else { g.DrawLine(pen, pts[1], pts[2]); g.DrawLine(pen, pts[2], pts[3]); } } else { if (PositionAtBottom) { g.DrawLine(pen, pts[0], pts[1]); g.DrawLine(pen, pts[1], pts[2]); g.DrawLine(pen, pts[2], pts[3]); } else { g.DrawLine(pen, pts[0], pts[1]); g.DrawLine(pen, pts[0], pts[3]); g.DrawLine(pen, pts[2], pts[3]); } } } } #endregion #region Flat Style else { if (SelectedTab == page) { g.DrawLine(SystemPens.ControlLightLight, pts[0], pts[1]); if (!PositionAtBottom) { using (var brush = new LinearGradientBrush( new Rectangle(pts[3].X, pts[3].Y, pts[2].X - pts[3].X, pts[2].Y - pts[3].Y - 5), SystemColors.Control, SystemColors.ControlDark, 0f)) using (var pen = new Pen(brush)) g.DrawLine(pen, pts[2], pts[3]); g.DrawLine(SystemPens.ControlLightLight, pts[0], pts[3]); } else { g.DrawLine(SystemPens.ControlDark, pts[1], pts[2]); g.DrawLine(SystemPens.ControlDark, pts[2], pts[3]); } } else { using (var pen = new Pen(StiColorUtils.Dark(SystemColors.Control, 40))) { if (PositionAtBottom) { g.DrawLine(pen, pts[0], pts[1]); g.DrawLine(pen, pts[1], pts[2]); g.DrawLine(pen, pts[2], pts[3]); } else { g.DrawLine(pen, pts[0], pts[1]); g.DrawLine(pen, pts[0], pts[3]); g.DrawLine(pen, pts[2], pts[3]); } } } } #endregion #endregion } } }