private void CreateCheckCodeImage(string checkCode) { if ((checkCode != null) && (checkCode.Trim() != string.Empty)) { Bitmap image = new Bitmap((int)Math.Ceiling((double)(checkCode.Length * 11.5)), 20); Graphics graphics = Graphics.FromImage(image); try { new Random(); graphics.Clear(Color.White); Font font = new Font("Arial", 13f, FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.DarkRed, 1.2f, true); graphics.DrawString(checkCode, font, brush, (float)2f, (float)2f); graphics.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Gif); base.Response.ClearContent(); base.Response.ContentType = "image/Gif"; base.Response.BinaryWrite(stream.ToArray()); } finally { graphics.Dispose(); image.Dispose(); } } }
private static LinearGradientBrush CreateGradientBrush(Orientation orientation, params Color[] colors) { var brush = new LinearGradientBrush(); var negatedStops = 1 / (float) colors.Length; for (var i = 0; i < colors.Length; i++) { brush.GradientStops.Add(new GradientStop { Offset = negatedStops * i, Color = colors[i] }); } // creating the full loop brush.GradientStops.Add(new GradientStop { Offset = negatedStops * colors.Length, Color = colors[0] }); if (orientation == Orientation.Vertical) { brush.StartPoint = new Point(0, 1); brush.EndPoint = new Point(); } else { brush.EndPoint = new Point(1, 0); } return brush; }
void D2Lines_Paint(object sender, PaintEventArgs e) { var lines = LineInfo.GenerateRandom(new Rectangle(Point.Empty, this.ClientSize)); var sw = new Stopwatch(); sw.Start(); this.d2target.BeginDraw(); this.d2target.Clear(Color.Black); foreach (var line in lines) { using (var gsc = new GradientStopCollection(this.d2target, new[]{ new GradientStop{ Position = 0f, Color = line.Ca }, new GradientStop{ Position = 1f, Color = line.Cb }, })) using(var gb = new LinearGradientBrush(this.d2target, gsc, new LinearGradientBrushProperties{ StartPoint = line.Pa, EndPoint = line.Pb, })) { this.d2target.DrawLine(gb, line.Pa.X, line.Pa.Y, line.Pb.X, line.Pb.Y); } } this.d2target.EndDraw(); sw.Stop(); Program.Info( "{0}: {1} [ms], {2} [line], {3:.00} [line/ms], {4} * {5}", this.Text, sw.ElapsedMilliseconds, lines.Length, lines.Length / (float)sw.ElapsedMilliseconds, this.ClientSize.Width, this.ClientSize.Height ); }
/// <summary> /// Converts the color of the supplied brush changing its luminosity by the given factor. /// </summary> /// <param name="value">The value that is produced by the binding target.</param> /// <param name="targetType">The type to convert to.</param> /// <param name="parameter">The factor used to adjust the luminosity (0..1).</param> /// <param name="culture">The culture to use in the converter (unused).</param> /// <returns>A converted value.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) #endif { if (value == null) return null; if (parameter == null) return null; var factor = double.Parse(parameter.ToString(), CultureInfo.InvariantCulture); if (value is SolidColorBrush) { var color = ((SolidColorBrush)value).Color; var hlsColor = HlsColor.FromRgb(color); hlsColor.L *= factor; return new SolidColorBrush(hlsColor.ToRgb()); } else if (value is LinearGradientBrush) { var gradientStops = new GradientStopCollection(); foreach (var stop in ((LinearGradientBrush)value).GradientStops) { var hlsColor = HlsColor.FromRgb(stop.Color); hlsColor.L *= factor; gradientStops.Add(new GradientStop() { Color = hlsColor.ToRgb(), Offset = stop.Offset }); } var brush = new LinearGradientBrush(gradientStops, 0.0); return brush; } return value; }
protected void Page_Load(object sender, System.EventArgs e) { // Create the in-memory bitmap where you will draw the image. Bitmap image = new Bitmap(300, 300); Graphics g = Graphics.FromImage(image); // Paint the background. g.FillRectangle(Brushes.White, 0, 0, 300, 300); // Create a brush to use. LinearGradientBrush myBrush; // Create variable to track the coordinates in the image. int y = 20; int x = 20; // Show a rectangle with each type of gradient. foreach (LinearGradientMode gradientStyle in System.Enum.GetValues(typeof(LinearGradientMode))) { myBrush = new LinearGradientBrush(new Rectangle(x, y, 100, 60), Color.Violet, Color.White, gradientStyle); g.FillRectangle(myBrush, x, y, 100, 60); g.DrawString(gradientStyle.ToString(), new Font("Tahoma", 8), Brushes.Black, 110 + x, y + 20); y += 70; } // Render the image to the HTML output stream. image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); image.Dispose(); }
public static void Run() { // ExStart:DrawingUsingGraphics // The path to the documents directory. string dataDir = RunExamples.GetDataDir_DrawingAndFormattingImages() + "SampleImage_out.bmp"; // Create an instance of BmpOptions and set its various properties BmpOptions imageOptions = new BmpOptions(); imageOptions.BitsPerPixel = 24; // Create an instance of FileCreateSource and assign it to Source property imageOptions.Source = new FileCreateSource(dataDir, false); using (var image = Image.Create(imageOptions, 500, 500)) { var graphics = new Graphics(image); // Clear the image surface with white color and Create and initialize a Pen object with blue color graphics.Clear(Color.White); var pen = new Pen(Color.Blue); // Draw Ellipse by defining the bounding rectangle of width 150 and height 100 also Draw a polygon using the LinearGradientBrush graphics.DrawEllipse(pen, new Rectangle(10, 10, 150, 100)); using (var linearGradientBrush = new LinearGradientBrush(image.Bounds, Color.Red, Color.White, 45f)) { graphics.FillPolygon(linearGradientBrush, new[] { new Point(200, 200), new Point(400, 200), new Point(250, 350) }); } image.Save(); } // ExEnd:DrawingUsingGraphics }
void OnPaint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Point pt1 = new Point(5, 5); Point pt2 = new Point(25, 25); Brush lg = new LinearGradientBrush(pt1, pt2, Color.Red, Color.Black); g.FillRectangle(lg, 20, 20, 300, 40); pt1 = new Point(5, 25); pt2 = new Point(20, 2); lg = new LinearGradientBrush(pt1, pt2, Color.Yellow, Color.Black); g.FillRectangle(lg, 20, 80, 300, 40); pt1 = new Point(5, 25); pt2 = new Point(2, 2); lg = new LinearGradientBrush(pt1, pt2, Color.Green, Color.Black); g.FillRectangle(lg, 20, 140, 300, 40); pt1 = new Point(25, 25); pt2 = new Point(15, 25); lg = new LinearGradientBrush(pt1, pt2, Color.Blue, Color.Black); g.FillRectangle(lg, 20, 200, 300, 40); pt1 = new Point(0, 10); pt2 = new Point(0, 20); lg = new LinearGradientBrush(pt1, pt2, Color.Orange, Color.Black); g.FillRectangle(lg, 20, 260, 300, 40); lg.Dispose(); g.Dispose(); }
public static void PaintDocumentGradientBackground(Graphics graphics, Rectangle rectangle) { LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, DefaultGradientUpper, DefaultGradientLower, LinearGradientMode.Vertical); graphics.Clear(DefaultGradientUpper); graphics.FillRectangle(BackgroundBrush, rectangle); BackgroundBrush.Dispose(); }
public static void Gradient(Graphics g, Color c1, Color c2, int x, int y, int width, int height) { Rectangle R = new Rectangle(x, y, width, height); using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)) { g.FillRectangle(T, R); } }
public void SetTransform (LinearGradientBrush widget, IMatrix transform) { var brush = ((BrushObject)widget.ControlObject); brush.Matrix = transform; var newmatrix = brush.InitialMatrix.Clone (); newmatrix.Multiply (transform.ToSD ()); brush.Brush.Transform = newmatrix; }
protected override void OnPaintBackground(PaintEventArgs e) { if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0) return; using (var brush = new LinearGradientBrush(ClientRectangle, GradientFirstColor, GradientSecondColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(brush, this.ClientRectangle); } }
//绘制随机码 private void CreatePic(string checkCode) { if (checkCode == null || checkCode.Trim() == String.Empty) return; Bitmap image = new Bitmap(checkCode.Length * 15 + 10, 30); Graphics g = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 g.Clear(Color.White); //画图片的背景噪音线 for (int i = 0; i < 25; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } //画图片字体和字号 Font font = new Font("Arial", 15, (FontStyle.Bold | FontStyle.Italic)); //初始化画刷 LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.BlueViolet, Color.Crimson, 1.2f, true); g.DrawString(checkCode, font, brush, 2, 2); //画图片的前景噪音点 for (int i = 0; i < 100; i++) { int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next())); } //画图片的边框线 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); // 输出图像 System.IO.MemoryStream ms = new System.IO.MemoryStream(); //将图像保存到指定流 image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); //配置输出类型 Response.ContentType = "image/Gif"; //输入内容 Response.BinaryWrite(ms.ToArray()); } finally { //清空不需要的资源 g.Dispose(); image.Dispose(); } }
public static void PaintBackground(Graphics graphics, Rectangle rectangle, Color colorLight, Color colorDark, Blend blend) { LinearGradientBrush BackgroundBrush = new LinearGradientBrush(rectangle, colorLight, colorDark, LinearGradientMode.Vertical); if (blend != null) { BackgroundBrush.Blend = blend; } graphics.FillRectangle(BackgroundBrush, rectangle); BackgroundBrush.Dispose(); }
public static void Blend(Graphics g, Color c1, Color c2, Color c3, float c, int d, int x, int y, int width, int height) { ColorBlend V = new ColorBlend(3); V.Colors = new Color[] { c1, c2, c3 }; V.Positions = new float[] { 0F, c, 1F }; Rectangle R = new Rectangle(x, y, width, height); using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c1, (LinearGradientMode)d)) { T.InterpolationColors = V; g.FillRectangle(T, R); } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Graphics G = e.Graphics; base.OnPaint(e); G.Clear(this.BackColor); //| Drawing the main rectangle base. Rectangle MainRect = new Rectangle(0, 0, Width - 1, Height - 1); Rectangle MainHighlightRect = new Rectangle(1, 1, Width - 3, Height - 3); TextureBrush BGTextureBrush = new TextureBrush(D.CodeToImage(D.BGTexture), WrapMode.TileFlipXY); G.FillRectangle(BGTextureBrush, MainRect); if (OverlayCol != null) { G.FillRectangle(new SolidBrush(OverlayCol), MainRect); } //| Detail to the main rect's top & bottom gradients int GradientHeight = Height / 2; Rectangle ShineRect = new Rectangle(0, 0, Width, GradientHeight); Rectangle ShineRect2 = new Rectangle(0, GradientHeight, Width, GradientHeight); G.FillRectangle(new SolidBrush(Color.FromArgb(40, Pal.ColMed)), ShineRect); D.FillGradientBeam(G, Color.Transparent, Color.FromArgb(60, Pal.ColHighest), ShineRect, GradientAlignment.Vertical); D.FillGradientBeam(G, Color.Transparent, Color.FromArgb(30, Pal.ColHighest), ShineRect2, GradientAlignment.Vertical); if (DrawSeparator) { G.DrawLine(new Pen(Color.FromArgb(50, Color.Black)), new Point(1, ShineRect.Height), new Point(Width - 2, ShineRect.Height)); G.DrawLine(new Pen(Color.FromArgb(35, Pal.ColHighest)), new Point(1, ShineRect.Height + 1), new Point(Width - 2, ShineRect.Height + 1)); G.DrawLine(new Pen(Color.FromArgb(50, Color.Black)), new Point(1, ShineRect.Height + 2), new Point(Width - 2, ShineRect.Height + 2)); } //| Goind back through and making the rect below the detail darker LinearGradientBrush DarkLGB = new LinearGradientBrush(MainRect, Color.FromArgb(20, Color.Black), Color.FromArgb(100, Color.Black), 90); G.FillRectangle(DarkLGB, MainRect); switch (State) { case MouseState.Over: G.FillRectangle(new SolidBrush(Color.FromArgb(30, Pal.ColHighest)), MainRect); break; case MouseState.Down: G.FillRectangle(new SolidBrush(Color.FromArgb(56, Color.Black)), MainRect); break; } G.DrawRectangle(new Pen(Color.FromArgb(40, Pal.ColHighest)), MainHighlightRect); G.DrawRectangle(Pens.Black, MainRect); if (!Enabled) { ForeColor = Color.FromArgb(146, 149, 152); } D.DrawTextWithShadow(G, new Rectangle(0, 0, Width, Height), Text, Font, HorizontalAlignment.Center, ForeColor, Color.Black); }
public async Task RectLinearGradient () { var canvas = Platforms.Current.CreateImageCanvas (new Size (100)); var rect = new Rect (0, 10, 100, 80); var brush = new LinearGradientBrush ( Point.Zero, Point.OneY, Colors.Green, Colors.LightGray); canvas.DrawRectangle (rect, brush: brush); await SaveImage (canvas, "Brush.RectLinearGradient.png"); }
private void ValidateCode(string VNum) { Bitmap image = new Bitmap((int)Math.Ceiling(VNum.Length * 16.0), 24); Graphics g = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 g.Clear(Color.WhiteSmoke); //画图片的干扰线 for (int i = 0; i < 10; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.Goldenrod), x1, y1, x2, y2); } for (int i = 0; i < VNum.Length; i++) { Font font = new Font("Arial", 16, FontStyle.Bold); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.DarkRed, Color.BlueViolet, 2.5f, true); g.DrawString(VNum.Substring(i, 1), font, brush, 2 + i * 14, 1); } //画图片的前景干扰点 for (int i = 0; i < 230; i++) { int x = random.Next(image.Width); int y = random.Next(image.Height); image.SetPixel(x, y, Color.FromArgb(random.Next())); } //画图片的边框线 g.DrawRectangle(new Pen(Color.Gray), 0, 0, image.Width - 1, image.Height - 1); //保存图片数据 MemoryStream stream = new MemoryStream(); image.Save(stream, ImageFormat.Gif); //输出图片 Response.Clear(); Response.ContentType = "image/GIF"; Response.BinaryWrite(stream.ToArray()); } finally { g.Dispose(); image.Dispose(); } }
public async Task RectAbsLinearGradient () { var canvas = Platforms.Current.CreateImageCanvas (new Size (100)); var rect = new Rect (0, 10, 100, 80); var brush = new LinearGradientBrush ( Point.Zero, new Point (0, 200), Colors.Yellow, Colors.Red); brush.Absolute = true; canvas.DrawRectangle (rect, brush: brush); await SaveImage (canvas, "Brush.RectAbsLinearGradient.png"); }
public static void Main() { // For WPF, we need to create two important objects. // You use the "new" keyword to create an object. // First, the application object: Application app = new Application(); // Then, the window object. Window win = new Window(); // The window object, which I called "win" in my program, // represents the main window of our program. // We can set some properties of our object, which make changes // to the real window on the screen. // The Title property sets the text that you see in the title bar. win.Title = "Handle An Event"; // In WPF, the Content property represents what you want to see in // the window. We are going to keep it simple and just put in some text. win.Content = "Coding 101"; // The Width and Height set the size of the window. win.Width = 500; win.Height = 500; // We can change the font of the text by using the FontFamily and // FontSize properties. win.FontFamily = new FontFamily("Comic Sans MS"); win.FontSize = 100; // In WPF, you use Brush objects to paint with color. We will create a special // brush object that is a gradient fill and use that for the Foreground property // which sets the text color. Brush brush = new LinearGradientBrush(Colors.Black, Colors.LightGreen, new Point(0.5, 0), new Point(0.5, 1)); win.Foreground = brush; // The background of the window we will just use a solid brush. win.Background = Brushes.Black; // Windows programs use "events" to let your code know something has // changed or the user took some action. The window class defines lots of // events, but we are just going to use the MouseDown event which represents // a mouse click in the window. // In order to tell our program what to do when the event happens, we // have to "handle" the event. We do that by matching up a function that // we write with the event. In C#, the += operator does the work of tying // the event to the handler. win.MouseDown += WindowOnMouseDown; // The last step we need to do is call the Run() method of the application // object we created. We pass it the window object we created. The Run() // method makes the window visible, and it keeps the program running // until the main window is closed. app.Run(win); }
public async Task Example1 () { var canvas = Platforms.Current.CreateImageCanvas (new Size (100), scale: 2); var skyBrush = new LinearGradientBrush (Point.Zero, Point.OneY, Colors.Blue, Colors.White); canvas.FillRectangle (new Rect (canvas.Size), skyBrush); canvas.FillEllipse (10, 10, 30, 30, Colors.Yellow); canvas.FillRectangle (50, 60, 60, 40, Colors.LightGray); canvas.FillPath (new PathOp[] { new MoveTo (40, 60), new LineTo (120, 60), new LineTo (80, 30), new ClosePath () }, Colors.Gray); await SaveImage (canvas, "Example1.png"); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { if (MouseState == State.MouseDown) B1 = new LinearGradientBrush(ClientRectangle, C1, C2, LinearGradientMode.Vertical); else B1 = new LinearGradientBrush(ClientRectangle, C2, C1, LinearGradientMode.Vertical); G.FillRectangle(B1, ClientRectangle); DrawText(HorizontalAlignment.Center, new SolidBrush(ForeColor)); DrawIcon(HorizontalAlignment.Left); DrawBorders(P1, P2, ClientRectangle); DrawCorners(BackColor, ClientRectangle); e.Graphics.DrawImage(B, 0, 0); }
protected void Page_Load(object sender, System.EventArgs e) { string text = Server.UrlDecode(Request.QueryString["Text"]); int textSize = Int32.Parse(Request.QueryString["TextSize"]); Color textColor = Color.FromArgb(Int32.Parse(Request.QueryString["TextColor"])); Color gradientColorA = Color.FromArgb(Int32.Parse(Request.QueryString["GradientColorA"])); Color gradientColorB = Color.FromArgb(Int32.Parse(Request.QueryString["GradientColorB"])); // Define the font. Font font = new Font("Tahoma", textSize, FontStyle.Bold); // Use a test image to measure the text. Bitmap image = new Bitmap(1, 1); Graphics g = Graphics.FromImage(image); SizeF size = g.MeasureString(text, font); g.Dispose(); image.Dispose(); // Using these measurements, try to choose a reasonable bitmap size. // Even if the text is large, cap the size at some maximum to // prevent causing a serious server slowdown! // (Allow for a 10 pixel buffer on all sides). int width = (int)Math.Min(size.Width + 20, 800); int height = (int)Math.Min(size.Height + 20, 800); image = new Bitmap(width, height); g = Graphics.FromImage(image); LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(new Point(0, 0), image.Size), gradientColorA, gradientColorB, LinearGradientMode.ForwardDiagonal); // Draw the gradient background. g.FillRectangle(brush, 0, 0, 300, 300); // Draw the label text. g.DrawString(text, font, new SolidBrush(textColor), 10, 10); // Render the image to the HTML output stream. image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); image.Dispose(); }
public override void DrawHeaderBg(System.Drawing.Graphics g, System.Drawing.Rectangle rect) { if (HeaderBgGradient) { using (LinearGradientBrush aGB = new LinearGradientBrush(rect, HeaderBgColor, HeaderBgColor2, LinearGradientMode.Vertical)) g.FillRectangle(aGB, rect); } else { using (SolidBrush backBrush = new SolidBrush(HeaderBgColor)) g.FillRectangle(backBrush, rect); } if (HasHorizontalLine) { using (Pen aPen = new Pen(GridColor)) g.DrawLine(aPen, rect.Left, rect.Bottom, rect.Right, rect.Bottom); } }
protected override void OnPaint (PaintEventArgs e) { base.OnPaint (e); LinearGradientBrush brush = new LinearGradientBrush ( new Point (10, 10), new Point (15, 10), Color.Red, Color.Yellow); Rectangle rect = new Rectangle (10, 10, 10, 10); Point [] points = new Point [] { new Point(100, 100), new Point(200, 100), new Point(100, 200) }; brush.Transform = new Matrix (rect, points); brush.WrapMode = WrapMode.TileFlipX; Pen pen = new Pen (Color.Black); e.Graphics.FillRectangle (brush, 100, 100, 100, 100); e.Graphics.DrawRectangle (pen, 100, 100, 100, 100); }
private void CreateCheckCodeImage(string checkCode) { if (checkCode == null || checkCode.Trim() == String.Empty) { return; } int iWordWidth = 15; int iImageWidth = checkCode.Length * iWordWidth; Bitmap image = new Bitmap(iImageWidth, 20); Graphics g = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 g.Clear(Color.White); //画图片的背景噪音点 for (int i = 0; i < 20; i++) { int x1 = random.Next(image.Width); int x2 = random.Next(image.Width); int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2); } //画图片的背景噪音线 for (int i = 0; i < 2; i++) { int x1 = 0; int x2 = image.Width; int y1 = random.Next(image.Height); int y2 = random.Next(image.Height); if (i == 0) { g.DrawLine(new Pen(Color.Gray, 2), x1, y1, x2, y2); } } for (int i = 0; i < checkCode.Length; i++) { string Code = checkCode[i].ToString(); int xLeft = iWordWidth * (i); random = new Random(xLeft); int iSeed = DateTime.Now.Millisecond; int iValue = random.Next(iSeed) % 4; if (iValue == 0) { Font font = new Font("Arial", 13, (FontStyle.Bold | System.Drawing.FontStyle.Italic)); Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height); LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Red, 1.5f, true); g.DrawString(Code, font, brush, xLeft, 2); } else if (iValue == 1) { Font font = new System.Drawing.Font("楷体", 13, (FontStyle.Bold)); Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height); LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.DarkRed, 1.3f, true); g.DrawString(Code, font, brush, xLeft, 2); } else if (iValue == 2) { Font font = new System.Drawing.Font("宋体", 13, (System.Drawing.FontStyle.Bold)); Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height); LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Green, Color.Blue, 1.2f, true); g.DrawString(Code, font, brush, xLeft, 2); } else if (iValue == 3) { Font font = new System.Drawing.Font("黑体", 13, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Bold)); Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height); LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Green, 1.8f, true); g.DrawString(Code, font, brush, xLeft, 2); } } //////画图片的前景噪音点 //for (int i = 0; i < 8; i++) //{ // int x = random.Next(image.Width); // int y = random.Next(image.Height); // image.SetPixel(x, y, Color.FromArgb(random.Next())); //} //画图片的边框线 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1); System.IO.MemoryStream ms = new System.IO.MemoryStream(); image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.ClearContent(); Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); } }
private void CustomClassicPaintHook() { LinearGradientBrush L1; HatchBrush hatchBrush; SolidBrush soliBrush; Rectangle R1 = new Rectangle(2, 2, Width - 4, Height - 4); //G.FillRectangle(new SolidBrush(customClassicBackground), ClientRectangle); DrawBorders(new Pen(customClassicBorder), ClientRectangle); DrawBorders(new Pen(customClassicHighlight), 1, 1, Width - 2, Height - 2); switch (State) { case MouseState.Over: L1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(100, customClassicColors[0]), customClassicColors[1], 270); soliBrush = new SolidBrush(Color.FromArgb(100, customClassicColors[0])); switch (DrawMode) { case RenderMode.Solid: G.FillRectangle(soliBrush, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; case RenderMode.Gradient: G.FillRectangle(L1, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; case RenderMode.Hatch: hatchBrush = new HatchBrush(HatchStyles, Color.FromArgb(100, customClassicColors[0]), customClassicColors[1]); G.FillRectangle(hatchBrush, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; default: throw new ArgumentOutOfRangeException(); } break; case MouseState.Down: L1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(50, customClassicColors[0]), customClassicColors[1], 90); soliBrush = new SolidBrush(Color.FromArgb(50, customClassicColors[0])); switch (DrawMode) { case RenderMode.Solid: G.FillRectangle(soliBrush, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; case RenderMode.Gradient: G.FillRectangle(L1, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; case RenderMode.Hatch: hatchBrush = new HatchBrush(HatchStyles, Color.FromArgb(50, customClassicColors[0]), customClassicColors[1]); G.FillRectangle(hatchBrush, R1); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 7, Width - 2, Height - 7); break; default: throw new ArgumentOutOfRangeException(); } break; case MouseState.None: switch (DrawMode) { case RenderMode.Solid: G.FillRectangle(new SolidBrush(customClassicBackground), ClientRectangle); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 8, Width - 2, Height - 8); break; case RenderMode.Gradient: L1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(255, customClassicBackground), customClassicBackground, 90); G.FillRectangle(L1, ClientRectangle); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 8, Width - 2, Height - 8); break; case RenderMode.Hatch: hatchBrush = new HatchBrush(HatchStyles, customClassicBackground, Color.FromArgb(25, customClassicBackground)); G.FillRectangle(hatchBrush, ClientRectangle); G.FillRectangle(new SolidBrush(customClassicShadow), 1, 8, Width - 2, Height - 8); break; default: throw new ArgumentOutOfRangeException(); } break; } //DrawText(ClassicBloom[4].Brush, HorizontalAlignment.Center, 0, 0); }
/// <summary> /// Paints the bar. /// </summary> /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param> protected virtual void PaintBar(PaintEventArgs e) { float angle; angle = (this.Orientation == Orientation.Horizontal) ? 0 : 90; if (this.BarBounds.Height > 0 && this.BarBounds.Width > 0) { ColorBlend blend; // HACK: Inflating the brush rectangle by 1 seems to get rid of a odd issue where the last color is drawn on the first pixel blend = new ColorBlend(); using (LinearGradientBrush brush = new LinearGradientBrush(Rectangle.Inflate(this.BarBounds, 1, 1), Color.Empty, Color.Empty, angle, false)) { switch (this.BarStyle) { case ColorBarStyle.TwoColor: blend.Colors = new[] { this.Color1, this.Color2 }; blend.Positions = new[] { 0F, 1F }; break; case ColorBarStyle.ThreeColor: blend.Colors = new[] { this.Color1, this.Color2, this.Color3 }; blend.Positions = new[] { 0, 0.5F, 1 }; break; case ColorBarStyle.Custom: if (this.CustomColors != null && this.CustomColors.Count > 0) { blend.Colors = this.CustomColors.ToArray(); blend.Positions = Enumerable.Range(0, this.CustomColors.Count).Select(i => i == 0 ? 0 : i == this.CustomColors.Count - 1 ? 1 : (float)(1.0D / this.CustomColors.Count) * i).ToArray(); } else { blend.Colors = new[] { this.Color1, this.Color2 }; blend.Positions = new[] { 0F, 1F }; } break; } brush.InterpolationColors = blend; e.Graphics.FillRectangle(brush, this.BarBounds); } } }
private static Brush CreateBrush(string solidBrushColor, XElement xComplexBrush) { if (solidBrushColor != null) { return(new SolidColorBrush((Color)ColorConverter.ConvertFromString(solidBrushColor))); } else if (xComplexBrush != null) { var nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; GradientBrush gBrush = null; if (String.CompareOrdinal(xComplexBrush.Name.LocalName, "LinearGradientBrush") == 0) { var lBrush = new LinearGradientBrush(); if (xComplexBrush.Attribute("StartPoint") != null) { var props = xComplexBrush.Attribute("StartPoint").Value.Split(',', ' '); lBrush.StartPoint = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi)); } if (xComplexBrush.Attribute("EndPoint") != null) { var props = xComplexBrush.Attribute("EndPoint").Value.Split(',', ' '); lBrush.EndPoint = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi)); } gBrush = lBrush; } else if (String.CompareOrdinal(xComplexBrush.Name.LocalName, "RadialGradientBrush") == 0) { var rBrush = new RadialGradientBrush(); if (xComplexBrush.Attribute("Center") != null) { var props = xComplexBrush.Attribute("Center").Value.Split(',', ' '); rBrush.Center = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi)); } if (xComplexBrush.Attribute("GradientOrigin") != null) { var props = xComplexBrush.Attribute("GradientOrigin").Value.Split(',', ' '); rBrush.GradientOrigin = new Point(Double.Parse(props[0], nfi), Double.Parse(props[1], nfi)); } if (xComplexBrush.Attribute("RadiusX") != null) { rBrush.RadiusX = Double.Parse(xComplexBrush.Attribute("RadiusX").Value, nfi); } if (xComplexBrush.Attribute("RadiusY") != null) { rBrush.RadiusY = Double.Parse(xComplexBrush.Attribute("RadiusY").Value, nfi); } gBrush = rBrush; } else { throw new Exception("Unknwon complex brush type: " + xComplexBrush.Name.LocalName); } if (gBrush != null) { var xStops = from s in xComplexBrush.Elements("GradientStop") select new { Offset = (string)s.Attributes("Offset").FirstOrDefault(), Color = (string)s.Attributes("Color").FirstOrDefault() }; foreach (var s in xStops) { var stop = new GradientStop(); if (s.Offset != null) { stop.Offset = Double.Parse(s.Offset, nfi); } if (s.Color != null) { stop.Color = (Color)ColorConverter.ConvertFromString(s.Color); } gBrush.GradientStops.Add(stop); } return(gBrush); } } return(null); }
protected override void OnPaint(PaintEventArgs e) { if (_palette != null) { // Save the original state, so any changes we make are easy to undo GraphicsState state = e.Graphics.Save(); // We want the inner part of the control to act like a button, so // we need to find the correct palette state based on if the mouse // is over the control and currently being pressed down or not. PaletteState buttonState = GetButtonState(); ///////////////////////////////////////////////////// // Get the various palette details needed to draw // // our fish in the various states we implement // ///////////////////////////////////////////////////// // Get the two colors and angle used to draw the control background Color backColor1 = _palette.GetBackColor1(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled); Color backColor2 = _palette.GetBackColor2(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled); float backColorAngle = _palette.GetBackColorAngle(PaletteBackStyle.PanelAlternate, Enabled ? PaletteState.Normal : PaletteState.Disabled); // Get the two colors and angle used to draw the fish area background Color fillColor1 = _palette.GetBackColor1(PaletteBackStyle.ButtonStandalone, buttonState); Color fillColor2 = _palette.GetBackColor2(PaletteBackStyle.ButtonStandalone, buttonState); float fillColorAngle = _palette.GetBackColorAngle(PaletteBackStyle.ButtonStandalone, buttonState); // Get the color used to draw the fish border Color borderColor = _palette.GetBorderColor1(PaletteBorderStyle.ButtonStandalone, buttonState); // Get the color and font used to draw the text Color textColor = _palette.GetContentShortTextColor1(PaletteContentStyle.ButtonStandalone, buttonState); Font textFont = _palette.GetContentShortTextFont(PaletteContentStyle.ButtonStandalone, buttonState); ///////////////////////////////////////////////////// // Perform actual drawing using the palette values // ///////////////////////////////////////////////////// // Populate a graphics path to describe the shape we want to draw using (GraphicsPath path = CreateFishPath()) { // We want to anti alias the drawing for nice smooth curves e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // Fill the entire background in the control background color using (Brush backBrush = new LinearGradientBrush(ClientRectangle, backColor1, backColor2, backColorAngle)) { e.Graphics.FillRectangle(backBrush, e.ClipRectangle); } // Fill the entire fish background using a gradient using (Brush fillBrush = new LinearGradientBrush(ClientRectangle, fillColor1, fillColor2, fillColorAngle)) { e.Graphics.FillPath(fillBrush, path); } // Draw the fish border using a single color using (Pen borderPen = new Pen(borderColor)) { e.Graphics.DrawPath(borderPen, path); } // Draw the text in about the center of the control using (Brush textBrush = new SolidBrush(textColor)) { e.Graphics.DrawString("Click me!", textFont, textBrush, Width / 2 - 10, Height / 2 - 5); } } // Put graphics back into original state before returning e.Graphics.Restore(state); } base.OnPaint(e); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0) { return; } if (PaintSplitterBackground != null) { PaintSplitterBackground(this, e); } if (_fillGradient) { Brush backBrush = new LinearGradientBrush(ClientRectangle, SystemColors.ControlLightLight, SystemColors.ControlDark, _isVertical ? LinearGradientMode.Horizontal : LinearGradientMode.Vertical); using ( backBrush ) { e.Graphics.FillRectangle(backBrush, ClientRectangle); } } Rectangle rcSplitterCenter = _splitterCenterRect; if (_fillCenterRect) { ColorScheme.DrawRectangle(e.Graphics, _colorScheme, "Splitter.CenterBorder", new Rectangle(rcSplitterCenter.Left, rcSplitterCenter.Top, rcSplitterCenter.Width - 1, rcSplitterCenter.Height - 1), SystemPens.Control); } if (_isVertical) { rcSplitterCenter.Inflate(0, -1); } else { rcSplitterCenter.Inflate(-1, 0); } if (_fillCenterRect && rcSplitterCenter.Width > 0 && rcSplitterCenter.Height > 0) { ColorScheme.FillRectangle(e.Graphics, _colorScheme, _isVertical ? "Splitter.CenterVert" : "Splitter.CenterHorz", rcSplitterCenter, SystemBrushes.Control); } if (_controlToCollapse != null) { for (int coord = _splitterCenter - _splitterCenterSize / 2 + 10; coord < _splitterCenter - 10; coord += 3) { DrawCenterDot(e.Graphics, coord); } for (int coord = _splitterCenter + 10; coord < _splitterCenter + _splitterCenterSize / 2 - 10; coord += 3) { DrawCenterDot(e.Graphics, coord); } Brush arrowBrush = ColorScheme.GetBrush(_colorScheme, "Splitter.Arrow", rcSplitterCenter, Brushes.Black); if (Dock == DockStyle.Top && _controlToCollapse.Visible) { e.Graphics.FillPolygon(arrowBrush, new Point[] { new Point(_splitterCenter - _splitterArrowSize, ClientRectangle.Bottom - 1), new Point(_splitterCenter + _splitterArrowSize + 1, ClientRectangle.Bottom - 1), new Point(_splitterCenter, ClientRectangle.Top - 1) }); } if (Dock == DockStyle.Top && !_controlToCollapse.Visible) { e.Graphics.FillPolygon(arrowBrush, new Point[] { new Point(_splitterCenter - _splitterArrowSize, ClientRectangle.Top), new Point(_splitterCenter + _splitterArrowSize + 1, ClientRectangle.Top), new Point(_splitterCenter, ClientRectangle.Bottom) }); } if ((Dock == DockStyle.Left && _controlToCollapse.Visible) || (Dock == DockStyle.Right && !_controlToCollapse.Visible)) { e.Graphics.FillPolygon(arrowBrush, new Point[] { new Point(ClientRectangle.Right - 1, _splitterCenter - _splitterArrowSize), new Point(ClientRectangle.Right - 1, _splitterCenter + _splitterArrowSize + 1), new Point(ClientRectangle.Left - 1, _splitterCenter) }); } if ((Dock == DockStyle.Right && _controlToCollapse.Visible) || (Dock == DockStyle.Left && !_controlToCollapse.Visible)) { e.Graphics.FillPolygon(arrowBrush, new Point[] { new Point(ClientRectangle.Left, _splitterCenter - _splitterArrowSize), new Point(ClientRectangle.Left, _splitterCenter + _splitterArrowSize + 1), new Point(ClientRectangle.Right, _splitterCenter) }); } } else { for (int coord = _splitterCenter - _splitterCenterSize / 2 + 10; coord < _splitterCenter + _splitterCenterSize / 2 - 10; coord += 3) { DrawCenterDot(e.Graphics, coord); } } }
private static readonly MainWindow MainWindow = (MainWindow)Application.Current.MainWindow; // Cсылка на главное окно public static void ShowNewAchieveWindow(string name, string achieve) // Показываем окно новой ачивки { var window = new Windows.NewAchieve(); switch (achieve) // В зависимости от названия ачивки вибираем сообщение, картинку и кисть { case "A10matchespalyed": window.AchieveName.Content = "\"10 games played\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10MatchesPlayed.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A100MatchesPalyed": window.AchieveName.Content = "\"100 games played\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100MatchesPlayed.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A1000MatchesPalyed": window.AchieveName.Content = "\"1000 games played\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000MatchesPlayed.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A10MatchesWon": window.AchieveName.Content = "\"10 matches won\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10MatchesWon.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A100MatchesWon": window.AchieveName.Content = "\"100 matches won\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100MatchesWon.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A1000MatchesWon": window.AchieveName.Content = "\"1000 matches won\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000MatchesWon.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A1000Throws": window.AchieveName.Content = "\"1000 throws made\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000Throws.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A10000Throws": window.AchieveName.Content = "\"10000 throws made\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10000Throws.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A100000Throws": window.AchieveName.Content = "\"100000 throws made\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100000Throws.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A10000Points": window.AchieveName.Content = "\"10000 points collected\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/10000Points.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A100000Points": window.AchieveName.Content = "\"100000 points collected\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/100000Points.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A1000000Points": window.AchieveName.Content = "\"1000000 points collected\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/1000000Points.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A180x10": window.AchieveName.Content = "\"10x180 hand committed\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x10.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A180x100": window.AchieveName.Content = "\"100x180 hand committed\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x100.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A180x1000": window.AchieveName.Content = "\"1000x180 hand committed\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/180x1000.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "AFirst180": window.AchieveName.Content = "\"It's your first 180 !\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/First180.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "A3Bull": window.AchieveName.Content = "\"3-eyed bull\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/3Bull.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; case "AmrZ": window.AchieveName.Content = "\"Absolute zero\""; window.AchieveImage.Source = new BitmapImage(new Uri("/OneHundredAndEighty;component/Images/Achieves/mr.Z.png", UriKind.Relative)); window.AchieveLight.Fill = Brush(achieve); break; } window.PlayerName.Content = name; window.Owner = MainWindow; MainWindow.FadeIn(); window.ShowDialog(); MainWindow.FadeOut(); Brush Brush(string achieveName) // Выбираем кисть { var brush = new LinearGradientBrush(); switch (achieveName) { case "A10matchespalyed": case "A10MatchesWon": case "A1000Throws": case "A10000Points": case "A180x10": brush.StartPoint = new Point(0.5, 1); brush.EndPoint = new Point(0.5, 0); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00420F"), 0)); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF2DC700"), 1)); brush.RelativeTransform = new RotateTransform(225); break; case "A100MatchesPalyed": case "A100MatchesWon": case "A10000Throws": case "A100000Points": case "A180x100": brush.StartPoint = new Point(0.5, 1); brush.EndPoint = new Point(0.5, 0); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF050078"), 0)); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00B1D8"), 1)); brush.RelativeTransform = new RotateTransform(225); break; case "A1000MatchesPalyed": case "A1000MatchesWon": case "A100000Throws": case "A1000000Points": case "A180x1000": brush.StartPoint = new Point(0.5, 1); brush.EndPoint = new Point(0.5, 0); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF610000"), 0)); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF81009E"), 1)); brush.RelativeTransform = new RotateTransform(225); break; case "AFirst180": brush.StartPoint = new Point(0.5, 0); brush.EndPoint = new Point(0.5, 1); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFFF4600"), 0)); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF34CF07"), 1)); brush.RelativeTransform = new RotateTransform(250); break; case "AmrZ": brush.StartPoint = new Point(0.5, 0); brush.EndPoint = new Point(0.5, 1); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF5B5B5B"), 0)); brush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFF7F7F7"), 1)); brush.RelativeTransform = new RotateTransform(225); break; case "A3Bull": var gradientBrush = new RadialGradientBrush(); gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FFC70900"), 0)); gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF00420F"), 0.577)); gradientBrush.GradientStops.Add(new GradientStop((Color)ColorConverter.ConvertFromString("#FF360146"), 1)); return(gradientBrush); } return(brush); } }
public override void DrawAt(Graphics g, float ratio, bool preview) { base.DrawAt(g, ratio, preview); if (Orientation.Horizontal == this.Orientation) { if (this.Size.Width < this.Size.Height) { this.Size = new Size(this.Size.Height, this.Size.Width); } } else { if (this.Size.Width > this.Size.Height) { this.Size = new Size(this.Size.Height, this.Size.Width); } } if (ControlState.Move == this.State) { Pen pen = new Pen(Color.Navy, 2.0f); DrawRoundRectangle(g, pen, this.RectInPage, this.Radius, 1.0f, ratio); } else { Rectangle rect = new Rectangle(Point.Empty, this.RectInPage.Size); Bitmap bm = new Bitmap(this.RectInPage.Width, this.RectInPage.Height); Graphics gp = Graphics.FromImage(bm); Color backColor = Color.FromArgb((int)(this.Alpha * 255), this.BackgroundColor); int p = (int)Math.Round(PADDING * ratio, 0); int sew = (int)Math.Round(SLIDER_EDGE_WIDTH * ratio, 0); /* SliderSwitch的长条形主体 */ int x; int y; // int width; int height; if (Orientation.Horizontal == this.Orientation) { x = 0; y = sew; width = rect.Width; height = rect.Height - 2 * y; } else { y = 0; x = sew; width = rect.Width - 2 * x; height = rect.Height; } Rectangle rect1 = new Rectangle(rect.X + x, rect.Y + y, width, height); if (EFlatStyle.Stereo == this.FlatStyle) { /* 绘制立体效果,三色渐变 */ LinearGradientBrush brush; Color[] colors = new Color[3]; ColorBlend blend = new ColorBlend(); if (Orientation.Horizontal == this.Orientation) { brush = new LinearGradientBrush(rect1, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical); colors[0] = ColorHelper.changeBrightnessOfColor(backColor, 100); colors[1] = backColor; colors[2] = ColorHelper.changeBrightnessOfColor(backColor, -50); blend.Positions = new float[] { .0f, 0.3f, 1.0f }; } else { brush = new LinearGradientBrush(rect1, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal); colors[0] = ColorHelper.changeBrightnessOfColor(backColor, 100); colors[1] = backColor; colors[2] = ColorHelper.changeBrightnessOfColor(backColor, -50); blend.Positions = new float[] { .0f, 0.7f, 1.0f }; } blend.Colors = colors; brush.InterpolationColors = blend; FillRoundRectangle(gp, brush, rect1, this.Radius, 1.0f, ratio); brush.Dispose(); } else if (EFlatStyle.Flat == this.FlatStyle) { SolidBrush brush = new SolidBrush(backColor); FillRoundRectangle(gp, brush, rect1, this.Radius, 1.0f, ratio); } /* 第一个图标 左边/下边 */ if (Orientation.Horizontal == this.Orientation) { x = p; y = p; height = rect.Height - 2 * y; // 计算出高度 width = height; // 计算出宽度 } else { x = p; // PADDING; width = rect.Width - 2 * x; height = width; y = rect.Height - p /*PADDING*/ - height; } Image img = this.ImgLeftImage; if (null != img) { gp.DrawImage(ImageHelper.Resize(img, new Size(width, height), false), rect.X + x, rect.Y + y); } /* 第二个图标 右边/上边 */ img = null; if (Orientation.Horizontal == this.Orientation) { x = rect.Width - p /*PADDING*/ - width; } else { y = p; // PADDING; } img = this.ImgRightImage; if (null != img) { gp.DrawImage(ImageHelper.Resize(img, new Size(width, height), false), rect.X + x, rect.Y + y); } int sw = (int)Math.Round(this.SliderWidth * ratio, 0); /* 中间滑块 */ if (Orientation.Horizontal == this.Orientation) { width = sw; // this.SliderWidth; x = rect.Width / 2 - width / 2; y = 0; height = rect.Height; } else { height = sw; // this.SliderWidth; y = rect.Height / 2 - height / 2; x = 0; width = rect.Width; } Rectangle rect2 = new Rectangle(rect.X + x, rect.Y + y, width, height); Color sliderColor = ColorHelper.changeBrightnessOfColor(backColor, 70); LinearGradientBrush sliderBrush; Color[] sliderColors = new Color[3]; ColorBlend sliderBlend = new ColorBlend(); if (Orientation.Horizontal == this.Orientation) { sliderBrush = new LinearGradientBrush(rect2, Color.Transparent, Color.Transparent, LinearGradientMode.Vertical); sliderColors[0] = ColorHelper.changeBrightnessOfColor(backColor, 100); sliderColors[1] = backColor; sliderColors[2] = ColorHelper.changeBrightnessOfColor(backColor, -50); sliderBlend.Positions = new float[] { .0f, 0.3f, 1.0f }; } else { sliderBrush = new LinearGradientBrush(rect2, Color.Transparent, Color.Transparent, LinearGradientMode.Horizontal); sliderColors[0] = ColorHelper.changeBrightnessOfColor(backColor, 100); sliderColors[1] = backColor; sliderColors[2] = ColorHelper.changeBrightnessOfColor(backColor, -50); sliderBlend.Positions = new float[] { .0f, 0.7f, 1.0f }; } sliderBlend.Colors = sliderColors; sliderBrush.InterpolationColors = sliderBlend; FillRoundRectangle(gp, sliderBrush, rect2, this.Radius, .0f, ratio); sliderBrush.Dispose(); if (EBool.Yes == this.DisplayBorder) { Color borderColor = this.BorderColor; DrawRoundRectangle(gp, new Pen(borderColor, 1), rect, this.Radius, 1.0f, ratio); } g.DrawImage(bm, this.VisibleRectInPage, new Rectangle(new Point(this.VisibleRectInPage.X - this.RectInPage.X, this.VisibleRectInPage.Y - this.RectInPage.Y), this.VisibleRectInPage.Size), GraphicsUnit.Pixel); if (!preview) { this.FrameIsVisible = false; if (this.IsThisSelected) { this.SetFrame(); Pen pen = new Pen(Color.LightGray, 1.0f); pen.DashStyle = DashStyle.Dot;//设置为虚线,用虚线画四边,模拟微软效果 g.DrawLine(pen, this.LinePoints[0], this.LinePoints[1]); g.DrawLine(pen, this.LinePoints[2], this.LinePoints[3]); g.DrawLine(pen, this.LinePoints[4], this.LinePoints[5]); g.DrawLine(pen, this.LinePoints[6], this.LinePoints[7]); g.DrawLine(pen, this.LinePoints[8], this.LinePoints[9]); g.DrawLine(pen, this.LinePoints[10], this.LinePoints[11]); g.DrawLine(pen, this.LinePoints[12], this.LinePoints[13]); g.DrawLine(pen, this.LinePoints[14], this.LinePoints[15]); g.FillRectangles(Brushes.White, this.SmallRects); //填充8个小矩形的内部 g.DrawRectangles(Pens.Black, this.SmallRects); //绘制8个小矩形的黑色边线 this.FrameIsVisible = true; } } } }
private LinearGradientBrush GetLinearGradientBrush(SvgLinearGradientElement res) { double x1 = res.X1.AnimVal.Value; double x2 = res.X2.AnimVal.Value; double y1 = res.Y1.AnimVal.Value; double y2 = res.Y2.AnimVal.Value; GradientStopCollection gradientStops = GetGradientStops(res.Stops); LinearGradientBrush brush = new LinearGradientBrush(gradientStops, new Point(x1, y1), new Point(x2, y2)); SvgSpreadMethod spreadMethod = SvgSpreadMethod.None; if (res.SpreadMethod != null) { spreadMethod = (SvgSpreadMethod)res.SpreadMethod.AnimVal; if (spreadMethod != SvgSpreadMethod.None) { brush.SpreadMethod = WpfConvert.ToSpreadMethod(spreadMethod); } } if (res.GradientUnits != null) { SvgUnitType mappingMode = (SvgUnitType)res.GradientUnits.AnimVal; if (mappingMode == SvgUnitType.ObjectBoundingBox) { brush.MappingMode = BrushMappingMode.RelativeToBoundingBox; } else if (mappingMode == SvgUnitType.UserSpaceOnUse) { brush.MappingMode = BrushMappingMode.Absolute; } } MatrixTransform transform = GetTransformMatrix(res); if (transform != null && !transform.Matrix.IsIdentity) { brush.Transform = transform; } //else //{ // float fLeft = (float)res.X1.AnimVal.Value; // float fRight = (float)res.X2.AnimVal.Value; // float fTop = (float)res.Y1.AnimVal.Value; // float fBottom = (float)res.Y2.AnimVal.Value; // if (fTop == fBottom) // { // //mode = LinearGradientMode.Horizontal; // } // else // { // if (fLeft == fRight) // { // //mode = LinearGradientMode.Vertical; // } // else // { // if (fLeft < fRight) // { // //mode = LinearGradientMode.ForwardDiagonal; // brush.Transform = new RotateTransform(45, 0, 0); // //brush.EndPoint = new Point(x1, y1 + 1); // } // else // { // //mode = LinearGradientMode.BackwardDiagonal; // brush.Transform = new RotateTransform(-45); // } // } // } //} string colorInterpolation = res.GetPropertyValue("color-interpolation"); if (!String.IsNullOrEmpty(colorInterpolation)) { if (colorInterpolation == "linearRGB") { brush.ColorInterpolationMode = ColorInterpolationMode.ScRgbLinearInterpolation; } else { brush.ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation; } } return(brush); }
public override Image Apply(Image img) { if (string.IsNullOrEmpty(Text)) { return(img); } using (Font textFont = TextFont) { if (textFont == null || textFont.Size < 1) { return(img); } NameParser parser = new NameParser(NameParserType.Text) { Picture = img }; string parsedText = parser.Parse(Text); Size textSize = Helpers.MeasureText(parsedText, textFont); Size watermarkSize = new Size(textSize.Width + BackgroundPadding * 2, textSize.Height + BackgroundPadding * 2); Point watermarkPosition = Helpers.GetPosition(Placement, Offset, img.Size, watermarkSize); Rectangle watermarkRectangle = new Rectangle(watermarkPosition, watermarkSize); if (AutoHide && !new Rectangle(0, 0, img.Width, img.Height).Contains(watermarkRectangle)) { return(img); } using (Bitmap bmpWatermark = new Bitmap(watermarkSize.Width, watermarkSize.Height)) using (Graphics gWatermark = Graphics.FromImage(bmpWatermark)) { gWatermark.SetHighQuality(); if (DrawBackground) { Rectangle backgroundRect = new Rectangle(0, 0, watermarkSize.Width, watermarkSize.Height); Brush backgroundBrush = null; try { if (UseCustomGradient && Gradient != null && Gradient.IsValid) { backgroundBrush = new LinearGradientBrush(backgroundRect, Color.Transparent, Color.Transparent, Gradient.Type); ColorBlend colorBlend = new ColorBlend(); IEnumerable <GradientStop> gradient = Gradient.Colors.OrderBy(x => x.Location); colorBlend.Colors = gradient.Select(x => x.Color).ToArray(); colorBlend.Positions = gradient.Select(x => x.Location / 100).ToArray(); ((LinearGradientBrush)backgroundBrush).InterpolationColors = colorBlend; } else if (UseGradient) { backgroundBrush = new LinearGradientBrush(backgroundRect, BackgroundColor, BackgroundColor2, GradientType); } else { backgroundBrush = new SolidBrush(BackgroundColor); } using (Pen borderPen = new Pen(BorderColor)) { gWatermark.DrawRoundedRectangle(backgroundBrush, borderPen, backgroundRect, CornerRadius); } } finally { if (backgroundBrush != null) { backgroundBrush.Dispose(); } } } using (StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) { float centerX = bmpWatermark.Width / 2f; float centerY = bmpWatermark.Height / 2f; if (DrawTextShadow) { using (Brush textShadowBrush = new SolidBrush(TextShadowColor)) { gWatermark.DrawString(parsedText, textFont, textShadowBrush, centerX + TextShadowOffset.X, centerY + TextShadowOffset.Y, sf); } } using (Brush textBrush = new SolidBrush(TextColor)) { gWatermark.DrawString(parsedText, textFont, textBrush, centerX, centerY, sf); } } using (Graphics gResult = Graphics.FromImage(img)) { gResult.SetHighQuality(); gResult.DrawImage(bmpWatermark, watermarkRectangle); } } } return(img); }
/// <inheritdocs/> protected override void OnPaintOffScreen(PaintEventArgs e) { // Sort the satellites by signal if (_satellites == null) return; // Decide which collection to display List<Satellite> satellitesToDraw; List<Satellite> satellitesToRender; try { #if PocketPC if (LicenseManager.UsageMode == LicenseUsageMode.Designtime) { // SatellitesToRender = SatelliteCollection.Random(45); } else { if (_Satellites == null) return; SatellitesToRender = new List<Satellite>(); foreach (Satellite satellite in _Satellites) { // Don't draw if the satellite is stale if (!satellite.IsActive) continue; // Add it in SatellitesToRender.Add(satellite); } Thread.Sleep(0); } #else satellitesToRender = new List<Satellite>(); for (int index = 0; index < _satellites.Count; index++) { Satellite satellite = _satellites[index]; // Don't draw if the satellite is stale if (!satellite.IsActive && !DesignMode) continue; // Add it in satellitesToRender.Add(satellite); } #endif // Make a fake collection if necessary if (satellitesToRender.Count == 0) return; // Sort the list by PRN satellitesToRender.Sort(); // Calculate the width of each bar float totalWidth = (Width - _gapWidth) / (float)satellitesToRender.Count; float barWidth = totalWidth - _gapWidth; satellitesToDraw = new List<Satellite>(); // If if the bars are thin, see if we can exclude 0 dB satellites if (barWidth < 15) { // Display only the satellites with a > 0 dB signal foreach (Satellite satellite in satellitesToRender) { // Draw if the signal is > 0 if (!satellite.SignalToNoiseRatio.IsEmpty) satellitesToDraw.Add(satellite); } // If there's anything left, recalculate if (satellitesToDraw.Count == 0) return; // Recalculate bar/total width totalWidth = (Width - _gapWidth) / (float)satellitesToDraw.Count; barWidth = totalWidth - _gapWidth; } else { // Display only the satellites with a > 0 dB signal foreach (Satellite satellite in satellitesToRender) { // Draw if the signal is > 0 satellitesToDraw.Add(satellite); } } // Anything to do? if (satellitesToDraw.Count == 0) return; // Now draw each one float startX = _gapWidth; float startY = Height - e.Graphics.MeasureString("10", _pseudorandomNumberFont).Height; float scaleFactor = (startY - e.Graphics.MeasureString("10", _signalStrengthLabelFont).Height) / 50.0f; foreach (Satellite satellite in satellitesToDraw) { // Each icon is 30x30, so we'll translate it by half the distance if (satellite.IsFixed) { SizeF prnSize = e.Graphics.MeasureString(satellite.PseudorandomNumber.ToString(CultureInfo.CurrentCulture), _pseudorandomNumberFont); #if PocketPC e.Graphics.FillEllipse(pSatelliteFixBrush, (int)(StartX + (BarWidth * 0.5) - (PrnSize.Width * 0.5) - 4.0), (int)(StartY - 4), (int)(PrnSize.Width + 8), (int)(PrnSize.Height + 8)); #else using (SolidBrush fixBrush = new SolidBrush(Color.FromArgb(Math.Min(255, _fixedSatellites.Count * 20), _satelliteFixColor))) { e.Graphics.FillEllipse(fixBrush, (float)(startX + (barWidth * 0.5) - (prnSize.Width * 0.5) - 4.0), startY - 4, prnSize.Width + 8, prnSize.Height + 8); } #endif } startX += _gapWidth; startX += barWidth; } startX = _gapWidth; foreach (Satellite satellite in satellitesToDraw) { // If the signal is 0dB, skip it if (satellite.SignalToNoiseRatio.Value == 0) continue; // Keep drawing the satellite float satelliteY = startY - (Math.Min(satellite.SignalToNoiseRatio.Value, 50) * scaleFactor); #if PocketPC // Draw a rectangle for each satellite SolidBrush FillBrush = new SolidBrush(GetFillColor(satellite.SignalToNoiseRatio)); e.Graphics.FillRectangle(FillBrush, (int)StartX, (int)SatelliteY, (int)BarWidth, (int)(StartY - SatelliteY)); FillBrush.Dispose(); Pen FillPen = new Pen(GetOutlineColor(satellite.SignalToNoiseRatio)); e.Graphics.DrawRectangle(FillPen, (int)StartX, (int)SatelliteY, (int)BarWidth, (int)(StartY - SatelliteY)); FillPen.Dispose(); #else // Get the fill color Color barColor = GetFillColor(satellite.SignalToNoiseRatio); float barHue = barColor.GetHue(); // Create gradients for a glass effect Color topTopColor = ColorFromAhsb(255, barHue, 0.2958f, 0.7292f); Color topBottomColor = ColorFromAhsb(255, barHue, 0.5875f, 0.35f); Color bottomTopColor = ColorFromAhsb(255, barHue, 0.7458f, 0.2f); Color bottomBottomColor = ColorFromAhsb(255, barHue, 0.6f, 0.4042f); // Draw a rectangle for each satellite RectangleF topRect = new RectangleF(startX, satelliteY, barWidth, Convert.ToSingle((startY - satelliteY) * 0.5)); using (Brush topFillBrush = new LinearGradientBrush(topRect, topTopColor, topBottomColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(topFillBrush, topRect); } // Draw a rectangle for each satellite RectangleF bottomRect = new RectangleF(startX, satelliteY + topRect.Height, barWidth, topRect.Height); using (Brush bottomFillBrush = new LinearGradientBrush(bottomRect, bottomTopColor, bottomBottomColor, LinearGradientMode.Vertical)) { e.Graphics.FillRectangle(bottomFillBrush, bottomRect); } using (Pen fillPen = new Pen(GetOutlineColor(satellite.SignalToNoiseRatio), 1.0f)) { e.Graphics.DrawRectangle(fillPen, startX, satelliteY, barWidth, startY - satelliteY); } #endif string prnString = satellite.PseudorandomNumber.ToString(CultureInfo.CurrentCulture); SizeF prnSize = e.Graphics.MeasureString(prnString, _pseudorandomNumberFont); e.Graphics.DrawString(prnString, _pseudorandomNumberFont, _pseudorandomNumberBrush, (float)(startX + (barWidth * 0.5) - (prnSize.Width * 0.5)), startY); string renderString = satellite.SignalToNoiseRatio.ToString("0 dB", CultureInfo.CurrentCulture); SizeF signalSize = e.Graphics.MeasureString(renderString, _signalStrengthLabelFont); if (signalSize.Width > barWidth) { renderString = satellite.SignalToNoiseRatio.ToString("0 dB", CultureInfo.CurrentCulture).Replace(" dB", string.Empty); signalSize = e.Graphics.MeasureString(renderString, _signalStrengthLabelFont); } e.Graphics.DrawString(renderString, _signalStrengthLabelFont, _signalStrengthLabelBrush, (float)(startX + (barWidth * 0.5) - (signalSize.Width * 0.5)), satelliteY - signalSize.Height); startX += _gapWidth; startX += barWidth; } } catch { } }
/// <summary> /// Draws the colorslider control using passed colors. /// </summary> /// <param name="e">The <see cref="T:System.Windows.Forms.PaintEventArgs"/> instance containing the event data.</param> /// <param name="thumbOuterColorPaint">The thumb outer color paint.</param> /// <param name="thumbInnerColorPaint">The thumb inner color paint.</param> /// <param name="thumbPenColorPaint">The thumb pen color paint.</param> /// <param name="barOuterColorPaint">The bar outer color paint.</param> /// <param name="barInnerColorPaint">The bar inner color paint.</param> /// <param name="barPenColorPaint">The bar pen color paint.</param> /// <param name="elapsedOuterColorPaint">The elapsed outer color paint.</param> /// <param name="elapsedInnerColorPaint">The elapsed inner color paint.</param> private void DrawColorSlider(PaintEventArgs e, Color thumbOuterColorPaint, Color thumbInnerColorPaint, Color thumbPenColorPaint, Color barOuterColorPaint, Color barInnerColorPaint, Color barPenColorPaint, Color elapsedOuterColorPaint, Color elapsedInnerColorPaint) { try { //set up thumbRect aproprietly if (barOrientation == Orientation.Horizontal) { int TrackX = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(TrackX, 1, thumbSize - 1, ClientRectangle.Height - 3); } else { int TrackY = (((trackerValue - barMinimum) * (ClientRectangle.Height - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(1, TrackY, ClientRectangle.Width - 3, thumbSize - 1); } //adjust drawing rects barRect = ClientRectangle; thumbHalfRect = thumbRect; LinearGradientMode gradientOrientation; if (barOrientation == Orientation.Horizontal) { barRect.Inflate(-1, -barRect.Height / 3); barHalfRect = barRect; barHalfRect.Height /= 2; gradientOrientation = LinearGradientMode.Vertical; thumbHalfRect.Height /= 2; elapsedRect = barRect; elapsedRect.Width = thumbRect.Left + thumbSize / 2; } else { barRect.Inflate(-barRect.Width / 3, -1); barHalfRect = barRect; barHalfRect.Width /= 2; gradientOrientation = LinearGradientMode.Horizontal; thumbHalfRect.Width /= 2; elapsedRect = barRect; elapsedRect.Height = thumbRect.Top + thumbSize / 2; } //get thumb shape path GraphicsPath thumbPath; if (thumbCustomShape == null) { thumbPath = CreateRoundRectPath(thumbRect, thumbRoundRectSize); } else { thumbPath = thumbCustomShape; Matrix m = new Matrix(); m.Translate(thumbRect.Left - thumbPath.GetBounds().Left, thumbRect.Top - thumbPath.GetBounds().Top); thumbPath.Transform(m); } //draw bar using ( LinearGradientBrush lgbBar = new LinearGradientBrush(barHalfRect, barOuterColorPaint, barInnerColorPaint, gradientOrientation) ) { lgbBar.WrapMode = WrapMode.TileFlipXY; e.Graphics.FillRectangle(lgbBar, barRect); //draw elapsed bar using ( LinearGradientBrush lgbElapsed = new LinearGradientBrush(barHalfRect, elapsedOuterColorPaint, elapsedInnerColorPaint, gradientOrientation)) { lgbElapsed.WrapMode = WrapMode.TileFlipXY; if (Capture && drawSemitransparentThumb) { Region elapsedReg = new Region(elapsedRect); elapsedReg.Exclude(thumbPath); e.Graphics.FillRegion(lgbElapsed, elapsedReg); } else { e.Graphics.FillRectangle(lgbElapsed, elapsedRect); } } //draw bar band using (Pen barPen = new Pen(barPenColorPaint, 0.5f)) { e.Graphics.DrawRectangle(barPen, barRect); } } //draw thumb Color newthumbOuterColorPaint = thumbOuterColorPaint, newthumbInnerColorPaint = thumbInnerColorPaint; if (Capture && drawSemitransparentThumb) { newthumbOuterColorPaint = Color.FromArgb(175, thumbOuterColorPaint); newthumbInnerColorPaint = Color.FromArgb(175, thumbInnerColorPaint); } using ( LinearGradientBrush lgbThumb = new LinearGradientBrush(thumbHalfRect, newthumbOuterColorPaint, newthumbInnerColorPaint, gradientOrientation)) { lgbThumb.WrapMode = WrapMode.TileFlipXY; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.FillPath(lgbThumb, thumbPath); //draw thumb band Color newThumbPenColor = thumbPenColorPaint; if (mouseEffects && (Capture || mouseInThumbRegion)) { newThumbPenColor = ControlPaint.Dark(newThumbPenColor); } using (Pen thumbPen = new Pen(newThumbPenColor)) { e.Graphics.DrawPath(thumbPen, thumbPath); } //gp.Dispose(); /*if (Capture || mouseInThumbRegion) * using (LinearGradientBrush lgbThumb2 = new LinearGradientBrush(thumbHalfRect, Color.FromArgb(150, Color.Blue), Color.Transparent, gradientOrientation)) * { * lgbThumb2.WrapMode = WrapMode.TileFlipXY; * e.Graphics.FillPath(lgbThumb2, gp); * }*/ } //draw focusing rectangle if (Focused & drawFocusRectangle) { using (Pen p = new Pen(Color.FromArgb(200, barPenColorPaint))) { p.DashStyle = DashStyle.Dot; Rectangle r = ClientRectangle; r.Width -= 2; r.Height--; r.X++; //ControlPaint.DrawFocusRectangle(e.Graphics, r); using (GraphicsPath gpBorder = CreateRoundRectPath(r, borderRoundRectSize)) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; e.Graphics.DrawPath(p, gpBorder); } } } } catch (Exception Err) { //Console.WriteLine("DrawBackGround Error in " + Name + ":" + Err.Message); } finally { } }
private void OnDrawTabPage(Graphics g, FATabStripItem currentItem) { bool isFirstTab = Items.IndexOf(currentItem) == 0; Font currentFont = Font; if (currentItem == SelectedItem) { currentFont = new Font(Font, FontStyle.Bold); } SizeF textSize = g.MeasureString(currentItem.Title, currentFont, new SizeF(200, 10), sf); textSize.Width += 20; RectangleF buttonRect = currentItem.StripRect; GraphicsPath path = new GraphicsPath(); LinearGradientBrush brush; int mtop = 3; #region Draw Not Right-To-Left Tab if (RightToLeft == RightToLeft.No) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Left - 10, buttonRect.Bottom - 1, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 4); } else { path.AddLine(buttonRect.Left, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Left, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Left + (buttonRect.Height / 2) - 4, mtop + 3); } path.AddLine(buttonRect.Left + (buttonRect.Height / 2) + 2, mtop, buttonRect.Right - 3, mtop); path.AddLine(buttonRect.Right, mtop + 2, buttonRect.Right, buttonRect.Bottom - 1); path.AddLine(buttonRect.Right - 4, buttonRect.Bottom - 1, buttonRect.Left, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Left - 9, buttonRect.Height + 2, buttonRect.Left + buttonRect.Width - 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + buttonRect.Height - 4, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 3); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 4; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { //textRect.Y -= 2; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } } #endregion #region Draw Right-To-Left Tab if (RightToLeft == RightToLeft.Yes) { if (currentItem == SelectedItem || isFirstTab) { path.AddLine(buttonRect.Right + 10, buttonRect.Bottom - 1, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 4); } else { path.AddLine(buttonRect.Right, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 2); path.AddLine(buttonRect.Right, buttonRect.Bottom - (buttonRect.Height / 2) - 3, buttonRect.Right - (buttonRect.Height / 2) + 4, mtop + 3); } path.AddLine(buttonRect.Right - (buttonRect.Height / 2) - 2, mtop, buttonRect.Left + 3, mtop); path.AddLine(buttonRect.Left, mtop + 2, buttonRect.Left, buttonRect.Bottom - 1); path.AddLine(buttonRect.Left + 4, buttonRect.Bottom - 1, buttonRect.Right, buttonRect.Bottom - 1); path.CloseFigure(); if (currentItem == SelectedItem) { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Window, LinearGradientMode.Vertical); } else { brush = new LinearGradientBrush(buttonRect, SystemColors.ControlLightLight, SystemColors.Control, LinearGradientMode.Vertical); } g.FillPath(brush, path); g.DrawPath(SystemPens.ControlDark, path); if (currentItem == SelectedItem) { g.DrawLine(new Pen(brush), buttonRect.Right + 9, buttonRect.Height + 2, buttonRect.Right - buttonRect.Width + 1, buttonRect.Height + 2); } PointF textLoc = new PointF(buttonRect.Left + 2, buttonRect.Top + (buttonRect.Height / 2) - (textSize.Height / 2) - 2); RectangleF textRect = buttonRect; textRect.Location = textLoc; textRect.Width = buttonRect.Width - (textRect.Left - buttonRect.Left) - 10; textRect.Height = textSize.Height + currentFont.Size / 2; if (currentItem == SelectedItem) { textRect.Y -= 1; g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } else { g.DrawString(currentItem.Title, currentFont, new SolidBrush(ForeColor), textRect, sf); } //g.FillRectangle(Brushes.Red, textRect); } #endregion currentItem.IsDrawn = true; }
private void panel1_Paint(object sender, PaintEventArgs e) { LinearGradientBrush brush = new LinearGradientBrush(panel1.ClientRectangle, Color.LightSkyBlue, Color.White, LinearGradientMode.Vertical); e.Graphics.FillRectangle(brush, panel1.ClientRectangle); }
private void Form1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; Color foreColor = Color.Black; Color backColor1 = Color.Tomato; Color backColor2 = Color.Yellow; Point grdntPt1 = new Point { X = Wide / 2, Y = High }; Point grdntPt2 = new Point { X = Wide / 2, Y = 0 }; Pen forePen = new Pen(foreColor, 2); Brush foreBrush = new SolidBrush(foreColor); Pen backPen = new Pen(Color.Transparent, 1); Brush backBrush1 = new LinearGradientBrush(grdntPt1, grdntPt2, backColor1, backColor2); Brush backBrush2 = new SolidBrush(Color.Transparent); Brush backBrush3 = new SolidBrush(Color.Goldenrod); int[] coordArr; //Background color //g.FillRectangle(backBrush1, 0, 0, 676, 611); //Gradient red to yellow g.FillRectangle(backBrush3, 0, 0, 676, 611); //Goldenrod //Nose //nose coordArr = new int[30] { 338, 334, 335, 334, 335, 318, 332, 306, 325, 298, 309, 290, 303, 289, 301, 286, 300, 281, 307, 283, 312, 280, 320, 275, 328, 277, 334, 280, 338, 280 }; symHorizCurve(g, forePen, foreBrush, coordArr); //nose lines coordArr = new int[16] { 299, 273, 296, 267, 299, 260, 312, 241, 315, 234, 313, 247, 306, 260, 299, 273 }; symHorizCurve(g, forePen, foreBrush, coordArr); //Eyes and surrounding //eyes coordArr = new int[34] { 257, 200, 263, 202, 272, 196, 277, 195, 287, 197, 295, 203, 299, 208, 300, 220, 308, 233, 298, 220, 294, 211, 286, 207, 281, 205, 274, 208, 272, 215, 267, 207, 257, 200 }; symHorizCurve(g, forePen, foreBrush, coordArr); //pupils coordArr = new int[6] { 285, 207, 285, 218, 287, 208 }; symHorizCurve(g, forePen, foreBrush, coordArr); //upper nose lines between eyes coordArr = new int[34] { 313, 182, 315, 185, 312, 194, 311, 196, 309, 200, 311, 205, 316, 208, 316, 218, 316, 222, 315, 216, 312, 211, 308, 208, 302, 202, 306, 194, 309, 189, 312, 183, 313, 178 }; symHorizCurve(g, forePen, foreBrush, coordArr); //under eyes coordArr = new int[16] { 302, 237, 289, 233, 267, 224, 261, 211, 273, 221, 286, 224, 293, 229, 302, 237 }; symHorizCurve(g, forePen, foreBrush, coordArr); //cheekbones coordArr = new int[16] { 273, 280, 260, 273, 252, 260, 250, 243, 253, 248, 257, 255, 272, 263, 273, 280 }; symHorizCurve(g, forePen, foreBrush, coordArr); //cheek skin coordArr = new int[12] { 273, 313, 273, 300, 277, 290, 286, 283, 277, 298, 273, 313 }; symHorizCurve(g, forePen, foreBrush, coordArr); //forhead line (center) coordArr = new int[10] { 338, 183, 335, 164, 338, 143, 341, 164, 338, 183 }; symHorizCurve(g, forePen, foreBrush, coordArr); //Ears and surrounding //hair under ear coordArr = new int[22] { 208, 235, 219, 221, 222, 208, 229, 190, 248, 181, 247, 189, 247, 195, 237, 204, 231, 220, 222, 229, 208, 235 }; symHorizCurve(g, forePen, foreBrush, coordArr); //inside of ears coordArr = new int[22] { 221, 169, 211, 156, 209, 143, 221, 131, 234, 133, 247, 140, 260, 146, 247, 159, 254, 159, 248, 170, 221, 169 }; symHorizCurve(g, forePen, foreBrush, coordArr); //ear tabs coordArr = new int[8] { 221, 169, 209, 176, 220, 168, 221, 169 }; symHorizCurve(g, forePen, foreBrush, coordArr); //top of ears coordArr = new int[38] { 215, 170, 204, 156, 200, 143, 204, 130, 221, 118, 247, 120, 267, 127, 286, 120, 260, 117, 273, 111, 286, 111, 308, 117, 283, 127, 270, 143, 234, 127, 211, 132, 205, 143, 208, 156, 215, 170 }; symHorizCurve(g, forePen, foreBrush, coordArr); //center tuft of hair --- a single asymmetrical shape coordArr = new int[40] { 338, 130, 332, 120, 319, 117, 306, 107, 287, 98, 312, 101, 332, 113, 328, 91, 321, 78, 306, 65, 325, 72, 338, 81, 348, 104, 346, 114, 352, 101, 358, 85, 364, 104, 364, 117, 350, 120, 338, 130 }; Point[] ptArr = new Point[38 / 2]; getPointArray(coordArr, out ptArr); g.DrawCurve(forePen, ptArr); g.FillClosedCurve(foreBrush, ptArr); //Beard and chin //beard --- s single asymmetrical shape coordArr = new int[148] { 244, 211, 230, 242, 222, 248, 208, 280, 212, 312, 221, 338, 221, 325, 218, 312, 224, 280, 224, 293, 241, 319, 247, 351, 247, 377, 254, 390, 251, 384, 260, 358, 273, 384, 276, 387, 276, 390, 280, 419, 304, 442, 319, 470, 320, 460, 309, 436, 341, 460, 351, 507, 359, 481, 361, 455, 371, 437, 390, 416, 384, 436, 385, 443, 395, 429, 410, 410, 413, 390, 410, 371, 423, 351, 429, 377, 436, 364, 437, 351, 436, 338, 442, 312, 450, 299, 454, 287, 452, 280, 456, 299, 454, 325, 455, 341, 460, 325, 468, 312, 468, 299, 469, 286, 460, 260, 448, 241, 436, 217, 442, 247, 439, 273, 435, 292, 427, 299, 405, 323, 404, 344, 392, 352, 386, 352, 338, 334, 289, 352, 283, 352, 273, 343, 271, 338, 271, 325, 248, 299, 240, 292, 234, 273, 235, 234, 243, 211 }; ptArr = new Point[148 / 2]; getPointArray(coordArr, out ptArr); g.DrawCurve(forePen, ptArr); g.FillClosedCurve(foreBrush, ptArr); //chin in middle of beard coordArr = new int[18] { 338, 391, 312, 390, 299, 382, 293, 371, 299, 354, 312, 348, 328, 344, 338, 351, 338, 391 }; //symHorizCurve(g, backPen, backBrush1, coordArr); // With gradient red to yellow background symHorizCurve(g, backPen, backBrush3, coordArr); // With goldenrod background // Mane Sections //mane section 1 coordArr = new int[46] { 117, 416, 104, 377, 98, 338, 97, 325, 98, 312, 104, 286, 116, 260, 131, 235, 144, 221, 160, 209, 156, 221, 140, 247, 127, 273, 117, 299, 114, 325, 113, 332, 114, 338, 117, 364, 130, 338, 146, 322, 143, 342, 140, 364, 117, 416 }; symHorizCurve(g, forePen, foreBrush, coordArr); //mane section 2 coordArr = new int[28] { 114, 263, 117, 234, 127, 195, 137, 169, 150, 150, 170, 134, 182, 129, 195, 129, 177, 143, 164, 154, 146, 182, 137, 208, 130, 247, 114, 263 }; symHorizCurve(g, forePen, foreBrush, coordArr); //mane section 3 coordArr = new int[42] { 142, 169, 143, 155, 153, 130, 166, 104, 174, 92, 187, 75, 210, 60, 220, 57, 234, 55, 247, 56, 280, 70, 260, 66, 247, 65, 234, 67, 221, 73, 208, 80, 195, 92, 182, 108, 169, 130, 163, 146, 142, 169 }; symHorizCurve(g, forePen, foreBrush, coordArr); //mane section 4 coordArr = new int[36] { 198, 62, 221, 46, 247, 29, 289, 26, 286, 25, 312, 27, 325, 30, 338, 36, 338, 55, 325, 49, 312, 42, 299, 40, 286, 39, 273, 40, 260, 43, 247, 49, 234, 55, 198, 62 }; symHorizCurve(g, forePen, foreBrush, coordArr); //mane section 5 coordArr = new int[30] { 202, 507, 182, 494, 169, 483, 156, 472, 143, 456, 137, 446, 130, 429, 124, 403, 142, 361, 140, 377, 143, 416, 156, 446, 173, 465, 195, 478, 202, 507 }; symHorizCurve(g, forePen, foreBrush, coordArr); //mane section 6 coordArr = new int[40] { 260, 540, 247, 532, 234, 520, 221, 512, 208, 501, 195, 488, 182, 475, 169, 455, 165, 429, 168, 416, 172, 403, 176, 416, 179, 429, 185, 442, 192, 455, 202, 468, 210, 481, 231, 494, 244, 507, 260, 540 }; symHorizCurve(g, forePen, foreBrush, coordArr); //bottom of mane --- a single asymmetrical shape coordArr = new int[130] { 260, 540, 244, 520, 234, 507, 235, 494, 237, 481, 241, 468, 247, 455, 260, 443, 260, 468, 264, 481, 270, 494, 279, 507, 293, 520, 296, 512, 299, 502, 312, 514, 317, 520, 324, 533, 326, 546, 328, 559, 328, 562, 338, 559, 351, 553, 364, 546, 374, 533, 380, 520, 390, 501, 392, 514, 390, 527, 403, 514, 413, 494, 417, 481, 417, 468, 417, 445, 429, 463, 432, 468, 440, 481, 442, 494, 441, 507, 416, 540, 423, 520, 422, 507, 416, 520, 406, 533, 393, 546, 374, 559, 348, 572, 312, 585, 313, 559, 312, 546, 302, 533, 304, 546, 296, 560, 296, 553, 293, 545, 286, 538, 281, 533, 273, 527, 267, 520, 260, 507, 252, 488, 248, 494, 250, 507, 253, 520, 260, 540 }; ptArr = new Point[65 / 2]; getPointArray(coordArr, out ptArr); g.DrawCurve(forePen, ptArr); g.FillClosedCurve(foreBrush, ptArr); //crossHairs(g, 291, 520); }
private void pictureBox_Paint(object sender, PaintEventArgs e) { if (selectedTool != "Pencil") { tempDraw = (Bitmap)snapshot.Clone(); } Graphics g = Graphics.FromImage(tempDraw); g.SmoothingMode = smooth; Pen myPen = new Pen(foreColor, lineWidth); switch (selectedTool) { case "Line": if (tempDraw != null) { g.DrawLine(myPen, x1, y1, x2, y2); } break; case "Rectangle": if (tempDraw != null) { g.DrawRectangle(myPen, x1, y1, x2 - x1, y2 - y1); } break; case "Pencil": if (tempDraw != null) { g.DrawLine(myPen, x1, y1, x2, y2); x1 = x2; y1 = y2; } break; case "GradientBrush": if (tempDraw != null) { if ((x2 > x1) && (y2 > y1)) { Brush linearGradientBrush = new LinearGradientBrush(new Rectangle(x1, y1, x2 - x1, y2 - y1), foreColor, Color.White, 45); g.FillRectangle(linearGradientBrush, new Rectangle(x1, y1, x2 - x1, y2 - y1)); linearGradientBrush.Dispose(); } } break; case "Oval": if (tempDraw != null) { g.DrawEllipse(myPen, x1, y1, x2 - x1, y2 - y1); } break; case "Circle": if (tempDraw != null) { g.DrawEllipse(myPen, x1, y1, x2 - x1, x2 - x1); } break; default: break; } myPen.Dispose(); e.Graphics.DrawImageUnscaled(tempDraw, 0, 0); g.Dispose(); }
protected override void OnMouseMove(MouseEventArgs e) { if (!DesignMode) { Graphics g = CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; for (int nIndex = 0; nIndex < this.TabCount; nIndex++) { RectangleF tabTextArea = (RectangleF)this.GetTabRect(nIndex); tabTextArea = new RectangleF(tabTextArea.X + tabTextArea.Width - 22, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); Point pt = new Point(e.X, e.Y); if (tabTextArea.Contains(pt)) { using ( LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 252, 193, 183), Color.FromArgb(255, 252, 193, 183), Color.FromArgb(255, 210, 35, 2), Color.FromArgb(255, 210, 35, 2) }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea); g.DrawRectangle(Pens.White, tabTextArea.X + 2, 6, tabTextArea.Height - 3, tabTextArea.Height - 4); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + 6, 9, tabTextArea.X + 15, 17); g.DrawLine(pen, tabTextArea.X + 6, 17, tabTextArea.X + 15, 9); } } } else { if (nIndex != SelectedIndex) { using ( LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea); g.DrawRectangle(Pens.White, tabTextArea.X + 2, 6, tabTextArea.Height - 3, tabTextArea.Height - 4); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + 6, 9, tabTextArea.X + 15, 17); g.DrawLine(pen, tabTextArea.X + 6, 17, tabTextArea.X + 15, 9); } } } } if (CanDrawMenuButton(nIndex)) { RectangleF tabMenuArea = (RectangleF)this.GetTabRect(nIndex); tabMenuArea = new RectangleF(tabMenuArea.X + tabMenuArea.Width - 43, 4, tabMenuArea.Height - 3, tabMenuArea.Height - 5); pt = new Point(e.X, e.Y); if (tabMenuArea.Contains(pt)) { using ( LinearGradientBrush _Brush = new LinearGradientBrush(tabMenuArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 170, 213, 255), Color.FromArgb(255, 170, 213, 255), Color.FromArgb(255, 44, 157, 250), Color.FromArgb(255, 44, 157, 250) }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabMenuArea); g.DrawRectangle(Pens.White, tabMenuArea.X + 2, 6, tabMenuArea.Height - 2, tabMenuArea.Height - 4); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabMenuArea.X + 7, 11, tabMenuArea.X + 10, 16); g.DrawLine(pen, tabMenuArea.X + 10, 16, tabMenuArea.X + 13, 11); } } } else { if (nIndex != SelectedIndex) { using ( LinearGradientBrush _Brush = new LinearGradientBrush(tabMenuArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabMenuArea); g.DrawRectangle(Pens.White, tabMenuArea.X + 2, 6, tabMenuArea.Height - 2, tabMenuArea.Height - 4); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabMenuArea.X + 7, 11, tabMenuArea.X + 10, 16); g.DrawLine(pen, tabMenuArea.X + 10, 16, tabMenuArea.X + 13, 11); } } } } } } g.Dispose(); } }
protected override void OnClientSizeChanged(EventArgs e) { base.OnClientSizeChanged(e); gb = new LinearGradientBrush(new Rectangle(0, 0, this.Width, this.Height), Color.SteelBlue, Color.DarkSlateGray, 90f); }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //content border Rectangle rectCont = rectContent; rectCont.X += 1; rectCont.Y += 1; rectCont.Width -= 3; rectCont.Height -= 3; GraphicsPath pathContentBorder = CreateRoundRectangle(rectCont, Radius.TopLeft, Radius.TopRight, Radius.BottomRight, Radius.BottomLeft); //button border Rectangle rectButton = rectBtn; rectButton.X += 1; rectButton.Y += 1; rectButton.Width -= 3; rectButton.Height -= 3; GraphicsPath pathBtnBorder = CreateRoundRectangle(rectButton, 0, Radius.TopRight, Radius.BottomRight, 0); //outer border Rectangle rectOuter = rectContent; rectOuter.Width -= 1; rectOuter.Height -= 1; GraphicsPath pathOuterBorder = CreateRoundRectangle(rectOuter, Radius.TopLeft, Radius.TopRight, Radius.BottomRight, Radius.BottomLeft); //inner border Rectangle rectInner = rectContent; rectInner.X += 1; rectInner.Y += 1; rectInner.Width -= 3; rectInner.Height -= 3; GraphicsPath pathInnerBorder = CreateRoundRectangle(rectInner, Radius.TopLeft, Radius.TopRight, Radius.BottomRight, Radius.BottomLeft); //brushes and pens Color foreColor = Color.FromArgb(IsDroppedDown ? 100 : 50, ForeColor); Brush brInnerBrush = new LinearGradientBrush( new Rectangle(rectInner.X, rectInner.Y, rectInner.Width, rectInner.Height + 1), Color.FromArgb((hovered || IsDroppedDown || Focused) ? 200 : 100, ForeColor), Color.Transparent, LinearGradientMode.Vertical); Brush brBackground; if (this.DropDownStyle == ComboBoxStyle.DropDownList) { brBackground = new LinearGradientBrush(pathInnerBorder.GetBounds(), BackColor, hovered ? Color.FromArgb(100, SystemColors.HotTrack) : foreColor, LinearGradientMode.Vertical); } else { brBackground = new SolidBrush(BackColor); } Pen penInnerBorder = new Pen(brInnerBrush, 0); LinearGradientBrush brButtonLeft = new LinearGradientBrush(rectBtn, BackColor, ForeColor, LinearGradientMode.Vertical); ColorBlend blend = new ColorBlend(); blend.Colors = new Color[] { Color.Transparent, foreColor, Color.Transparent }; blend.Positions = new float[] { 0.0f, 0.5f, 1.0f }; brButtonLeft.InterpolationColors = blend; Pen penLeftButton = new Pen(brButtonLeft, 0); Brush brButton = new LinearGradientBrush(pathBtnBorder.GetBounds(), BackColor, foreColor, LinearGradientMode.Vertical); //draw e.Graphics.FillPath(brBackground, pathContentBorder); if (DropDownStyle != ComboBoxStyle.DropDownList) { e.Graphics.FillPath(brButton, pathBtnBorder); } Color outerBorderColor = GetOuterBorderColor(); if (outerBorderColor.IsSystemColor) { Pen penOuterBorder = SystemPens.FromSystemColor(outerBorderColor); e.Graphics.DrawPath(penOuterBorder, pathOuterBorder); } else { using (Pen penOuterBorder = new Pen(outerBorderColor)) e.Graphics.DrawPath(penOuterBorder, pathOuterBorder); } e.Graphics.DrawPath(penInnerBorder, pathInnerBorder); e.Graphics.DrawLine(penLeftButton, rectBtn.Left + 1, rectInner.Top + 1, rectBtn.Left + 1, rectInner.Bottom - 1); //Glimph Rectangle rectGlimph = rectButton; rectButton.Width -= 4; e.Graphics.TranslateTransform(rectGlimph.Left + rectGlimph.Width / 2.0f, rectGlimph.Top + rectGlimph.Height / 2.0f); GraphicsPath path = new GraphicsPath(); PointF[] points = new PointF[3]; points[0] = new PointF(-6 / 2.0f, -3 / 2.0f); points[1] = new PointF(6 / 2.0f, -3 / 2.0f); points[2] = new PointF(0, 6 / 2.0f); path.AddLine(points[0], points[1]); path.AddLine(points[1], points[2]); path.CloseFigure(); e.Graphics.RotateTransform(0); SolidBrush br = new SolidBrush(Enabled ? Color.Gray : Color.Gainsboro); e.Graphics.FillPath(br, path); e.Graphics.ResetTransform(); br.Dispose(); path.Dispose(); // image if (ImageList != null) { int idx = GetImageKey(SelectedIndex); if (idx >= 0) { this.ImageList.Draw(e.Graphics, _textBox.Bounds.Left - this.ImageList.ImageSize.Width - 5, rectContent.Y + 2, idx); } } //text if (DropDownStyle == ComboBoxStyle.DropDownList) { StringFormat sf = new StringFormat(StringFormatFlags.NoWrap); sf.Alignment = StringAlignment.Near; Rectangle rectText = _textBox.Bounds; rectText.Offset(-3, 0); SolidBrush foreBrush = new SolidBrush(ForeColor); if (Enabled) { e.Graphics.DrawString(_textBox.Text, this.Font, foreBrush, rectText); } else { ControlPaint.DrawStringDisabled(e.Graphics, _textBox.Text, Font, BackColor, rectText, sf); } } /* * Dim foreBrush As SolidBrush = New SolidBrush(color) * If (enabled) Then * g.DrawString(text, font, foreBrush, rect, sf) * Else * ControlPaint.DrawStringDisabled(g, text, font, backColor, _ * rect, sf) * End If * foreBrush.Dispose()*/ pathContentBorder.Dispose(); pathOuterBorder.Dispose(); pathInnerBorder.Dispose(); pathBtnBorder.Dispose(); penInnerBorder.Dispose(); penLeftButton.Dispose(); brBackground.Dispose(); brInnerBrush.Dispose(); brButtonLeft.Dispose(); brButton.Dispose(); }
/// <summary> /// Draws the colorslider control using passed colors. /// </summary> private void DrawColorSlider(Graphics g) { try { //set up thumbRect aproprietly int track = (((trackerValue - barMinimum) * (ClientRectangle.Width - thumbSize)) / (barMaximum - barMinimum)); thumbRect = new Rectangle(track, this.Height / 2 - 3, thumbSize - 1, 10); //adjust drawing rects barRect = new Rectangle(1, this.Height / 2, this.Width - 2, 5); //get thumb shape path GraphicsPath thumbPath = new GraphicsPath(); thumbPath.AddPolygon(new Point[] { new Point(thumbRect.Left, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Top), new Point(thumbRect.Right, thumbRect.Bottom - 4), new Point(thumbRect.Left + thumbRect.Width / 2, thumbRect.Bottom), new Point(thumbRect.Left, thumbRect.Bottom - 4) }); Brush sliderLGBrushH = new LinearGradientBrush(barRect, WColorS_Dark.ColorGray122, WColorS_Dark.ColorGray107, LinearGradientMode.Horizontal); Brush barFill = (criticalPercent > 0 && trackerValue > criticalPercent) ? Brushes.Peru : Brushes.Green; //draw bar { // Background gradient g.FillRectangle(sliderLGBrushH, barRect); // Background fill g.FillRectangle(WColorS_Dark.SliderBorderBrush, barRect.Left + 1, barRect.Top, barRect.Width - 2, barRect.Height - 1); // Bar fill g.FillRectangle(WColorS_Dark.SliderFillBrush, barRect.Left + 2, barRect.Top + 1, barRect.Width - 4, barRect.Height - 3); // Elapsed bar fill g.FillRectangle(barFill, barRect.Left + 2, barRect.Top + 1, thumbRect.Left + thumbSize / 2 - 2, barRect.Height - 3); //draw bar band //g.DrawRectangle(barPen, barRect); } sliderLGBrushH.Dispose(); //draw thumb Brush brushInner = new LinearGradientBrush(thumbRect, Color.FromArgb(111, 111, 111), Color.FromArgb(80, 80, 80), LinearGradientMode.Vertical); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(brushInner, thumbPath); g.DrawPath(Pens.Black, thumbPath); brushInner.Dispose(); //draw thumb band //Color newThumbPenColor = thumbPenColorPaint; //if (mouseEffects && (Capture || mouseInThumbRegion)) // newThumbPenColor = ControlPaint.Dark(newThumbPenColor); //g.DrawPath(thumbPen, thumbPath); } catch (Exception) { } finally { } }
private void DrawBackground(Graphics g, System.Drawing.RectangleF rect, StyleInfo si) { LinearGradientBrush linGrBrush = null; SolidBrush sb = null; HatchBrush hb = null; try { if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None && !si.BackgroundGradientEndColor.IsEmpty && !si.BackgroundColor.IsEmpty) { Color c = si.BackgroundColor; Color ec = si.BackgroundGradientEndColor; switch (si.BackgroundGradientType) { case BackgroundGradientTypeEnum.LeftRight: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); break; case BackgroundGradientTypeEnum.TopBottom: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); break; case BackgroundGradientTypeEnum.Center: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); break; case BackgroundGradientTypeEnum.DiagonalLeft: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal); break; case BackgroundGradientTypeEnum.DiagonalRight: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal); break; case BackgroundGradientTypeEnum.HorizontalCenter: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal); break; case BackgroundGradientTypeEnum.VerticalCenter: linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical); break; default: break; } } if (si.PatternType != patternTypeEnum.None) { switch (si.PatternType) { case patternTypeEnum.BackwardDiagonal: hb = new HatchBrush(HatchStyle.BackwardDiagonal, si.Color, si.BackgroundColor); break; case patternTypeEnum.CheckerBoard: hb = new HatchBrush(HatchStyle.LargeCheckerBoard, si.Color, si.BackgroundColor); break; case patternTypeEnum.Cross: hb = new HatchBrush(HatchStyle.Cross, si.Color, si.BackgroundColor); break; case patternTypeEnum.DarkDownwardDiagonal: hb = new HatchBrush(HatchStyle.DarkDownwardDiagonal, si.Color, si.BackgroundColor); break; case patternTypeEnum.DarkHorizontal: hb = new HatchBrush(HatchStyle.DarkHorizontal, si.Color, si.BackgroundColor); break; case patternTypeEnum.DiagonalBrick: hb = new HatchBrush(HatchStyle.DiagonalBrick, si.Color, si.BackgroundColor); break; case patternTypeEnum.HorizontalBrick: hb = new HatchBrush(HatchStyle.HorizontalBrick, si.Color, si.BackgroundColor); break; case patternTypeEnum.LargeConfetti: hb = new HatchBrush(HatchStyle.LargeConfetti, si.Color, si.BackgroundColor); break; case patternTypeEnum.OutlinedDiamond: hb = new HatchBrush(HatchStyle.OutlinedDiamond, si.Color, si.BackgroundColor); break; case patternTypeEnum.SmallConfetti: hb = new HatchBrush(HatchStyle.SmallConfetti, si.Color, si.BackgroundColor); break; case patternTypeEnum.SolidDiamond: hb = new HatchBrush(HatchStyle.SolidDiamond, si.Color, si.BackgroundColor); break; case patternTypeEnum.Vertical: hb = new HatchBrush(HatchStyle.Vertical, si.Color, si.BackgroundColor); break; } } if (linGrBrush != null) { g.FillRectangle(linGrBrush, rect); linGrBrush.Dispose(); } else if (hb != null) { g.FillRectangle(hb, rect); hb.Dispose(); } else if (!si.BackgroundColor.IsEmpty) { sb = new SolidBrush(si.BackgroundColor); g.FillRectangle(sb, rect); sb.Dispose(); } } finally { if (linGrBrush != null) { linGrBrush.Dispose(); } if (sb != null) { sb.Dispose(); } } return; }
protected override void OnDrawItem(DrawItemEventArgs e) { if (e.Bounds != RectangleF.Empty) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; RectangleF tabTextArea = RectangleF.Empty; for (int nIndex = 0; nIndex < this.TabCount; nIndex++) { if (nIndex != this.SelectedIndex) { tabTextArea = (RectangleF)this.GetTabRect(nIndex); GraphicsPath _Path = new GraphicsPath(); _Path.AddRectangle(tabTextArea); using (LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { SystemColors.ControlLightLight, Color.FromArgb(255, SystemColors.ControlLight), SystemColors.ControlDark, SystemColors.ControlLightLight }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillPath(_Brush, _Path); using (Pen pen = new Pen(SystemColors.ActiveBorder)) { e.Graphics.DrawPath(pen, _Path); } _ColorBlend.Colors = new Color[] { SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 22, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); e.Graphics.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 20, 6, tabTextArea.Height - 8, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 9, tabTextArea.X + tabTextArea.Width - 7, 17); e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 17, tabTextArea.X + tabTextArea.Width - 7, 9); } if (CanDrawMenuButton(nIndex)) { _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; // assign the color blend to the pathgradientbrush _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 43, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); // e.Graphics.DrawRectangle(SystemPens.GradientInactiveCaption, tabTextArea.X + tabTextArea.Width - 37, 7, 13, 13); e.Graphics.DrawRectangle(new Pen(Color.White), tabTextArea.X + tabTextArea.Width - 41, 6, tabTextArea.Height - 7, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 36, 11, tabTextArea.X + tabTextArea.Width - 33, 16); e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 33, 16, tabTextArea.X + tabTextArea.Width - 30, 11); } } } _Path.Dispose(); } else { tabTextArea = (RectangleF)this.GetTabRect(nIndex); GraphicsPath _Path = new GraphicsPath(); _Path.AddRectangle(tabTextArea); using (LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { SystemColors.ControlLightLight, Color.FromArgb(255, SystemColors.Control), SystemColors.ControlLight, SystemColors.Control }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillPath(_Brush, _Path); using (Pen pen = new Pen(SystemColors.ActiveBorder)) { e.Graphics.DrawPath(pen, _Path); } //Drawing Close Button _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 231, 164, 152), Color.FromArgb(255, 231, 164, 152), Color.FromArgb(255, 197, 98, 79), Color.FromArgb(255, 197, 98, 79) }; _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 22, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); e.Graphics.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 20, 6, tabTextArea.Height - 8, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 9, tabTextArea.X + tabTextArea.Width - 7, 17); e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 17, tabTextArea.X + tabTextArea.Width - 7, 9); } if (CanDrawMenuButton(nIndex)) { //Drawing menu button _ColorBlend.Colors = new Color[] { SystemColors.ControlLightLight, Color.FromArgb(255, SystemColors.ControlLight), SystemColors.ControlDark, SystemColors.ControlLightLight }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 170, 213, 243), Color.FromArgb(255, 170, 213, 243), Color.FromArgb(255, 44, 137, 191), Color.FromArgb(255, 44, 137, 191) }; _Brush.InterpolationColors = _ColorBlend; e.Graphics.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 43, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); e.Graphics.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 41, 6, tabTextArea.Height - 7, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 36, 11, tabTextArea.X + tabTextArea.Width - 33, 16); e.Graphics.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 33, 16, tabTextArea.X + tabTextArea.Width - 30, 11); } } } _Path.Dispose(); } string str = this.TabPages[nIndex].Text; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; e.Graphics.DrawString(str, this.Font, new SolidBrush(this.TabPages[nIndex].ForeColor), tabTextArea, stringFormat); } } }
/// <summary>Draws the gradient rectangle.</summary> /// <param name="graphics">The specified graphics to draw on.</param> /// <param name="gradient">The gradient.</param> public static void Draw(Graphics graphics, Gradient gradient) { LinearGradientBrush _linearGradientBrush = CreateBrush(gradient); graphics.FillRectangle(_linearGradientBrush, gradient.Rectangle); }
protected override void OnMouseLeave(EventArgs e) { Graphics g = CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; RectangleF tabTextArea = RectangleF.Empty; for (int nIndex = 0; nIndex < this.TabCount; nIndex++) { if (nIndex != this.SelectedIndex) { tabTextArea = (RectangleF)this.GetTabRect(nIndex); GraphicsPath _Path = new GraphicsPath(); _Path.AddRectangle(tabTextArea); using (LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[] { SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder, SystemColors.ActiveBorder }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 22, 4, tabTextArea.Height - 2, tabTextArea.Height - 5); g.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 20, 6, tabTextArea.Height - 8, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 9, tabTextArea.X + tabTextArea.Width - 7, 17); g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 17, tabTextArea.X + tabTextArea.Width - 7, 9); } if (CanDrawMenuButton(nIndex)) { _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; // assign the color blend to the pathgradientbrush _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 43, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); // e.Graphics.DrawRectangle(SystemPens.GradientInactiveCaption, tabTextArea.X + tabTextArea.Width - 37, 7, 13, 13); g.DrawRectangle(new Pen(Color.White), tabTextArea.X + tabTextArea.Width - 41, 6, tabTextArea.Height - 7, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 36, 11, tabTextArea.X + tabTextArea.Width - 33, 16); g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 33, 16, tabTextArea.X + tabTextArea.Width - 30, 11); } } } _Path.Dispose(); } else { tabTextArea = (RectangleF)this.GetTabRect(nIndex); GraphicsPath _Path = new GraphicsPath(); _Path.AddRectangle(tabTextArea); using (LinearGradientBrush _Brush = new LinearGradientBrush(tabTextArea, SystemColors.Control, SystemColors.ControlLight, LinearGradientMode.Vertical)) { ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 231, 164, 152), Color.FromArgb(255, 231, 164, 152), Color.FromArgb(255, 197, 98, 79), Color.FromArgb(255, 197, 98, 79) }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 22, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); g.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 20, 6, tabTextArea.Height - 8, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 9, tabTextArea.X + tabTextArea.Width - 7, 17); g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 16, 17, tabTextArea.X + tabTextArea.Width - 7, 9); } if (CanDrawMenuButton(nIndex)) { //Drawing menu button _ColorBlend.Colors = new Color[] { SystemColors.ControlLightLight, Color.FromArgb(255, SystemColors.ControlLight), SystemColors.ControlDark, SystemColors.ControlLightLight }; _ColorBlend.Positions = new float[] { 0f, .4f, 0.5f, 1f }; _Brush.InterpolationColors = _ColorBlend; _ColorBlend.Colors = new Color[] { Color.FromArgb(255, 170, 213, 243), Color.FromArgb(255, 170, 213, 243), Color.FromArgb(255, 44, 137, 191), Color.FromArgb(255, 44, 137, 191) }; _Brush.InterpolationColors = _ColorBlend; g.FillRectangle(_Brush, tabTextArea.X + tabTextArea.Width - 43, 4, tabTextArea.Height - 3, tabTextArea.Height - 5); g.DrawRectangle(Pens.White, tabTextArea.X + tabTextArea.Width - 41, 6, tabTextArea.Height - 7, tabTextArea.Height - 9); using (Pen pen = new Pen(Color.White, 2)) { g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 36, 11, tabTextArea.X + tabTextArea.Width - 33, 16); g.DrawLine(pen, tabTextArea.X + tabTextArea.Width - 33, 16, tabTextArea.X + tabTextArea.Width - 30, 11); } } } _Path.Dispose(); } } g.Dispose(); }
public override void Draw() { Rectangle rectangle2; Graphics graphics1; Rectangle rectangle1 = new Rectangle(base.leftBounds - 2, base.topBounds - 2, (base.rightBounds - base.leftBounds) + 1, (base.bottomBounds - base.topBounds) + 1); goto Label_0165; Label_005C: if ((0 == 0) && (0x7fffffff != 0)) { goto Label_0073; } Label_005F: if (base._isResizing) { graphics1.DrawRectangle(this.BorderPenStyle, rectangle1); Color color1 = Color.FromArgb(100, Color.Yellow); if (0 == 0) { if (0 == 0) { if (1 == 0) { goto Label_0196; } Color color2 = Color.FromArgb(30, Color.Yellow); LinearGradientBrush brush1 = new LinearGradientBrush(rectangle1, color1, color2, 90f); graphics1.FillRectangle(brush1, rectangle1); SolidBrush brush2 = new SolidBrush(Color.Black); Interop.IHTMLElement element1 = (Interop.IHTMLElement)base.attachedElement; do { string text1 = element1.GetStyle().GetWidth() + ", " + element1.GetStyle().GetHeight(); graphics1.DrawString(text1, new Font("Arial", 8f), brush2, 5f + base.leftBounds, 5f + base.topBounds); }while (1 == 0); if (0 == 0) { goto Label_005C; } goto Label_0143; } return; } goto Label_0165; } Label_0073: graphics1.DrawImage(Resources.top, base.leftBounds, base.topBounds); Pen pen1 = new Pen(Color.DarkGray); graphics1.DrawRectangle(pen1, rectangle2); graphics1.Dispose(); if (0x7fffffff == 0) { goto Label_005C; } Label_0143: if (0 == 0) { return; } Label_0165: rectangle2 = new Rectangle(base.leftBounds, base.topBounds, (base.rightBounds - base.leftBounds) - 3, (base.bottomBounds - base.topBounds) - 3); Label_0196: graphics1 = Graphics.FromHdc(base.pvDrawObject); graphics1.Clear(Color.Transparent); graphics1.PageUnit = GraphicsUnit.Pixel; goto Label_005F; }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { LinearGradientBrush ColumnHeaderBrush = new LinearGradientBrush(e.Bounds, ColumnHeader[0], ColumnHeader[1], gradientAngle[0]); Pen HeaderBorderBrush = new Pen(CellBorderFocused); switch (DrawMode) { case drawMode.Default: base.OnDrawColumnHeader(e); break; case drawMode.Stylish: base.OnDrawColumnHeader(e); if (!HideHeader) { int internalWidth = e.Bounds.Width - (2 * (int)HeaderBorderBrush.Width); int internalHeight = (e.Bounds.Height - (2 * (int)HeaderBorderBrush.Width)); Graphics g = e.Graphics; GraphicsPath BG = CreateRoundRect(e.Bounds.X + (int)HeaderBorderBrush.Width, e.Bounds.Y + (int)HeaderBorderBrush.Width, internalWidth - 3, internalHeight - 3, radius); g.SmoothingMode = Smoothing; g.TextRenderingHint = TextRendering; SizeF fs = g.MeasureString(e.Header.Text, HeaderFont, e.Bounds.Width).ToSize(); using (StringFormat sf = new StringFormat()) { // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } if (rounding) { if (ShowBorder) { g.FillPath(new LinearGradientBrush(new Rectangle(e.Bounds.X + (int)HeaderBorderBrush.Width, e.Bounds.Y + (int)HeaderBorderBrush.Width, internalWidth - 3, internalHeight - 3), ColumnHeader[0], ColumnHeader[1], gradientAngle[0]), BG); g.DrawPath(HeaderBorderBrush, BG); //g.DrawRectangle(HeaderBorder.GetPen(), new Rectangle(e.Bounds.X + (int)HeaderBorder.GetPen().Width, e.Bounds.Y + (int)HeaderBorder.GetPen().Width, e.Bounds.Width - (2 * (int)HeaderBorder.GetPen().Width), e.Bounds.Height - (2 * (int)HeaderBorder.GetPen().Width))); } else { BG = CreateRoundRect(e.Bounds.X, e.Bounds.Y, internalWidth, internalHeight, radius); g.FillPath(new LinearGradientBrush(new Rectangle(e.Bounds.X, e.Bounds.Y, internalWidth, internalHeight), ColumnHeader[0], ColumnHeader[1], gradientAngle[0]), BG); } } else { g.FillRectangle(ColumnHeaderBrush, e.Bounds); if (ShowBorder) { g.DrawRectangle(HeaderBorderBrush, new Rectangle(e.Bounds.X + (int)HeaderBorderBrush.Width, e.Bounds.Y + (int)HeaderBorderBrush.Width, e.Bounds.Width - (2 * (int)HeaderBorderBrush.Width), e.Bounds.Height - (2 * (int)HeaderBorderBrush.Width))); } } if (ShowHeaderLine) { foreach (ColumnHeader items in Columns) { //g.DrawRectangle(new Pen(LineColor,lineHeight), new Rectangle(e.Bounds.X, e.Bounds.Y + (int)fs.Height + (int)(fs.Height / 4), items.Width, LineHeight)); g.DrawLine(new Pen(LineColor, lineHeight), new Point(e.Bounds.X, e.Bounds.Y + (int)fs.Height /*+ (int)(fs.Height / 10)*/), new Point(e.Bounds.X + e.Bounds.Width, e.Bounds.Y + (int)fs.Height /*+ (int)(fs.Height / 10)*/)); } } switch (HeaderAlignment) { case headerAlignment.Left: g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), e.Bounds, sf); break; case headerAlignment.Center: foreach (ColumnHeader items in Columns) { g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), new Rectangle(e.Bounds.X + (e.Bounds.Width / 2 - (int)(fs.Width / 2)), e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), sf); } break; case headerAlignment.Right: foreach (ColumnHeader items in Columns) { g.DrawString(e.Header.Text, HeaderFont, new SolidBrush(HeaderColor), new Rectangle(e.Bounds.X + (e.Bounds.Width - (int)fs.Width), e.Bounds.Y, e.Bounds.Width, e.Bounds.Height), sf); } break; default: throw new ArgumentOutOfRangeException(); } } } if (!DesignMode) { GC.Collect(); } return; } }
protected override void OnPaint(PaintEventArgs e) { bool rtl = RightToLeft == RightToLeft.Yes; AdjustScroll(); int startI = VerticalScroll.Value / ItemHeight - 1; int finishI = (VerticalScroll.Value + ClientSize.Height) / ItemHeight + 1; startI = Math.Max(startI, 0); finishI = Math.Min(finishI, VisibleItems.Count); int y = 0; int leftPadding = 18; for (int i = startI; i < finishI; i++) { y = i * ItemHeight - VerticalScroll.Value; if (ImageList != null && VisibleItems[i].ImageIndex >= 0) { if (rtl) { e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], Width - 1 - leftPadding, y); } else { e.Graphics.DrawImage(ImageList.Images[VisibleItems[i].ImageIndex], 1, y); } } var textRect = new Rectangle(leftPadding, y, ClientSize.Width - 1 - leftPadding, ItemHeight - 1); if (rtl) { textRect = new Rectangle(1, y, ClientSize.Width - 1 - leftPadding, ItemHeight - 1); } if (i == SelectedItemIndex) { Brush selectedBrush = new LinearGradientBrush(new Point(0, y - 3), new Point(0, y + ItemHeight), Color.White, Color.Orange); e.Graphics.FillRectangle(selectedBrush, textRect); e.Graphics.DrawRectangle(Pens.Orange, textRect); } if (i == hoveredItemIndex) { e.Graphics.DrawRectangle(Pens.Red, textRect); } var sf = new StringFormat(); if (rtl) { sf.FormatFlags = StringFormatFlags.DirectionRightToLeft; } var args = new PaintItemEventArgs(e.Graphics, e.ClipRectangle) { Font = Font, TextRect = new RectangleF(textRect.Location, textRect.Size), StringFormat = sf, IsSelected = i == SelectedItemIndex, IsHovered = i == hoveredItemIndex }; //call drawing VisibleItems[i].OnPaint(args); } }
private bool DrawItem(Graphics wa, Graph.ILaneRow row) { if (row == null || row.NodeLane == -1) { return(false); } // Clip to the area we're drawing in, but draw 1 pixel past so // that the top/bottom of the line segment's anti-aliasing isn't // visible in the final rendering. int top = wa.RenderingOrigin.Y + _rowHeight / 2; var laneRect = new Rectangle(0, top, Width, _rowHeight); Region oldClip = wa.Clip; var newClip = new Region(laneRect); newClip.Intersect(oldClip); wa.Clip = newClip; wa.Clear(Color.Transparent); //Getting RevisionGraphDrawStyle results in call to AppSettings. This is not very cheap, cache. revisionGraphDrawStyleCache = RevisionGraphDrawStyle; //for (int r = 0; r < 2; r++) for (int lane = 0; lane < row.Count; lane++) { int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * _laneWidth); for (int item = 0; item < row.LaneInfoCount(lane); item++) { Graph.LaneInfo laneInfo = row[lane, item]; bool highLight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal); List <Color> curColors = GetJunctionColors(laneInfo.Junctions); // Create the brush for drawing the line Brush brushLineColor = null; Pen brushLineColorPen = null; try { bool drawBorder = highLight && AppSettings.BranchBorders; //hide border for "non-relatives" if (curColors.Count == 1 || !AppSettings.StripedBranchChange) { if (curColors[0] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[0]); } else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor) { brushLineColor = new SolidBrush(curColors[1]); } else { drawBorder = false; brushLineColor = new SolidBrush(_nonRelativeColor); } } else { Color lastRealColor = curColors.LastOrDefault(c => c != _nonRelativeColor); if (lastRealColor.IsEmpty) { brushLineColor = new SolidBrush(_nonRelativeColor); drawBorder = false; } else { brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor); } } // Precalculate line endpoints bool singleLane = laneInfo.ConnectLane == lane; int x0 = mid; int y0 = top - 1; int x1 = singleLane ? x0 : mid + (laneInfo.ConnectLane - lane) * _laneWidth; int y1 = top + _rowHeight; Point p0 = new Point(x0, y0); Point p1 = new Point(x1, y1); // Precalculate curve control points when needed Point c0, c1; if (singleLane) { c0 = c1 = Point.Empty; } else { // Controls the curvature of cross-lane lines (0 = straight line, 1 = 90 degree turns) const float severity = 0.5f; c0 = new Point(x0, (int)(y0 * (1.0f - severity) + y1 * severity)); c1 = new Point(x1, (int)(y1 * (1.0f - severity) + y0 * severity)); } for (int i = drawBorder ? 0 : 2; i < 3; i++) { Pen penLine; switch (i) { case 0: penLine = _whiteBorderPen; break; case 1: penLine = _blackBorderPen; break; default: if (brushLineColorPen == null) { brushLineColorPen = new Pen(brushLineColor, _laneLineWidth); } penLine = brushLineColorPen; break; } if (singleLane) { wa.DrawLine(penLine, p0, p1); } else { wa.DrawBezier(penLine, p0, c0, c1, p1); } } } finally { if (brushLineColorPen != null) { ((IDisposable)brushLineColorPen).Dispose(); } if (brushLineColor != null) { ((IDisposable)brushLineColor).Dispose(); } } } } // Reset the clip region wa.Clip = oldClip; { // Draw node var nodeRect = new Rectangle ( wa.RenderingOrigin.X + (_laneWidth - _nodeDimension) / 2 + row.NodeLane * _laneWidth, wa.RenderingOrigin.Y + (_rowHeight - _nodeDimension) / 2, _nodeDimension, _nodeDimension ); Brush nodeBrush; List <Color> nodeColors = GetJunctionColors(row.Node.Ancestors); bool highlight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) || (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal); bool drawBorder = AppSettings.BranchBorders && highlight; if (nodeColors.Count == 1) { nodeBrush = new SolidBrush(highlight ? nodeColors[0] : _nonRelativeColor); if (nodeColors[0] == _nonRelativeColor) { drawBorder = false; } } else { nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1], LinearGradientMode.Horizontal); if (nodeColors.All(c => c == _nonRelativeColor)) { drawBorder = false; } } if (_filterMode == FilterType.Highlight && row.Node.IsFiltered) { Rectangle highlightRect = nodeRect; highlightRect.Inflate(2, 3); wa.FillRectangle(Brushes.Yellow, highlightRect); wa.DrawRectangle(Pens.Black, highlightRect); } if (row.Node.Data == null) { wa.FillEllipse(Brushes.White, nodeRect); using (var pen = new Pen(Color.Red, 2)) { wa.DrawEllipse(pen, nodeRect); } } else if (row.Node.IsActive) { wa.FillRectangle(nodeBrush, nodeRect); nodeRect.Inflate(1, 1); using (var pen = new Pen(Color.Black, 3)) wa.DrawRectangle(pen, nodeRect); } else if (row.Node.IsSpecial) { wa.FillRectangle(nodeBrush, nodeRect); if (drawBorder) { wa.DrawRectangle(Pens.Black, nodeRect); } } else { wa.FillEllipse(nodeBrush, nodeRect); if (drawBorder) { wa.DrawEllipse(Pens.Black, nodeRect); } } } return(true); }
internal void RenderTabBackgroundInternal(Graphics g, Rectangle rect, Color baseColor, Color borderColor, float basePosition, LinearGradientMode mode) { using (GraphicsPath graphicsPath = CreateTabPath(rect)) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4] { GetColor(baseColor, 0, 35, 24, 9), GetColor(baseColor, 0, 13, 8, 3), baseColor, GetColor(baseColor, 0, 68, 69, 54) }; ColorBlend colorBlend = new ColorBlend(); colorBlend.Positions = new float[4] { 0f, basePosition, basePosition + 0.05f, 1f }; colorBlend.Colors = colors; linearGradientBrush.InterpolationColors = colorBlend; g.FillPath(linearGradientBrush, graphicsPath); } if (baseColor.A > 80) { Rectangle rect2 = rect; if (mode == LinearGradientMode.Vertical) { rect2.Height = (int)((float)rect2.Height * basePosition); } else { rect2.Width = (int)((float)rect.Width * basePosition); } using (SolidBrush brush = new SolidBrush(Color.FromArgb(80, 255, 255, 255))) { g.FillRectangle(brush, rect2); } } rect.Inflate(-1, -1); using (GraphicsPath graphicsPath2 = CreateTabPath(rect)) { using (Pen pen = new Pen(Color.FromArgb(255, 255, 255))) { if (base.Multiline) { g.DrawPath(pen, graphicsPath2); } else { g.DrawLines(pen, graphicsPath2.PathPoints); } } } using (Pen pen = new Pen(borderColor)) { if (base.Multiline) { g.DrawPath(pen, graphicsPath); } g.DrawLines(pen, graphicsPath.PathPoints); } } }
protected override void OnPaint(PaintEventArgs e) { G = e.Graphics; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.Clear(BackColor); G.SmoothingMode = SmoothingMode.AntiAlias; GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7); GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7); GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.SetClip(GP1); G.FillRectangle(GB1, ClientRectangle); G.ResetClip(); G.DrawPath(P1, GP1); G.DrawPath(P4, GP2); SZ1 = G.MeasureString(Text, Font); PT1 = new PointF(5, Height / 2 - SZ1.Height / 2); G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1); G.DrawString(Text, Font, Brushes.White, PT1); G.DrawLine(P3, Width - 15, 10, Width - 11, 13); G.DrawLine(P3, Width - 7, 10, Width - 11, 13); G.DrawLine(Pens.Black, Width - 11, 13, Width - 11, 14); G.DrawLine(P2, Width - 16, 9, Width - 12, 12); G.DrawLine(P2, Width - 8, 9, Width - 12, 12); G.DrawLine(Pens.White, Width - 12, 12, Width - 12, 13); G.DrawLine(P1, Width - 22, 0, Width - 22, Height); G.DrawLine(P4, Width - 23, 1, Width - 23, Height - 2); G.DrawLine(P4, Width - 21, 1, Width - 21, Height - 2); }
private void button2_Click(object sender, EventArgs e) { /* * Создает новый объект Graphics из указанного дескриптора окна. * public static Graphics FromHwnd( * IntPtr hwnd * ) */ Graphics gr = Graphics.FromHwnd(this.Handle); gr.DrawLine(new Pen(Color.Green), 10, 50, 10, 200); // рисуем на форме Graphics gr1 = Graphics.FromHwnd(label1.Handle); gr1.DrawLine(new Pen(Color.Green, 5.0f), 20, 10, 90, 10); // рисуем на статике /* * Рисует прямоугольник, который определен парой координат, шириной и высотой. * public void DrawRectangle( * Pen pen, // Структура Pen, определяющая цвет, ширину и стиль прямоугольника. * int x, // Координата X верхнего левого угла прямоугольника для рисования. * int y, // Координата Y верхнего левого угла прямоугольника для рисования. * int width, // Ширина прямоугольника для рисования. * int height // Высота прямоугольника для рисования. * ) */ using (Pen p = new Pen(Color.Red, 4f)) { p.DashStyle = DashStyle.DashDotDot; gr.DrawRectangle(p, 160, 100, 100, 100); // отрисовываем контур прямоугольника штриховой линией } // Определяет кисть одного цвета. Кисти используются для заливки графических фигур, // таких как прямоугольники, эллипсы, круги, многоугольники и контуры. SolidBrush brush = new SolidBrush(Color.Blue); /* * Заполняет внутреннюю часть прямоугольника, который определен парой координат, шириной и высотой. * public void FillRectangle( * Brush brush, // Объект Brush, определяющий параметры заливки. * int x, // Координата X верхнего левого угла прямоугольника для заливки. * int y, // Координата Y верхнего левого угла прямоугольника для заливки. * int width, // Ширина прямоугольника для заливки. * int height // Высота прямоугольника для заливки. * ) */ gr.FillRectangle(brush, 300, 10, 100, 100); // заполняем прямоугольник синей кистью // Задает прямоугольную кисть со стилем штриховки, основным цветом и цветом фона. HatchBrush hatch_brush = new HatchBrush(HatchStyle.ZigZag, Color.Green, Color.Tomato); /* * Заполняет внутреннюю часть эллипса, определяемого ограничивающим прямоугольником, заданным с помощью пары координат, ширины и высоты. * public void FillEllipse( * Brush brush, // Объект Brush, определяющий параметры заливки. * int x, // Координата X верхнего левого угла ограничивающего прямоугольника, который определяет эллипс. * int y, // Координата Y верхнего левого угла ограничивающего прямоугольника, который определяет эллипс. * int width, // Ширина ограничивающего прямоугольника, определяющего эллипс. * int height // Высота ограничивающего прямоугольника, определяющего эллипс. * ) */ gr.FillEllipse(hatch_brush, 300, 120, 100, 100); // заполняем прямоугольник узорчатой кистью using (Pen p = new Pen(hatch_brush, 10)) { gr.DrawEllipse(p, 450, 10, 100, 100); // отрисовываем контур круга } Image img = Image.FromFile("fon2.bmp"); TextureBrush texture = new TextureBrush(img); gr.FillRectangle(texture, 450, 120, 100, 100); // заполняем прямоугольник текстурой LinearGradientBrush gradient = new LinearGradientBrush(new Point(12, 12), new Point(110, 110), Color.Red, Color.Black); gr.FillRectangle(gradient, 600, 10, 100, 100); // заполняем прямоугольник градиентной заливкой Point[] pts = new Point[6] { new Point(600, 150), new Point(640, 130), new Point(680, 140), new Point(700, 200), new Point(680, 230), new Point(620, 200) }; // Инкапсулирует объект Brush, заполняющий градиентом внутреннюю область объекта GraphicsPath PathGradientBrush path = new PathGradientBrush(pts); /* * Заполняет внутреннюю часть многоугольника, определяемого массивом точек, заданных структурами Point. * public void FillPolygon( * Brush brush, // Объект Brush, определяющий параметры заливки. * Point[] points, // Массив структур Point, которые представляют вершины закрашиваемого многоугольника. * ) */ gr.FillPolygon(path, pts); // Освобождаем системные ресурсы brush.Dispose(); path.Dispose(); img.Dispose(); texture.Dispose(); gradient.Dispose(); gr1.Dispose(); gr.Dispose(); }
protected override void OnPaint(PaintEventArgs e) { G = e.Graphics; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.Clear(BackColor); int X = 0; int Y = 0; float H = 0; G.DrawRectangle(P1, 1, 1, Width - 3, Height - 3); Rectangle R1 = default(Rectangle); NSListViewItem CI = null; int Offset = Convert.ToInt32(VS.Percent * (VS.Maximum - (Height - (ItemHeight * 2)))); int StartIndex = 0; if (Offset == 0) StartIndex = 0; else StartIndex = (Offset / ItemHeight); int EndIndex = Math.Min(StartIndex + (Height / ItemHeight), _Items.Count - 1); for (int I = StartIndex; I <= EndIndex; I++) { CI = Items[I]; R1 = new Rectangle(0, ItemHeight + (I * ItemHeight) + 1 - Offset, Width, ItemHeight - 1); H = G.MeasureString(CI.Text, Font).Height; Y = R1.Y + Convert.ToInt32((ItemHeight / 2) - (H / 2)); if (_SelectedItems.Contains(CI)) { if (I % 2 == 0) { G.FillRectangle(B1, R1); } else { G.FillRectangle(B2, R1); } } else { if (I % 2 == 0) { G.FillRectangle(B3, R1); } else { G.FillRectangle(B4, R1); } } G.DrawLine(P2, 0, R1.Bottom, Width, R1.Bottom); if (Columns.Length > 0) { R1.Width = Columns[0].Width; G.SetClip(R1); } //TODO: Ellipse text that overhangs seperators. G.DrawString(CI.Text, Font, Brushes.Black, 10, Y + 1); G.DrawString(CI.Text, Font, Brushes.White, 9, Y); if (CI.SubItems != null) { for (int I2 = 0; I2 <= Math.Min(CI.SubItems.Count, _Columns.Count) - 1; I2++) { X = ColumnOffsets[I2 + 1] + 4; R1.X = X; R1.Width = Columns[I2].Width; G.SetClip(R1); G.DrawString(CI.SubItems[I2].Text, Font, Brushes.Black, X + 1, Y + 1); G.DrawString(CI.SubItems[I2].Text, Font, Brushes.White, X, Y); } } G.ResetClip(); } R1 = new Rectangle(0, 0, Width, ItemHeight); GB1 = new LinearGradientBrush(R1, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.FillRectangle(GB1, R1); G.DrawRectangle(P3, 1, 1, Width - 22, ItemHeight - 2); int LH = Math.Min(VS.Maximum + ItemHeight - Offset, Height); NSListViewColumnHeader CC = null; for (int I = 0; I <= _Columns.Count - 1; I++) { CC = Columns[I]; H = G.MeasureString(CC.Text, Font).Height; Y = Convert.ToInt32((ItemHeight / 2) - (H / 2)); X = ColumnOffsets[I]; G.DrawString(CC.Text, Font, Brushes.Black, X + 1, Y + 1); G.DrawString(CC.Text, Font, Brushes.White, X, Y); G.DrawLine(P2, X - 3, 0, X - 3, LH); G.DrawLine(P3, X - 2, 0, X - 2, ItemHeight); } G.DrawRectangle(P2, 0, 0, Width - 1, Height - 1); G.DrawLine(P2, 0, ItemHeight, Width, ItemHeight); G.DrawLine(P2, VS.Location.X - 1, 0, VS.Location.X - 1, Height); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { G = e.Graphics; G.Clear(BackColor); G.SmoothingMode = SmoothingMode.AntiAlias; GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7); GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7); R1 = new Rectangle(0, 2, Width - 1, Height - 1); GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f); G.SetClip(GP1); G.FillRectangle(GB1, R1); I1 = Convert.ToInt32((_Value - _Minimum) / (_Maximum - _Minimum) * (Width - 3)); if (I1 > 1) { GP3 = ThemeModule.CreateRound(1, 1, I1, Height - 3, 7); R2 = new Rectangle(1, 1, I1, Height - 3); GB2 = new LinearGradientBrush(R2, Color.FromArgb(205, 150, 0), Color.FromArgb(150, 110, 0), 90f); G.FillPath(GB2, GP3); G.DrawPath(P1, GP3); G.SetClip(GP3); G.SmoothingMode = SmoothingMode.None; G.FillRectangle(B1, R2.X, R2.Y + 1, R2.Width, R2.Height / 2); G.SmoothingMode = SmoothingMode.AntiAlias; G.ResetClip(); } G.DrawPath(P2, GP1); G.DrawPath(P1, GP2); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { G = e.Graphics; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.Clear(BackColor); Rectangle R = default(Rectangle); int Offset = 0; G.DrawRectangle(P1, 0, 0, (12 * 32) + 1, (5 * 32) + 1); for (int I = 0; I <= Buttons.Length - 1; I++) { R = Buttons[I]; Offset = 0; if (I == Pressed) { Offset = 1; GP1 = new GraphicsPath(); GP1.AddRectangle(R); PB1 = new PathGradientBrush(GP1); PB1.CenterColor = Color.FromArgb(60, 60, 60); PB1.SurroundColors = new Color[] { Color.FromArgb(55, 55, 55) }; PB1.FocusScales = new PointF(0.8f, 0.5f); G.FillPath(PB1, GP1); } else { GB1 = new LinearGradientBrush(R, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.FillRectangle(GB1, R); } switch (I) { case 48: case 49: case 50: SZ1 = G.MeasureString(Other[I - 48], Font); G.DrawString(Other[I - 48], Font, Brushes.Black, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset + 1, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset + 1); G.DrawString(Other[I - 48], Font, Brushes.White, R.X + (R.Width / 2 - SZ1.Width / 2) + Offset, R.Y + (R.Height / 2 - SZ1.Height / 2) + Offset); break; case 47: DrawArrow(Color.Black, R.X + Offset + 1, R.Y + Offset + 1); DrawArrow(Color.White, R.X + Offset, R.Y + Offset); break; default: if (Shift) { G.DrawString(Upper[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1); G.DrawString(Upper[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset); if (!char.IsLetter(Lower[I])) { PT1 = LowerCache[I]; G.DrawString(Lower[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset); } } else { G.DrawString(Lower[I].ToString(), Font, Brushes.Black, R.X + 3 + Offset + 1, R.Y + 2 + Offset + 1); G.DrawString(Lower[I].ToString(), Font, Brushes.White, R.X + 3 + Offset, R.Y + 2 + Offset); if (!char.IsLetter(Upper[I])) { PT1 = UpperCache[I]; G.DrawString(Upper[I].ToString(), Font, B1, PT1.X + Offset, PT1.Y + Offset); } } break; } G.DrawRectangle(P2, R.X + 1 + Offset, R.Y + 1 + Offset, R.Width - 2, R.Height - 2); G.DrawRectangle(P3, R.X + Offset, R.Y + Offset, R.Width, R.Height); if (I == Pressed) { G.DrawLine(P1, R.X, R.Y, R.Right, R.Y); G.DrawLine(P1, R.X, R.Y, R.X, R.Bottom); } } }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { G = e.Graphics; G.Clear(BackColor); G.SmoothingMode = SmoothingMode.AntiAlias; GP1 = ThemeModule.CreateRound(0, 5, Width - 1, 10, 5); GP2 = ThemeModule.CreateRound(1, 6, Width - 3, 8, 5); R1 = new Rectangle(0, 7, Width - 1, 5); GB1 = new LinearGradientBrush(R1, Color.FromArgb(45, 45, 45), Color.FromArgb(50, 50, 50), 90f); I1 = Convert.ToInt32((double)(_Value - _Minimum) / (double)(_Maximum - _Minimum) * (Width - 11)); R2 = new Rectangle(I1, 0, 10, 20); G.SetClip(GP2); G.FillRectangle(GB1, R1); R3 = new Rectangle(1, 7, R2.X + R2.Width - 2, 8); GB2 = new LinearGradientBrush(R3, Color.FromArgb(205, 150, 0), Color.FromArgb(150, 110, 0), 90f); G.SmoothingMode = SmoothingMode.None; G.FillRectangle(GB2, R3); G.SmoothingMode = SmoothingMode.AntiAlias; for (int I = 0; I <= R3.Width - 15; I += 5) { G.DrawLine(P1, I, 0, I + 15, Height); } G.ResetClip(); G.DrawPath(P2, GP1); G.DrawPath(P3, GP2); GP3 = ThemeModule.CreateRound(R2, 5); GP4 = ThemeModule.CreateRound(R2.X + 1, R2.Y + 1, R2.Width - 2, R2.Height - 2, 5); GB3 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.FillPath(GB3, GP3); G.DrawPath(P3, GP3); G.DrawPath(P4, GP4); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { G = e.Graphics; G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; G.Clear(BackColor); G.SmoothingMode = SmoothingMode.AntiAlias; GP1 = ThemeModule.CreateRound(0, 0, Width - 1, Height - 1, 7); GP2 = ThemeModule.CreateRound(1, 1, Width - 3, Height - 3, 7); if (IsMouseDown) { PB1 = new PathGradientBrush(GP1); PB1.CenterColor = Color.FromArgb(60, 60, 60); PB1.SurroundColors = new Color[] { Color.FromArgb(55, 55, 55) }; PB1.FocusScales = new PointF(0.8f, 0.5f); G.FillPath(PB1, GP1); } else { GB1 = new LinearGradientBrush(ClientRectangle, Color.FromArgb(60, 60, 60), Color.FromArgb(55, 55, 55), 90f); G.FillPath(GB1, GP1); } G.DrawPath(P1, GP1); G.DrawPath(P2, GP2); SZ1 = G.MeasureString(Text, Font); PT1 = new PointF(5, Height / 2 - SZ1.Height / 2); if (IsMouseDown) { PT1.X += 1f; PT1.Y += 1f; } G.DrawString(Text, Font, Brushes.Black, PT1.X + 1, PT1.Y + 1); G.DrawString(Text, Font, Brushes.White, PT1); }