public static Color GetColor(double luminance) { Color col = RibbonControl.HSL2RGB(RibbonControl.Color.GetHue() / 360.0, RibbonControl.Color.GetSaturation() / 2.0, RibbonControl.Color.GetBrightness() * 1.025); double r = (double)col.R * luminance; double g = (double)col.G * luminance; double b = (double)col.B * luminance; if (r > 255.0) { r = 255.0; } if (g > 255.0) { g = 255.0; } if (b > 255.0) { b = 255.0; } return(Color.FromArgb((int)r, (int)g, (int)b)); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; switch (RibbonControl.ColorScheme) { case ColorScheme.Blue: { e.Graphics.Clear(Color.FromArgb(191, 219, 255)); Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); Color[] col = new Color[] { Color.FromArgb(225, 234, 245), Color.FromArgb(209, 223, 240), Color.FromArgb(199, 216, 237), Color.FromArgb(231, 242, 255) }; float[] pos = new float[] { 0.0f, 0.2f, 0.2f, 1.0f }; ColorBlend blend = new ColorBlend(); blend.Colors = col; blend.Positions = pos; LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical); brush.InterpolationColors = blend; RibbonControl.FillRoundRectangle(e.Graphics, brush, rect, 3f); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(141, 178, 227)), rect, 3f); rect.Offset(1, 1); rect.Width -= 2; rect.Height -= 2; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(rect, Color.FromArgb(231, 239, 248), Color.Transparent, LinearGradientMode.ForwardDiagonal)), rect, 3f); } break; case ColorScheme.Gray: { e.Graphics.Clear(Color.FromArgb(83, 83, 83)); Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); Color[] col = new Color[] { Color.FromArgb(210, 214, 221), Color.FromArgb(193, 198, 207), Color.FromArgb(180, 187, 197), Color.FromArgb(231, 240, 241) }; float[] pos = new float[] { 0.0f, 0.2f, 0.2f, 1.0f }; ColorBlend blend = new ColorBlend(); blend.Colors = col; blend.Positions = pos; LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical); brush.InterpolationColors = blend; RibbonControl.FillRoundRectangle(e.Graphics, brush, rect, 3f); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(190, 190, 190)), rect, 3f); rect.Offset(1, 1); rect.Width -= 2; rect.Height -= 2; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(rect, Color.FromArgb(231, 233, 237), Color.Transparent, LinearGradientMode.ForwardDiagonal)), rect, 3f); } break; case ColorScheme.Custom: { e.Graphics.Clear(RibbonControl.Color); Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1); Color[] col = new Color[] { RibbonControl.GetColor(1.025), RibbonControl.GetColor(1.0), RibbonControl.GetColor(0.975), RibbonControl.GetColor(1.075) }; float[] pos = new float[] { 0.0f, 0.2f, 0.2f, 1.0f }; ColorBlend blend = new ColorBlend(); blend.Colors = col; blend.Positions = pos; LinearGradientBrush brush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical); brush.InterpolationColors = blend; RibbonControl.FillRoundRectangle(e.Graphics, brush, rect, 3f); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(RibbonControl.GetColor(0.75)), rect, 3f); rect.Offset(1, 1); rect.Width -= 2; rect.Height -= 2; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(rect, RibbonControl.GetColor(1.05), Color.Transparent, LinearGradientMode.ForwardDiagonal)), rect, 3f); } break; } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; switch (RibbonControl.ColorScheme) { case ColorScheme.Blue: { Rectangle rect1 = new Rectangle(1, 1, this.Width - 2, this.Height - 2); Rectangle rect2 = new Rectangle(0, this.Height - 18, this.Width - 2, 16); Rectangle rect3 = new Rectangle(this.Width - 18, this.Height - 18, 15, 15); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(237, 242, 248)), rect1, 3f); GraphicsPath gp = new GraphicsPath(); gp.AddArc(rect2.X, rect2.Y - 4f, 6f, 6f, 180, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y - 5f, 6f, 6f, 270, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y + rect2.Height - 6f, 6f, 6f, 0, 90); gp.AddArc(rect2.X, rect2.Y + rect2.Height - 6f, 6f, 6f, 90, 90); gp.CloseFigure(); e.Graphics.SetClip(gp, CombineMode.Intersect); gp.Dispose(); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(193, 217, 241)), rect2); e.Graphics.Clip = new Region(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.FromArgb(21, 66, 139)), rect2, sf); if (OnPopup != null) { if (this.hoverplus) { RibbonControl.RenderSelection(e.Graphics, rect3, 2f, this.pressed); } e.Graphics.DrawString("+", this.Font, new SolidBrush(Color.FromArgb(21, 66, 139)), rect3, sf); } rect1.Offset(-1, -1); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(197, 210, 223)), rect1, 3f); } break; case ColorScheme.Gray: { Rectangle rect1 = new Rectangle(1, 1, this.Width - 2, this.Height - 2); Rectangle rect2 = new Rectangle(0, this.Height - 18, this.Width - 2, 16); Rectangle rect3 = new Rectangle(this.Width - 18, this.Height - 18, 15, 15); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(231, 233, 237)), rect1, 3f); GraphicsPath gp = new GraphicsPath(); gp.AddArc(rect2.X, rect2.Y - 4f, 6f, 6f, 180, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y - 5f, 6f, 6f, 270, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y + rect2.Height - 6f, 6f, 6f, 0, 90); gp.AddArc(rect2.X, rect2.Y + rect2.Height - 6f, 6f, 6f, 90, 90); gp.CloseFigure(); e.Graphics.SetClip(gp, CombineMode.Intersect); gp.Dispose(); e.Graphics.FillRectangle(new LinearGradientBrush(rect2, Color.FromArgb(182, 184, 184), Color.FromArgb(157, 159, 159), LinearGradientMode.Vertical), rect2); e.Graphics.Clip = new Region(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.White), rect2, sf); if (OnPopup != null) { if (this.hoverplus) { RibbonControl.RenderSelection(e.Graphics, rect3, 2f, this.pressed); e.Graphics.DrawString("+", this.Font, new SolidBrush(Color.Black), rect3, sf); } else { e.Graphics.DrawString("+", this.Font, new SolidBrush(Color.White), rect3, sf); } } rect1.Offset(-1, -1); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(140, 141, 143)), rect1, 3f); } break; case ColorScheme.Custom: { Rectangle rect1 = new Rectangle(1, 1, this.Width - 2, this.Height - 2); Rectangle rect2 = new Rectangle(0, this.Height - 18, this.Width - 2, 16); Rectangle rect3 = new Rectangle(this.Width - 18, this.Height - 18, 15, 15); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(RibbonControl.GetColor(1.05)), rect1, 3f); GraphicsPath gp = new GraphicsPath(); gp.AddArc(rect2.X, rect2.Y - 4f, 6f, 6f, 180, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y - 5f, 6f, 6f, 270, 90); gp.AddArc(rect2.X + rect2.Width - 6f, rect2.Y + rect2.Height - 6f, 6f, 6f, 0, 90); gp.AddArc(rect2.X, rect2.Y + rect2.Height - 6f, 6f, 6f, 90, 90); gp.CloseFigure(); e.Graphics.SetClip(gp, CombineMode.Intersect); gp.Dispose(); e.Graphics.FillRectangle(new SolidBrush(RibbonControl.GetColor(0.975)), rect2); e.Graphics.Clip = new Region(); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(this.Text, this.Font, new SolidBrush(RibbonControl.TextColor), rect2, sf); if (OnPopup != null) { if (this.hoverplus) { RibbonControl.RenderSelection(e.Graphics, rect3, 2f, this.pressed); } e.Graphics.DrawString("+", this.Font, new SolidBrush(this.ForeColor), rect3, sf); } rect1.Offset(-1, -1); RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(RibbonControl.GetColor(0.85)), rect1, 3f); } break; } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; switch (RibbonControl.ColorScheme) { case ColorScheme.Blue: { e.Graphics.Clear(Color.FromArgb(191, 219, 255)); Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); if (this.Height > 26) { RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 17), 3f); RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 16), 3f); } int ti = 0; foreach (TabPage tab in this.TabPages) { Rectangle tabrect = this.GetTabRect(ti); tabrect.Height += 4; if (this.SelectedIndex > 0 && this.Height > 26 && tab == this.SelectedTab) { RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(tabrect.X - 2, tabrect.Y, tabrect.Width + 4, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(16, Color.Black)), new Rectangle(tabrect.X - 1, tabrect.Y, tabrect.Width + 2, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new LinearGradientBrush(tabrect, Color.FromArgb(235, 243, 254), Color.FromArgb(220, 231, 245), LinearGradientMode.Vertical), tabrect, 3f); RibbonControl.DrawTopRoundRectangle(e.Graphics, new Pen(Color.FromArgb(141, 178, 227)), tabrect, 3f); tabrect.Offset(1, 1); tabrect.Width -= 2; tabrect.Height--; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(tabrect, Color.FromArgb(248, 251, 255), Color.Transparent, LinearGradientMode.ForwardDiagonal)), tabrect, 3f); Region region = new Region(); region.Exclude(new Rectangle(tabrect.X - 4, 0, tabrect.Width + 1, 2)); tab.Region = region; } else if (ti == this.hoverindex) { tabrect.Width--; if (ti == 0) { tabrect.Height -= 3; RibbonControl.RenderSelection(e.Graphics, tabrect, 3f, this.pressed); tabrect.Height += 3; } else { RibbonControl.RenderTopSelection(e.Graphics, tabrect, 3f, this.pressed); } tabrect.Width++; } tabrect.Height -= 2; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(tab.Text, tab.Font, new SolidBrush(Color.FromArgb(21, 66, 139)), tabrect, sf); ti++; } } break; case ColorScheme.Gray: { e.Graphics.Clear(Color.FromArgb(83, 83, 83)); Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); if (this.Height > 26) { RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 17), 3f); RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 16), 3f); } int ti = 0; foreach (TabPage tab in this.TabPages) { Rectangle tabrect = this.GetTabRect(ti); tabrect.Height += 4; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; if (this.SelectedIndex > 0 && this.Height > 26 && tab == this.SelectedTab) { RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(tabrect.X - 2, tabrect.Y, tabrect.Width + 4, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(16, Color.Black)), new Rectangle(tabrect.X - 1, tabrect.Y, tabrect.Width + 2, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new LinearGradientBrush(tabrect, Color.FromArgb(237, 238, 239), Color.FromArgb(206, 210, 217), LinearGradientMode.Vertical), tabrect, 3f); RibbonControl.DrawTopRoundRectangle(e.Graphics, new Pen(Color.FromArgb(190, 190, 190)), tabrect, 3f); tabrect.Offset(1, 1); tabrect.Width -= 2; tabrect.Height--; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(tabrect, Color.FromArgb(249, 249, 249), Color.Transparent, LinearGradientMode.ForwardDiagonal)), tabrect, 3f); Region region = new Region(); region.Exclude(new Rectangle(tabrect.X - 4, 0, tabrect.Width + 1, 2)); tab.Region = region; tabrect.Height -= 2; e.Graphics.DrawString(tab.Text, tab.Font, new SolidBrush(Color.Black), tabrect, sf); } else if (ti == this.hoverindex) { tabrect.Width--; if (ti == 0) { tabrect.X += 2; tabrect.Width -= 2; tabrect.Height -= 3; RibbonControl.RenderSelection(e.Graphics, tabrect, 3f, this.pressed); tabrect.X -= 2; tabrect.Width += 2; tabrect.Height += 3; } else { RibbonControl.RenderTopSelection(e.Graphics, tabrect, 3f, this.pressed); } tabrect.Width++; tabrect.Height -= 2; e.Graphics.DrawString(tab.Text, tab.Font, new SolidBrush(Color.Black), tabrect, sf); } else { tabrect.Height -= 2; e.Graphics.DrawString(tab.Text, tab.Font, new SolidBrush(Color.White), tabrect, sf); } ti++; } } break; case ColorScheme.Custom: { e.Graphics.Clear(RibbonControl.Color); Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); if (this.Height > 26) { RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 17), 3f); RibbonControl.FillRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(5, this.Height - 20, this.Width - 10, 16), 3f); } int ti = 0; foreach (TabPage tab in this.TabPages) { Rectangle tabrect = this.GetTabRect(ti); tabrect.Height += 4; if (this.SelectedIndex > 0 && this.Height > 26 && tab == this.SelectedTab) { RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(32, Color.Black)), new Rectangle(tabrect.X - 2, tabrect.Y, tabrect.Width + 4, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new SolidBrush(Color.FromArgb(16, Color.Black)), new Rectangle(tabrect.X - 1, tabrect.Y, tabrect.Width + 2, tabrect.Height + 4), 3f); RibbonControl.FillTopRoundRectangle(e.Graphics, new LinearGradientBrush(tabrect, RibbonControl.GetColor(1.085), RibbonControl.GetColor(1.025), LinearGradientMode.Vertical), tabrect, 3f); RibbonControl.DrawTopRoundRectangle(e.Graphics, new Pen(RibbonControl.GetColor(0.75)), tabrect, 3f); tabrect.Offset(1, 1); tabrect.Width -= 2; tabrect.Height--; RibbonControl.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(tabrect, RibbonControl.GetColor(1.105), Color.Transparent, LinearGradientMode.ForwardDiagonal)), tabrect, 3f); Region region = new Region(); region.Exclude(new Rectangle(tabrect.X - 4, 0, tabrect.Width + 1, 2)); tab.Region = region; } else if (ti == this.hoverindex) { tabrect.Width--; if (ti == 0) { tabrect.Height -= 3; RibbonControl.RenderSelection(e.Graphics, tabrect, 3f, this.pressed); tabrect.Height += 3; } else { RibbonControl.RenderTopSelection(e.Graphics, tabrect, 3f, this.pressed); } tabrect.Width++; } tabrect.Height -= 2; StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; e.Graphics.DrawString(tab.Text, tab.Font, new SolidBrush(RibbonControl.TextColor), tabrect, sf); ti++; } } break; } }