private void Form1_Paint(object sender, PaintEventArgs e) { return; using (LinearGradientBrush lb1 = new LinearGradientBrush( new Point(0, 0), new Point(this.ClientRectangle.Width, this.ClientRectangle.Height), Color.LightSteelBlue, Color.CornflowerBlue)) { using (LinearGradientBrush lb2 = new LinearGradientBrush( new Point(0, 0), new Point(this.ClientRectangle.Width, this.ClientRectangle.Height), Color.LightSteelBlue, Color.CornflowerBlue )) { ControlPaint.DrawCaptionButton(e.Graphics, this.ClientRectangle, CaptionButton.Close, ButtonState.Normal); } } }
private void PaintElement(Graphics g, VisualStyleElement element, Rectangle rect, int state) { if (VisualStyleRenderer.IsSupported) { VisualStyleRenderer renderer = new VisualStyleRenderer(element.ClassName, element.Part, state); renderer.DrawBackground(g, rect); } else { ButtonState buttonState = ButtonState.Normal; if (state == State.Disabled) { buttonState = ButtonState.Inactive; } else if (state == State.Pressed) { buttonState = ButtonState.Pushed; } if (element == _elementClose) { ControlPaint.DrawCaptionButton(g, rect, CaptionButton.Close, buttonState); } else { ControlPaint.DrawButton(g, rect, buttonState); } } }
private void MaximizeWindowButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { intptrWindowTheme = openThemeData(MaximizeWindowButton.Handle, "Window"); IsButtonActive(ref MaximizeButtonState); if (FindForm().WindowState == FormWindowState.Maximized) { if (isAppThemed()) { RECT tmp = new RECT(new Rectangle(0, 0, MaximizeWindowButton.Width, MaximizeWindowButton.Height)); drawThemeBackground(intptrWindowTheme, e.Graphics.GetHdc(), (int)UxThemeWindowParts.WP_RESTOREBUTTON, (int)MaximizeButtonState, ref tmp, IntPtr.Zero); e.Graphics.ReleaseHdc(); CloseThemeData(intptrWindowTheme); } else { ControlPaint.DrawCaptionButton(e.Graphics, MaximizeWindowButton.DisplayRectangle, CaptionButton.Restore, ConvertThemeToClassic(MaximizeButtonState)); } } else { if (isAppThemed()) { RECT tmp = new RECT(new Rectangle(0, 0, MaximizeWindowButton.Width, MaximizeWindowButton.Height)); drawThemeBackground(intptrWindowTheme, e.Graphics.GetHdc(), (int)UxThemeWindowParts.WP_MAXBUTTON, Convert.ToInt32((!IsFormActive & MaximizeButtonState == UxThemeSysButtonStates.SBS_NORMAL ? UxThemeSysButtonStates.SBS_INACTIVE : MaximizeButtonState)), ref tmp, IntPtr.Zero); e.Graphics.ReleaseHdc(); CloseThemeData(intptrWindowTheme); } else { ControlPaint.DrawCaptionButton(e.Graphics, MaximizeWindowButton.DisplayRectangle, CaptionButton.Maximize, ConvertThemeToClassic(MaximizeButtonState)); } } }
/// <summary> /// Draw a Windows 95 style close button. /// </summary> protected Bitmap DrawLegacyCloseButton(CloseButtonState state) { var output = new Bitmap(closeButton.Width, closeButton.Height, PixelFormat.Format32bppArgb); try { using (var fx = Graphics.FromImage(output)) { var rClose = new Rectangle(0, 0, closeButton.Width, closeButton.Height); ButtonState bState; if (state == CloseButtonState.Pushed) { bState = ButtonState.Pushed; } else // the Windows 95 theme doesn't have a "hot" button { bState = ButtonState.Normal; } ControlPaint.DrawCaptionButton(fx, rClose, CaptionButton.Close, bState); fx.DrawImage(output, rClose); } } catch { output.Dispose(); throw; } return(output); }
//<snippet1> // Handle the Button1 object's Paint Event to create a CaptionButton. private void Button1_Paint(object sender, PaintEventArgs e) { // Draw a CaptionButton control using the ClientRectangle // property of Button1. Make the button a Help button // with a normal state. ControlPaint.DrawCaptionButton(e.Graphics, Button1.ClientRectangle, CaptionButton.Help, ButtonState.Normal); }
private void DrawForm(Graphics g, Point ptOffset) { // Calculate the Title Bar rectangle int iBarHeight = (int)g.MeasureString(_formulario.Text, _formulario.Font).Height; Rectangle rTitleBar = new Rectangle(ptOffset.X, ptOffset.Y, _formulario.Width, iBarHeight + 2); // Draw the rest of the Form under the Title Bar ptOffset.Offset(0, rTitleBar.Height); g.FillRectangle(new SolidBrush(_formulario.BackColor), ptOffset.X, ptOffset.Y, _formulario.Width, _formulario.Height); // Draw the rest of the controls DrawControl(_formulario, ptOffset, g); // Draw the Form's Title Bar Bitmap bmp = Bitmap.FromHicon(_formulario.Icon.Handle); g.FillRectangle(new SolidBrush(SystemColors.ActiveCaption), rTitleBar); g.DrawImage(bmp, rTitleBar.X, rTitleBar.Y, rTitleBar.Height, rTitleBar.Height); g.DrawString(_formulario.Text, _formulario.Font, new SolidBrush(SystemColors.ActiveCaptionText), rTitleBar.X + rTitleBar.Height, // adding the width of the icon rTitleBar.Y + (rTitleBar.Height / 2) - (g.MeasureString(_formulario.Text, _formulario.Font).Height) / 2); // Draw the Title Bar buttons Size s = new Size(16, 14); // size determined from graphics program ControlPaint.DrawCaptionButton(g, ptOffset.X + _formulario.Width - s.Width, ptOffset.Y + (rTitleBar.Height / 2) - (s.Height / 2) - rTitleBar.Height, s.Width, s.Height, CaptionButton.Close, ButtonState.Normal); ControlPaint.DrawCaptionButton(g, ptOffset.X + _formulario.Width - (s.Width * 2) - 1, ptOffset.Y + (rTitleBar.Height / 2) - (s.Height / 2) - rTitleBar.Height, s.Width, s.Height, (_formulario.WindowState == FormWindowState.Maximized ? CaptionButton.Restore : CaptionButton.Maximize), ButtonState.Normal); ControlPaint.DrawCaptionButton(g, ptOffset.X + _formulario.Width - (s.Width * 3 - 1), ptOffset.Y + (rTitleBar.Height / 2) - (s.Height / 2) - rTitleBar.Height, s.Width, s.Height, CaptionButton.Minimize, ButtonState.Normal); // Draw a rectangle around the entire Form g.DrawRectangle(Pens.Black, ptOffset.X, ptOffset.Y - rTitleBar.Height, _formulario.Width, _formulario.Height + rTitleBar.Height); }
private void frmDiscordNitroSniper_Paint(object sender, PaintEventArgs e) { using (Brush b = new SolidBrush(this.borderColor)) { e.Graphics.FillRectangle(b, this.headerRect); } using (Brush b2 = new SolidBrush(Color.White)) { e.Graphics.DrawString(this.Text, this.Font, b2, this.titleRect); } ControlPaint.DrawCaptionButton(e.Graphics, this.miniBoxRect, CaptionButton.Minimize, this.miniState); ControlPaint.DrawCaptionButton(e.Graphics, this.closeBoxRect, CaptionButton.Close, this.closeState); ControlPaint.DrawBorder(e.Graphics, this.clientRect, this.borderColor, this.borderWidth, ButtonBorderStyle.Solid, this.borderColor, this.borderWidth, ButtonBorderStyle.Solid, this.borderColor, this.borderWidth, ButtonBorderStyle.Solid, this.borderColor, this.borderWidth, ButtonBorderStyle.Solid); }
protected void drawLegacyCloseButton(Graphics fx) { ButtonState pushed; if (this.closePressed) { pushed = ButtonState.Pushed; } else { pushed = ButtonState.Normal; } ControlPaint.DrawCaptionButton(fx, this.rClose, CaptionButton.Close, pushed); }
/// <summary> /// Draw a Windows 95 style close button. /// </summary> protected void drawLegacyCloseButton(Graphics fx) { ButtonState bState; if (closePressed) { bState = ButtonState.Pushed; } else // the Windows 95 theme doesn't have a "hot" button { bState = ButtonState.Normal; } ControlPaint.DrawCaptionButton(fx, rClose, CaptionButton.Close, bState); }
private void DrawTabCloseButton() { Graphics g = this.CreateGraphics(); Rectangle rect = Rectangle.Empty; Point pt = this.PointToClient(Cursor.Position); for (int i = 0; i < this.TabPages.Count; i++) { rect = this.GetTabCloseButtonRect(i); // 閉じるボタン描画 ControlPaint.DrawCaptionButton(g, rect, CaptionButton.Close, ButtonState.Flat); } g = null; }
protected override void OnPaint(PaintEventArgs pevent) { base.OnPaint(pevent); Rectangle rc = new Rectangle(pevent.ClipRectangle.X, pevent.ClipRectangle.Y - 1, pevent.ClipRectangle.Width, pevent.ClipRectangle.Height + 1); if (this.Name == "btnDropDown") { ControlPaint.DrawComboButton(pevent.Graphics, rc, ButtonState.Flat); } else if (this.Name == "btnClear") { ControlPaint.DrawCaptionButton(pevent.Graphics, rc, CaptionButton.Close, ButtonState.Flat); } ControlPaint.DrawBorder(pevent.Graphics, rc, Color.White, ButtonBorderStyle.Solid); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); using (LinearGradientBrush linGrBrush = new LinearGradientBrush( new Point(0, 0), new Point(Width, 0), Color.FromArgb(255, 128, 0, 0), // Opaque red Color.FromArgb(255, 0, 0, 0))) { e.Graphics.FillRectangle(linGrBrush, 0, 0, Width, Height); }; ControlPaint.DrawBorder3D(e.Graphics, 0, 0, Width, Height, Border3DStyle.SunkenInner); ControlPaint.DrawCaptionButton(e.Graphics, _closeRect, CaptionButton.Close, ButtonState.Flat); e.Graphics.DrawString(Title, TitleFont, TitleColor, 4, (Height / 2) - (TitleFont.Height / 2)); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Draw the custom title bar ornamentation. if (this.Focused) { ControlPaint.DrawCaptionButton(e.Graphics, rcMinimizeButton, CaptionButton.Minimize, ButtonState.Normal); ControlPaint.DrawCaptionButton(e.Graphics, rcCloseButton, CaptionButton.Close, ButtonState.Normal); } else { ControlPaint.DrawCaptionButton(e.Graphics, rcMinimizeButton, CaptionButton.Minimize, ButtonState.Inactive); ControlPaint.DrawCaptionButton(e.Graphics, rcCloseButton, CaptionButton.Close, ButtonState.Inactive); } }
private void CloseWindowButton_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { IsButtonActive(ref CloseButtonState); if (isAppThemed()) { intptrWindowTheme = openThemeData(CloseWindowButton.Handle, "Window"); RECT tmp = new RECT(new Rectangle(0, 0, CloseWindowButton.Width, CloseWindowButton.Height)); drawThemeBackground(intptrWindowTheme, e.Graphics.GetHdc(), (int)UxThemeWindowParts.WP_CLOSEBUTTON, (int)CloseButtonState, ref tmp, IntPtr.Zero); e.Graphics.ReleaseHdc(); CloseThemeData(intptrWindowTheme); } else { ControlPaint.DrawCaptionButton(e.Graphics, CloseWindowButton.DisplayRectangle, CaptionButton.Close, ConvertThemeToClassic(CloseButtonState)); } }
protected override void OnPaint(PaintEventArgs e) { if (isActive) { e.Graphics.FillRectangle(SystemBrushes.ActiveCaption, ClientRectangle); } else { e.Graphics.FillRectangle(SystemBrushes.InactiveCaption, ClientRectangle); } if (VisualStyleRenderer.IsSupported) { VisualStyleRenderer vr = null; if (state == CloseButtonState.Pressed) { vr = new VisualStyleRenderer(VisualStyleElement.Window.SmallCloseButton.Pressed); } else if (state == CloseButtonState.Hover) { vr = new VisualStyleRenderer(VisualStyleElement.Window.SmallCloseButton.Hot); } else { vr = new VisualStyleRenderer(VisualStyleElement.Window.SmallCloseButton.Normal); } vr.DrawBackground(e.Graphics, ClientRectangle); } else { if (state == CloseButtonState.Pressed) { ControlPaint.DrawCaptionButton(e.Graphics, ClientRectangle, CaptionButton.Close, ButtonState.Pushed); } else { ControlPaint.DrawCaptionButton(e.Graphics, ClientRectangle, CaptionButton.Close, ButtonState.Normal); } } }
private void drawButton(Graphics g, Rectangle r, ButtonState bstate) { Rectangle rc = Rectangle.Empty; try { if (bstate == ButtonState.Normal) { rc = new Rectangle(r.X, r.Y, r.Width, r.Height); } else { rc = new Rectangle(r.X, r.Y, r.Width - 1, r.Height - 1); } switch (_type) { case ChooserButtonType.DropDown: ControlPaint.DrawComboButton(g, rc, bstate); break; case ChooserButtonType.Reset: ControlPaint.DrawCaptionButton(g, rc, CaptionButton.Close, bstate); break; case ChooserButtonType.Dialog: ControlPaint.DrawCaptionButton(g, rc, CaptionButton.Maximize, bstate); break; } //чтобы по¤вилась сера¤ рамочка вокруг кнопок //ControlPaint.DrawBorder(g, rc, Color.White, ButtonBorderStyle.Solid); } catch (Exception exp) { Console.WriteLine("---\n" + rc.Size.ToString() + "\n" + Common.ExMessage(exp) + "\n---"); } }
/// <summary> /// Draw a Windows 95 style close button. /// </summary> protected Bitmap DrawLegacyCloseButton(CloseButtonState state) { Bitmap output = new Bitmap(closeButton.Width, closeButton.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics fx = Graphics.FromImage(output); Rectangle rClose = new Rectangle(0, 0, closeButton.Width, closeButton.Height); ButtonState bState; if (state == CloseButtonState.Pushed) { bState = ButtonState.Pushed; } else // the Windows 95 theme doesn't have a "hot" button { bState = ButtonState.Normal; } ControlPaint.DrawCaptionButton(fx, rClose, CaptionButton.Close, bState); fx.DrawImage(output, rClose); fx.Dispose(); return(output); }
private bool paintCaption_(Graphics g) { int X = 0; int R = this.ClientSize.Width; bool ret = false; // paint caption bar // - icon // - text // - mainmenustrip // - min/max/close var rc = new Rectangle(X, 0, R, CaptionHeight); if (g != null) { var sb = new SolidBrush(CaptionColor); g.FillRectangle(sb, rc); } if (this.ShowIcon) { if (g != null) { var rcIcon = new Rectangle(X, 0, CaptionHeight, CaptionHeight); g.DrawIcon(this.Icon, rcIcon); X += CaptionHeight; } } if (!string.IsNullOrEmpty(Text)) { var captionFont = SystemFonts.CaptionFont; var captionBrush = SystemBrushes.ActiveCaptionText; if (g != null) { var m = g.MeasureString(Text, captionFont); int W = CaptionTextWidth; if (W == 0) { W = (int)m.Width + 2;// runf up plus extra pixel space } actualCaptionTextWidth = W; var topOffset = (CaptionHeight - m.Height) / 2; var captionRect = new RectangleF(X, topOffset < 0 ? 0 : topOffset, W, CaptionHeight); g.DrawString(Text, captionFont, captionBrush, captionRect); X += W; } else { X += actualCaptionTextWidth;// use width from last time we drew it (are we one step behind?) } } // // seperator after text X += CaptionHeight; // // control button far right if (this.ControlBox) { R -= CaptionHeight; if (g != null) { #if SYSTEM_CLOSE_BUTTON var r = new Rectangle(R, 0, CaptionHeight, CaptionHeight); ControlPaint.DrawCaptionButton(g, r, CaptionButton.Close, ButtonState.Normal | ButtonState.Flat); #else // just draw a simple cross Pen p = Pens.Black; int o = CaptionHeight / 3; // offset to cross ends inside the box int w = CaptionHeight - o - o; // width/height of the cross g.DrawLine(p, R + o, o, R + o + w, o + w); g.DrawLine(p, R + o, o + w, R + o + w, o); #endif } } // // seperator before control button R -= CaptionHeight; // // whatever isleft is for mmenu strip // from X to R... if (this.MainMenuStrip != null) { // no room for the menu! if (R < X) { R = X; } // // if mainmenu is not in calculated place then move it // - note width check is ">" rather than "!=" becuase we may set toolstrip size and it // may set somethign lower depending what it has if (this.MainMenuStrip.Left != X || this.MainMenuStrip.Right > R) { // never dock the main menu from outer form...we "own" its position if (this.MainMenuStrip.Dock != DockStyle.None) { this.MainMenuStrip.Dock = DockStyle.None; } this.MainMenuStrip.SetBounds(X, 0, R - X, CaptionHeight); ret = true; } if (g != null) { // menu same back color as us if (MainMenuStrip.BackColor != this.CaptionColor) { MainMenuStrip.BackColor = this.CaptionColor; } MainMenuStrip.Refresh(); } } return(ret); }
protected void drawLegacyCloseButton(Graphics fx) { ButtonState state = !this.closePressed ? ButtonState.Normal : ButtonState.Pushed; ControlPaint.DrawCaptionButton(fx, this.rClose, CaptionButton.Close, state); }