protected override void OnPaint(PaintEventArgs pe) { var g = pe.Graphics; Share.GraphicSetup(g); //g.Clip = new Region(rectPath); using (var sb = new SolidBrush(btnColor)) { g.FillPath(sb, rectPath); //画背景 //rectPath.Dispose(); } if (Style == ProgressBarStyle.Continuous) //进度条 { using (var tb = new TextureBrush(blockBitmap)) { g.FillPath(tb, loadPath); } } else if (Style == ProgressBarStyle.Marquee) //动画 { g.DrawImage(blockBitmap, pos, 0); } else if (Style == ProgressBarStyle.Blocks) //滚动 { using (var tb = new TextureBrush(blockBitmap)) { // g.Clip = new Region(blocksPath); g.FillPath(tb, blocksPath); } } if (ShowBorder) { using (var pen = new Pen(borderColor)) { g.DrawPath(pen, rectPath); //画边框 // rectPath.Dispose(); } } }
protected override void OnPaint(PaintEventArgs e) { //base.OnPaint(e); if (showBorder) { Share.GraphicSetup(e.Graphics); e.Graphics.SetClip(rectPath); var pen = new Pen(Share.BorderColor); var sb = new SolidBrush(Share.BackColor); e.Graphics.FillPath(sb, rectPath); e.Graphics.DrawPath(pen, rectPath); pen.Dispose(); sb.Dispose(); } var sz = TextRenderer.MeasureText(Text, Font); //Rectangle textRect = new Rectangle(base.Padding.Left, base.Padding.Top, // base.Padding.Left + base.Padding.Right + sz.Width + base.Margin.Left, // base.Padding.Left + sz.Height); //if (base.Text != "") DrawHelper.DrawCaptionText(e.Graphics, ClientRectangle, Text, Font, true, Color.White, 3, ForeColor); }
private Color GetColor() { var b = new Bitmap(colorImageRect.Width, colorImageRect.Height); var g = Graphics.FromImage(b); Share.GraphicSetup(g); g.DrawImage(ColorImage, new Rectangle(0, 0, colorImageRect.Width, colorImageRect.Height)); // g.CopyFromScreen(new Point(MousePosition.X, MousePosition.Y), new Point(0, 0), b.Size); // else // g.CopyFromScreen(new Point(r.X, r.Y), new Point(0, 0), b.Size); // if (r.X - 5 > b.Width) r.X = b.Width; // if (r.Y - 5 > b.Height) r.Y = b.Height; var x = r.X + 5; var y = r.Y - (Height - colorImageRect.Height) + 5; if (x >= b.Width) { x = b.Width - 1; } if (y >= b.Height) { y = b.Height - 1; } if (x <= 0) { x = 1; } if (y <= 0) { y = 1; } // y = b.Height - y; var color = b.GetPixel(x, y); g.Dispose(); b.Dispose(); return(color); }
protected override void OnPaint(PaintEventArgs pevent) { var g = pevent.Graphics; Share.GraphicSetup(g); var sb = new SolidBrush(Share.FocusBackColor); var p = new Pen(Share.FocusBackColor); if (Checked) { g.FillEllipse(sb, radioRect); g.DrawEllipse(p, radioRect); sb.Color = Share.BackColor; g.FillEllipse(sb, innerRadioRect); } else { sb.Color = bgColor; g.FillEllipse(sb, radioRect); p.Color = borderColor; g.DrawEllipse(p, radioRect); } sb.Dispose(); p.Dispose(); //TextRenderer.DrawText(g, base.Text, base.Font, TextRect, base.ForeColor, TextFormatFlags.VerticalCenter | // TextFormatFlags.Left | // TextFormatFlags.SingleLine); if (Text != "") { var TextRect = new RectangleF(radioRect.Width + 3f, ((float)Height - g.MeasureString(Text, Font).Height) / 2f + .5f, Width - radioRect.Width - 3f, Height); DrawHelper.DrawCaptionText(g, TextRect, Text, Font, true, Color.White, 3, ForeColor); } }
protected override void OnPaint(PaintEventArgs e) { var g = e.Graphics; Share.GraphicSetup(g); SliderBar = new Rectangle(x, (Height - sliderbar) / 2, sliderbar, sliderbar); //画背景条 var sb = new SolidBrush(bgColor); var p = new Pen(borderColor); g.FillPath(sb, rectPath); g.DrawPath(p, rectPath); //画进度 sb.Color = Share.FocusBackColor; p.Color = Share.FocusBackColor; g.FillPath(sb, ThumbPath); g.DrawPath(p, ThumbPath); //画拉杆 sb.Color = bgColor; p.Color = borderColor; g.FillEllipse(sb, SliderBar); g.DrawEllipse(p, SliderBar); sb.Dispose(); p.Dispose(); rectPath.Dispose(); // using (SolidBrush sb = new SolidBrush(this.BarColor)) // { // g.FillPath(new SolidBrush(Color.FromArgb(100, Color.Gray)), rectPath); // g.DrawPath(new Pen(Color.FromArgb(100, Color.Gray)), rectPath); //g.FillRectangle(new SolidBrush(Color.FromArgb(100, Color.Gray)), Thumb); //g.DrawRectangle(new Pen(c), Thumb); // g.FillEllipse(sb, SliderBar); //g.DrawEllipse(new Pen(c), SliderBar); }
//子项背景 protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { var toolStrip = e.ToolStrip; var item = e.Item; if (!item.Enabled) { return; } var g = e.Graphics; Share.GraphicSetup(g); //渲染顶级项 if (toolStrip is MenuStrip) { var gp = DrawHelper.CreateRoundPath2(item.ContentRectangle, Share.DefaultRadius); // int alpha = (int)Alpha.Normal; var sb = new SolidBrush(Share.BackColor); var pen = new Pen(Share.BorderColor); if (item.Selected) { // alpha = (int)Alpha.Normal; sb.Color = pen.Color = Share.FocusBackColor; g.FillPath(sb, gp); g.DrawPath(pen, gp); } else if (item.Pressed) { // alpha = (int)Alpha.PressOrDown; sb.Color = pen.Color = Share.FocusBackColor; g.FillPath(sb, gp); g.DrawPath(pen, gp); } else { sb.Color = Share.FocusBackColor; pen.Color = Share.BorderColor; base.OnRenderMenuItemBackground(e); } sb.Dispose(); pen.Dispose(); gp.Dispose(); } //渲染下拉项 右键菜单 else if (toolStrip is ToolStripDropDown) { if (item.Selected) { item.ForeColor = Color.White; var rect = new Rectangle( item.ContentRectangle.X, item.ContentRectangle.Y - 2, item.ContentRectangle.Width + 1, item.ContentRectangle.Height + 3); //Color cl = Color.FromArgb(150, 150, 150); var sb = new SolidBrush(Share.FocusBackColor); g.FillRectangle(sb, rect); sb.Dispose(); } else { item.ForeColor = Color.FromArgb(80, 80, 80); } } else { base.OnRenderMenuItemBackground(e); } }
/// <summary> /// 主要针对toolbar的绘制 /// </summary> /// <param name="e"></param> protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e) { var toolStrip = e.ToolStrip; var item = e.Item as ToolStripButton; var g = e.Graphics; Share.GraphicSetup(g); if (item != null) { var bounds = new Rectangle(Point.Empty, item.Size); var rectPath = DrawHelper.CreateRoundPath2(bounds, Share.DefaultRadius); //int alpha = (int)Alpha.Normal; if (item.BackgroundImage != null) { //这里绘制背景 } var sb = new SolidBrush(Share.BackColor); var p = new Pen(Share.BorderColor); //默认没有选中 if (item.CheckState == CheckState.Unchecked) { if (item.Selected) { item.ForeColor = Color.White; if (item.Pressed) { sb.Color = p.Color = Share.BorderColor; //alpha = (int)Alpha.PressOrDown; } else { sb.Color = p.Color = Share.BorderColor; // alpha = (int)Alpha.MoveOrUp; } } else { item.ForeColor = Color.Black; sb.Color = p.Color = Share.BackColor; //alpha = (int)Alpha.None; if (toolStrip is ToolStripOverflow) { } } } else { if (item.Selected) { sb.Color = p.Color = Share.BorderColor; //alpha = (int)Alpha.MoveOrUp; // DrawHelper.RendererBackground(g, bounds, ToolHoverBgImg, true); } if (item.Pressed) { sb.Color = p.Color = Share.FocusBackColor; //alpha = (int)Alpha.PressOrDown; // DrawHelper.RendererBackground(g, bounds, ToolDownBgImg, true); } } //SolidBrush sb = new SolidBrush(Color.FromArgb(alpha, 0, 0, 0)); //Pen pen = new Pen(Color.FromArgb(alpha, 0, 0, 0)); g.FillPath(sb, rectPath); g.DrawPath(p, rectPath); sb.Dispose(); p.Dispose(); rectPath.Dispose(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!Visible) { return; } var g = e.Graphics; Share.GraphicSetup(g); using (var sb = new SolidBrush(thumbColor)) { using (var pen = new Pen(thumbColor)) { g.FillPath(sb, rectPath); g.DrawPath(pen, rectPath); rectPath.Dispose(); } } // if (DesignMode) // { ScrollThumb.Width = 10; ScrollThumb.X = Width - 10; ScrollThumb.Height = (int)(((double)Height / virtualHeight) * (Height)); ScrollThumb.Y = (int)(((double)value / (virtualHeight - Height)) * (Height - ScrollThumb.Height)); if (ScrollThumb.Height < 20) { ScrollThumb.Height = 20; } g.TranslateTransform(0, -Value); var rectItem = new Rectangle(1, 1, Width - 2, ItemHeight); if (virtualHeight > Height) //如果超出了.就是存在滚动条 { rectItem.Width -= 10; } Color fontColor = Color.Black; var font = Share.DefaultFont; var sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Near; sf.Trimming = StringTrimming.EllipsisCharacter; //超出指定矩形区域部分用"..."替代 if (list != null && list.Count > 0) { for (var i = 0; i < list.Count; i++) { fontColor = (BgColor == Color.Transparent) ? Color.Orange : Color.White; if (list[i].Equals(mouseoverItem)) //鼠标划过 { list[i].Alpha = (int)Alpha.Normal; } else if (list[i].Equals(SelectItem)) //选中 { list[i].Alpha = (int)Alpha.MoveOrUp; } else { list[i].Alpha = (int)Alpha.None; fontColor = Color.Black; } //var s = g.MeasureString(list[i].Text, font); //var textRect = new RectangleF(list[i].Bounds.Left, i * ItemHeight + (ItemHeight - s.Height) / 2.0f, // list[i].Bounds.Width, s.Height); list[i].Bounds = new Rectangle(rectItem.Location, rectItem.Size); using (var sb = new SolidBrush(GetColor(list[i].Alpha))) { //画背景 g.FillRectangle(sb, rectItem); } using (var sb = new SolidBrush(fontColor)) { //画文字 // TextRenderer.DrawText(g, list[i].Text, font, list[i].Bounds, fontColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter | TextFormatFlags.Left | TextFormatFlags.EndEllipsis); g.DrawString(list[i].Text, font, sb, list[i].Bounds, sf); } rectItem.Y = rectItem.Bottom + 1; } } g.ResetTransform(); VirtualHeight = rectItem.Bottom - rectItem.Size.Height; //画滚动条 if (virtualHeight > Height) { var sb = new SolidBrush(thumbColor); var gp = DrawHelper.CreateRoundPath2(ScrollThumb, 8); var pen = new Pen(thumbColor); g.FillPath(sb, gp); g.DrawPath(pen, gp); sb.Dispose(); pen.Dispose(); gp.Dispose(); } // } }
protected override void OnPaint(PaintEventArgs e) { Rectangle imageRect; Rectangle textRect; CalculateRect(out imageRect, out textRect); //按钮背景 if (BgImage != null) { DrawBackGroundImage(e.Graphics); } if (btnImage != null) { //e.Graphics.Clip = new Region(rectPath); drawBtn(e.Graphics); } else { SetColor(); using (var sb = new SolidBrush(backColor)) { using (var p = new Pen(borderColor)) { Share.GraphicSetup(e.Graphics); e.Graphics.FillPath(sb, rectPath); //画背景 if (showBorder) { e.Graphics.DrawPath(p, rectPath); //画边框 } rectPath.Dispose(); } } } //按钮图标 if (Image != null) { imageRect.X += imageoffset.X; imageRect.Y += imageoffset.Y; e.Graphics.DrawImage(Image, imageRect); } //按钮文字 if (Text != "") { TextRenderer.DrawText(e.Graphics, Text, Font, textRect, fontColor, _textAlign); } // DrawHelper.DrawCaptionText(g, textRect, base.Text, base.Font, true, Color.White, 1, base.ForeColor); //} //g1.DrawImage(drawimg, 0, 0); // drawimg.Dispose(); #region old //using (SolidBrush sb = new SolidBrush(color)) { g.FillPath(sb, gp); }//画背景 //Rectangle clientRectangle = base.ClientRectangle; //Image image = null; //Size empty = Size.Empty; //if (base.Image != null) //{ // if (string.IsNullOrEmpty(this.Text)) // { // image = base.Image; // empty = new Size(image.Width, image.Height); // clientRectangle.Inflate(-4, -4); // if ((empty.Width * empty.Height) != 0) // { // Rectangle withinThis = clientRectangle; // withinThis = ImageDrawRect.HAlignWithin(empty, withinThis, base.ImageAlign); // withinThis = ImageDrawRect.VAlignWithin(empty, withinThis, base.ImageAlign); // if (!base.Enabled) // { // ControlPaint.DrawImageDisabled(g, image, withinThis.Left, withinThis.Top, this.BackColor); // } // else // { // g.DrawImage(image, withinThis.Left + num, withinThis.Top + num, image.Width, image.Height); // } // } // } // else // { // g.InterpolationMode = InterpolationMode.HighQualityBilinear; // g.DrawImage(base.Image, imageRect, -num, -num, base.Image.Width, base.Image.Height, GraphicsUnit.Pixel); // } //} //else if ((base.ImageList != null) && (base.ImageIndex != -1)) //{ // image = base.ImageList.Images[base.ImageIndex]; //} ////画图片 ////if (Image != null) ////{ //// g.InterpolationMode = InterpolationMode.HighQualityBilinear; //// g.DrawImage( //// Image, //// imageRect, //// 0, //// 0, //// Image.Width, //// Image.Height, //// GraphicsUnit.Pixel); ////} ////g.TextRenderingHint = TextRenderingHint.AntiAlias; //if (!base.Enabled) //{ // alpha = Alpha.DisEnable; // base.ForeColor = Color.DarkGray; //} //else // base.ForeColor = Color.Black; //using (Pen pen = new Pen(bdcolor)) //{ // g.DrawPath(pen, gp); // if (this.Focused) // { // pen.DashStyle = DashStyle.Dash; // g.DrawPath(pen, gp1); // gp1.Dispose(); // } //} //if (mouseDown && base.Enabled) { textRect.X++; textRect.Y++; } //// _textAlign.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide; //Size sz = TextRenderer.MeasureText(base.Text, base.Font); //if (Image == null) //{ // textRect.Y = (this.Height - sz.Height) / 2; //} //textRect.X = (Width - sz.Width) / 2; // //TextRenderer.DrawText(g, base.Text, new Font("微软雅黑", base.Font.Size), textRect, base.ForeColor, this._textAlign); //gp.Dispose(); #endregion }
/// <summary> /// 关闭Tab之前触发事件 /// </summary> /// <summary> /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!Visible) { return; } //画选点击选项卡, if (TabCount > 0) { var g = e.Graphics; Share.GraphicSetup(g); // g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; // g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; // alpha = Alpha.Normal; var sb = new SolidBrush(Share.BackColor); var pen = new Pen(Share.BorderColor); // g.FillPath(sb, GetPath(ClientRectangle, 5)); //画整体边框 // g.DrawPath(pen, GetPath(ClientRectangle, 5)); //画整体背景 var tabRect = Rectangle.Empty; var selecttabRect = Rectangle.Empty; // Point cursorPoint = this.PointToClient(MousePosition); TabPage page = null; TabPage selectPage = null; GraphicsPath gp = null; GraphicsPath selectgp = null; for (var i = 0; i < TabCount; i++) { page = TabPages[i]; tabRect = GetTabRect(i); tabRect.X += 2; tabRect.Y += 2; gp = DrawHelper.GetGoogleTabPath(tabRect, 8); if (SelectedIndex != i) { // alpha = Alpha.MoveOrUp; page.ForeColor = Color.CornflowerBlue; // sb = new SolidBrush(color); // pen = new Pen(color); sb.Color = Share.DisabelBackColor; g.FillPath(sb, gp); //画边框 g.DrawPath(pen, gp); //画背景 gp.Dispose(); // sb.Dispose(); //渲染选项卡文字 tabRect.X += 10; //让文字往右偏移10个像素.因为谷歌的tab 是个梯形的 tabRect.Width -= 20; TextRenderer.DrawText(g, page.Text, page.Font, tabRect, page.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter); } else { selectPage = page; selectgp = gp; selecttabRect = tabRect; } if (i == TabCount - 1) { selectPage.ForeColor = Color.Orange; // alpha = Alpha.a200; // sb = new SolidBrush(color); // pen = new Pen(color); sb.Color = Share.BackColor; g.FillPath(sb, selectgp); //画背景 g.DrawPath(pen, selectgp); //画边框 selectgp.Dispose(); // sb.Dispose(); //画叉叉 ,叉叉是在最上层的, 所以要最后画 Bitmap clsBitmap; if (closeState == MouseState.press) { clsBitmap = Properties.Resources.icon_tbclose_press; } else if (closeState == MouseState.move) { clsBitmap = Properties.Resources.icon_tbclose_hover; } else { clsBitmap = Properties.Resources.icon_tbclose_normal; } g.DrawImage(clsBitmap, GetCloseRect(selecttabRect)); clsBitmap.Dispose(); //渲染选项卡文字 selecttabRect.X += 10; //让文字往右偏移10个像素.因为谷歌的tab 是个梯形的 selecttabRect.Width -= 20; TextRenderer.DrawText(g, selectPage.Text, selectPage.Font, selecttabRect, selectPage.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter); var rect = new Rectangle(GetTabRect(0).X + 2, GetTabRect(0).Bottom + 2, TabPages[0].DisplayRectangle.Width + 6, TabPages[0].DisplayRectangle.Height + 6); var path = GetPath(rect, 5); pen.Color = Share.BorderColor; g.DrawPath(pen, path); //画页面边框 path.Dispose(); } } sb.Dispose(); pen.Dispose(); } }