protected override void OnRenderToolStripBackground( ToolStripRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; // 如果设置了背景透明,则不再绘制背景 if (toolStrip.BackColor == Color.Transparent) { return; } Graphics g = e.Graphics; Rectangle bounds = e.AffectedBounds; if (toolStrip is ToolStripDropDown) { ImageDrawRect.DrawRect(g, _TSDbgImg, bounds, Rectangle.FromLTRB(30, 3, 3, 3), 1, 1); } else if (toolStrip is MenuStrip) { ImageDrawRect.DrawRect(g, _TopBgImg, bounds, Rectangle.FromLTRB(1, 1, 1, 2), 1, 1); } else { base.OnRenderToolStripBackground(e); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Rectangle rc = this.ClientRectangle; Graphics g = e.Graphics; ImageDrawRect.DrawRect(g, _BackImg, rc, Rectangle.FromLTRB(10, 50, 10, 30), 1, 1); }
protected override void OnRenderSeparator( ToolStripSeparatorRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; Rectangle rect = e.Item.ContentRectangle; Graphics g = e.Graphics; rect.X += 25; rect.Width -= 26; if (toolStrip is ToolStripDropDown) { ImageDrawRect.DrawRect(g, _Sepebg, rect, Rectangle.FromLTRB(2, 0, 30, 0), 1, 1); } }
protected override void OnRenderMenuItemBackground( ToolStripItemRenderEventArgs e) { ToolStrip toolStrip = e.ToolStrip; ToolStripItem item = e.Item; if (!item.Enabled) { return; } Graphics g = e.Graphics; Rectangle rect = new Rectangle(Point.Empty, e.Item.Size); if (toolStrip is MenuStrip) { LinearGradientMode mode = toolStrip.Orientation == Orientation.Horizontal ? LinearGradientMode.Vertical : LinearGradientMode.Horizontal; if (item.Selected) { ImageDrawRect.DrawRect(g, _MbgImg, rect, Rectangle.FromLTRB(1, 1, 1, 1), 1, 1); } else if (item.Pressed) { ImageDrawRect.DrawRect(g, _MbgImg, rect, Rectangle.FromLTRB(1, 1, 1, 1), 1, 1); } else { base.OnRenderMenuItemBackground(e); } } else if (toolStrip is ToolStripDropDown) { rect.X += 29; rect.Width -= 30; if (item.Selected) { ImageDrawRect.DrawRect(g, _MbgImg, rect, Rectangle.FromLTRB(3, 3, 3, 3), 1, 1); } else { base.OnRenderMenuItemBackground(e); } } }
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { bool chk = false; chk = (e.Item as ToolStripButton).Checked; if (e.Item.Pressed && e.Item.Selected) { i = 2; } else if (e.Item.Selected) { i = 1; } else if (chk) { i = 2; } else { i = 0; } ImageDrawRect.DrawRect(e.Graphics, backImg, new Rectangle(Point.Empty, e.Item.Size), Rectangle.FromLTRB(5, 15, 5, 5), i, 2); }
/// <summary> /// 重绘控件 /// </summary> /// <param name="e"></param> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (BackImg == null) { base.OnPaint(e); return; } int i = (int)state; if (this.Focused && state != State.MouseDown && _IsTabFocus == true) { i = 5; } if (!this.Enabled) { i = 4; } Rectangle rc = this.ClientRectangle; Graphics g = e.Graphics; base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle)); try { if (BackImg != null) { if (_BacklightLTRB != Rectangle.Empty) { ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), i, 5); } else { ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), i, 5); } } } catch { } Image img = null; Size txts, imgs; txts = Size.Empty; imgs = Size.Empty; if (this.Image != null) { img = this.Image; } else if (this.ImageList != null && this.ImageIndex != -1) { img = this.ImageList.Images[this.ImageIndex]; } if (img != null) { imgs.Width = img.Width; imgs.Height = img.Height; } StringFormat format1; using (format1 = new StringFormat()) { format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1); txts = Size.Ceiling(ef1); } rc.Inflate(-4, -4); if (imgs.Width * imgs.Height != 0) { Rectangle imgr = rc; imgr = AlClass.ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign); imgr = AlClass.ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign); if (!this.Enabled) { ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor); } else { g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height); } } Rectangle txtr = rc; txtr = AlClass.ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign); txtr = AlClass.ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign); format1 = new StringFormat(); format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; if (this.RightToLeft == RightToLeft.Yes) { format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } brush = new SolidBrush(this.ForeColor); g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1); brush.Dispose(); }