public SnakePit() { this.screen = DeviceGraphics.GetScreen(); this.screen.Clear(Color.White); this.numCellsX = (DeviceGraphics.ScreenXSize / cellSize) - 2; this.numCellsY = ((DeviceGraphics.ScreenYSize - scoreBoardHeight) / cellSize) - 2; this.cellOfsX = cellSize; this.cellOfsY = cellSize; this.rnd = new Random(); this.food = null; this.score = 0; this.level = 1; using (Brush brush = new HatchBrush(HatchStyle.DiagonalCross, Color.Black, Color.White)) { this.screen.FillRectangle(brush, 0, 0, DeviceGraphics.ScreenXSize, cellSize); this.screen.FillRectangle(brush, 0, cellSize, cellSize, this.numCellsY * cellSize); this.screen.FillRectangle(brush, (1 + this.numCellsX) * cellSize, cellSize, cellSize, this.numCellsY * cellSize); this.screen.FillRectangle(brush, 0, (1 + this.numCellsY) * cellSize, DeviceGraphics.ScreenXSize, cellSize); } this.screen.DrawRectangle(Pens.Black, cellSize - 1, cellSize - 1, this.numCellsX * cellSize + 1, this.numCellsY * cellSize + 1); using (Font f = new Font("tahoma", 15)) { using (StringFormat sf = new StringFormat()) { sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; this.screen.DrawString("<", f, Brushes.Black, new RectangleF(0, 220, 64, 20), sf); this.screen.DrawString("v", f, Brushes.Black, new RectangleF(64, 220, 64, 20), sf); this.screen.DrawString("^", f, Brushes.Black, new RectangleF(128, 220, 64, 20), sf); this.screen.DrawString(">", f, Brushes.Black, new RectangleF(192, 220, 64, 20), sf); } } this.ShowScore(); }
/*产生验证图片*/ public void CreateImages(string code) { int fontsize = 20; int width = code.Length * fontsize; int height = fontsize + 8; Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); HatchBrush b = new HatchBrush(HatchStyle.DiagonalCross, Color.LightGray, Color.WhiteSmoke); g.FillRectangle(b, 0, 0, width, height); Random random = new Random(); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush( new Rectangle(0, 0, bmp.Width, bmp.Height), Color.Black, Color.FromArgb(120, 120, 120), 20.0f, true); g.DrawString(code, new Font("Courier New", fontsize, FontStyle.Bold), brush, 2.0F, 1.0F); //画图片的前景噪音点 for (int i = 0; i < 50; i++) { int x = random.Next(bmp.Width); int y = random.Next(bmp.Height); bmp.SetPixel(x, y, Color.Green); } bmp.Save(Response.OutputStream, ImageFormat.Jpeg); b.Dispose(); g.Dispose(); bmp.Dispose(); }
private void HatchBrushes_Paint(object sender, PaintEventArgs e) { int y = 20; int x = 20; Font font = new Font("Tahoma", 8); // Enumerate over all the styles. foreach (HatchStyle brushStyle in System.Enum.GetValues(typeof(HatchStyle))) { HatchBrush myBrush = new HatchBrush(brushStyle, Color.Blue, Color.LightYellow); // Fill a rectangle with the brush. e.Graphics.FillRectangle(myBrush, x, y, 40, 20); // Display the brush name. e.Graphics.DrawString(brushStyle.ToString(), font, Brushes.Black, 50 + x, y + 5); y += 30; if ((y + 30) > this.ClientSize.Height) { y = 20; x += 180; } myBrush.Dispose(); } font.Dispose(); }
public static void BrushesExampleMethod(Graphics g) { Color pink = Color.FromArgb(241, 105, 190); SolidBrush sldBrush = new SolidBrush(pink); g.FillRectangle(sldBrush, 300, 150, 70, 70); HatchBrush hBrush = new HatchBrush(HatchStyle.NarrowVertical, Color.Pink, Color.Blue); g.FillRectangle(hBrush, 370, 150, 70, 70); sldBrush = new SolidBrush(Color.Orchid); g.FillRectangle(sldBrush, 440, 150, 70, 70); LinearGradientBrush lgBrush = new LinearGradientBrush(new Rectangle(0, 0, 20, 20), Color.Violet, Color.LightSteelBlue, LinearGradientMode.Vertical); g.FillRectangle(lgBrush, 300, 220, 70, 70); g.FillRectangle(Brushes.Indigo, 370, 220, 70, 70); sldBrush = new SolidBrush(Color.Orange); g.FillRectangle(sldBrush, 440, 220, 70, 70); lgBrush = new LinearGradientBrush(new RectangleF(0, 0, 90, 90), Color.BlueViolet, Color.LightPink, LinearGradientMode.BackwardDiagonal); g.FillRectangle(lgBrush, 300, 290, 70, 70); TextureBrush tBrush = new TextureBrush(Image.FromFile(@"Images\csharp.jpg")); g.FillRectangle(tBrush, 370, 290, 70, 70); tBrush = new TextureBrush(Image.FromFile(@"Images\003.jpg")); g.FillRectangle(tBrush, 440, 290, 70, 70); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { Graphics g = e.Graphics; { HatchBrush hatchBrush = null; Pen pen = null; try { switch (FileDlgStartLocation) { case AddonWindowLocation.Right: hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red); pen = new Pen(hatchBrush, 5); g.DrawLine(pen, 0, 0, 0, this.Height); break; case AddonWindowLocation.Bottom: hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red); pen = new Pen(hatchBrush, 5); g.DrawLine(pen, 0, 0, this.Width, 0); break; case AddonWindowLocation.BottomRight: default: hatchBrush = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red); pen = new Pen(hatchBrush, 5); g.DrawLine(pen, 0, 0, 4, 4); break; } } catch (Exception exc) { } finally { if (pen != null) { pen.Dispose(); } if (hatchBrush != null) { hatchBrush.Dispose(); } } } } base.OnPaint(e); }
protected void FillImageByHatch(Image img, HatchStyle s) { Graphics g = Graphics.FromImage(img); HatchBrush brush = new HatchBrush(s, Color.Black, Color.White); g.FillRectangle(brush, new Rectangle(0, 0, img.Width, img.Height)); g.Dispose(); }
//Filled shapes! public void Draw3() { g = this.CreateGraphics(); g.Clear(SystemColors.Window); Point[] po = new Point[] { new Point(10, 10), new Point(10, 100), new Point(50, 65), new Point(100, 100), new Point(85, 40) }; Brush b = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Cross, Color.DarkGreen); Pen p = new Pen(b, 3); g.DrawPolygon(p, po); //Point[] p1 = new Point[] { po[0], po[3]}; //byte[] b1 = new byte[]{(byte)PathPointType.Start , (byte)PathPointType.CloseSubpath }; //GraphicsPath gp = new GraphicsPath(p1,b1,FillMode.Winding); //Brush fill = new System.Drawing.Drawing2D.PathGradientBrush(gp); Brush solid = new SolidBrush(Color.IndianRed); g.FillPolygon(solid, po); Pen p1 = new Pen(Color.Maroon, 3); Brush b1 = new LinearGradientBrush(new Point(151, 151), new Point(250, 250), Color.GhostWhite, Color.Red); for (int x = 0; x < po.Length; x++) { po[x].X += 150; po[x].Y += 150; } g.DrawPolygon(p1, po); g.FillPolygon(b1, po); }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); e.DrawBackground(); HatchStyle style = FromString((string)this.Items[e.Index]); System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(style, Color.Black, e.BackColor); System.Drawing.Pen pen = new System.Drawing.Pen(Color.Black, 0); Rectangle rect = e.Bounds; rect.Inflate(-1, -1); rect.Width -= 1; rect.Height -= 1; e.Graphics.RenderingOrigin = new Point(0, 0); e.Graphics.FillRectangle(brush, rect); e.Graphics.DrawRectangle(pen, rect); pen.Dispose(); brush.Dispose(); }
private Image CreateSwatchImage(Color color) { Rectangle r = new Rectangle(0, 0, 20, 13); Bitmap image = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb); using (Graphics g = Graphics.FromImage(image)) { DisplayHelp.DrawRectangle(g, SwatchBorderColor, r); r.Inflate(-1, -1); if (color == Color.Empty) { using (HatchBrush brush = new HatchBrush(HatchStyle.BackwardDiagonal, SwatchHatchForeColor, SwatchBackColor)) g.FillRectangle(brush, r); } else if (color == Color.Transparent || color.A < 255) { using (HatchBrush brush = new HatchBrush(HatchStyle.LargeCheckerBoard, SwatchHatchForeColor, SwatchBackColor)) g.FillRectangle(brush, r); if (color != Color.Transparent) { using (SolidBrush brush = new SolidBrush(color)) g.FillRectangle(brush, r); } } else { using (SolidBrush brush = new SolidBrush(color)) g.FillRectangle(brush, r); } } image.Tag = color; return image; }
private void WorkSpace_Paint(object sender, PaintEventArgs e) { if (!this.dragimage) this.pictureBox1.Location = new Point(this.idx + (this.Width / 2) - (this.pictureBox1.Width / 2), this.idy + (this.Height / 2) - (this.pictureBox1.Height / 2)); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; LinearGradientBrush brush1 = new LinearGradientBrush(new Rectangle(0, 0, ((WorkSpace)sender).Width, ((WorkSpace)sender).Height / 2), Color.FromArgb(255, 155, 160, 179), Color.FromArgb(255, 114, 125, 153), LinearGradientMode.Vertical); brush1.WrapMode = WrapMode.TileFlipX; HatchBrush brush2 = new HatchBrush(HatchStyle.Percent75, Color.Transparent, Color.FromArgb(255, 169, 175, 199)); e.Graphics.FillRectangle(brush1, 0, 0, ((WorkSpace)sender).Width, ((WorkSpace)sender).Height); e.Graphics.FillRectangle(brush2, 0, 0, ((WorkSpace)sender).Width, ((WorkSpace)sender).Height); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), this.pictureBox1.Location.X - 3, this.pictureBox1.Location.Y - 3, this.pictureBox1.Width + 6, this.pictureBox1.Height + 6); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), this.pictureBox1.Location.X - 2, this.pictureBox1.Location.Y - 2, this.pictureBox1.Width + 4, this.pictureBox1.Height + 4); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(32, 0, 0, 0)), this.pictureBox1.Location.X - 1, this.pictureBox1.Location.Y - 1, this.pictureBox1.Width + 2, this.pictureBox1.Height + 2); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(16, 0, 0, 0)), this.pictureBox1.Location.X, this.pictureBox1.Location.Y, this.pictureBox1.Width + 4, this.pictureBox1.Height + 4); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(16, 0, 0, 0)), this.pictureBox1.Location.X, this.pictureBox1.Location.Y, this.pictureBox1.Width + 5, this.pictureBox1.Height + 5); if (this.dragimage) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.LightSteelBlue)), new Rectangle(new Point(this.idx + (this.Width / 2) - (this.pictureBox1.Width / 2), this.idy + (this.Height / 2) - (this.pictureBox1.Width / 2)), this.pictureBox1.Size)); e.Graphics.DrawRectangle(Pens.LightSteelBlue, new Rectangle(new Point(this.idx + (this.Width / 2) - (this.pictureBox1.Width / 2), this.idy + (this.Height / 2) - (this.pictureBox1.Width / 2)), this.pictureBox1.Size)); } }
public Signal() { data = new List<SignalEntry>(); Brush b = b = new HatchBrush(HatchStyle.DarkVertical, Color.Black, Color.White); }
private void TimelineUserControl_Paint(object sender, PaintEventArgs e) { var g = e.Graphics; if (this.DesignMode) { var rect = new RectangleF(0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height); using (var brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent10, Color.DimGray, Color.Black)) { g.FillRectangle(brush, rect); } var format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; g.DrawString("Graphs", this.Font, Brushes.White, rect, format); return; } lock (_drawLock) { if (_backBufferCurrent == null) { g.FillRectangle(Brushes.Black, this.ClientRectangle); } else { g.DrawImageUnscaled(_backBufferCurrent, 0, 0); } } }
void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e) { e.DrawBackground(); if (e.Index >= 0) { Rectangle rectangle = new Rectangle(4, e.Bounds.Top + 2, 30, e.Bounds.Height - 4); Color rectColor = (Color)Items[e.Index]; e.Graphics.FillRectangle(new SolidBrush(rectColor), rectangle); e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rectangle); if (e.Index == 0) { e.Graphics.DrawString("Custom", e.Font, System.Drawing.Brushes.Black, new PointF(42, e.Bounds.Top + 2)); } else { e.Graphics.DrawString(((Color)Items[e.Index]).Name, e.Font, System.Drawing.Brushes.Black, new PointF(42, e.Bounds.Top + 2)); } if (!Enabled) { HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.LightGray, Color.FromArgb(10, Color.LightGray)); rectangle.Inflate(1, 1); e.Graphics.FillRectangle(brush, rectangle); brush.Dispose(); } e.DrawFocusRectangle(); } }
void DrawFrames(Graphics g, ref float yOffset) { float frameWidth = this.ClientSize.Width / (float)VIDEO_FRAME_COUNT; float frameHeight = frameWidth * 9 / 16; if (_fields.Count > 0) { for (int frameIndex = 0; frameIndex < VIDEO_FRAME_COUNT; frameIndex++) { float x = frameIndex * frameWidth; var field = _fields[frameIndex]; var frameRect = new RectangleF(x, yOffset, frameWidth - 1.0f, frameHeight - 1.0f); if (field == null) { using (var brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.DarkGray, Color.Black)) { g.FillRectangle(brush, frameRect); } } else if (field.Image == null) { using (var brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard, Color.DarkGray, Color.Black)) { g.FillRectangle(brush, frameRect); } } else { g.DrawImage(field.Image, frameRect); } } } yOffset += frameHeight; }
public Bitmap GenerateImage() { int a = random.Next(_maxNumber); int b = random.Next(_maxNumber); _answer = (a + b).ToString(); string text = string.Format("{0} + {1} = ", a, b); Bitmap bitmap = new Bitmap(_width, _height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, _width, _height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, _foreColor, _bgColor); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(_familyName, fontSize, FontStyle.Bold); size = g.MeasureString(text, font); } while (size.Width > rect.Width); // Set up the text format. StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Create a path using the text and warp it randomly. GraphicsPath path = new GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, font.Size, rect, format); float v = 4F; PointF[] points = { new PointF(random.Next(rect.Width) / v, random.Next(rect.Height) / v), new PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v), new PointF(random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v), new PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.SolidDiamond, _foreColor, _foreColor); g.FillPath(hatchBrush, path); // Add some random noise. int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = random.Next(rect.Width); int y = random.Next(rect.Height); int w = random.Next(m / 50); int h = random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } return bitmap; }
/// <summary> /// Instructs the drawing code to fill the specified path with the specified pattern /// </summary> /// <param name="g">The System.Drawing.Graphics device to draw to</param> /// <param name="gp">The System.Drawing.Drawing2D.GraphicsPath to fill</param> public override void FillPath(Graphics g, GraphicsPath gp) { System.Drawing.Drawing2D.HatchBrush hb = new HatchBrush(_hatchStyle, _foreColor, _backColor); g.FillPath(hb, gp); hb.Dispose(); base.FillPath(g, gp); }
protected override void DrawSlider( PaintEventArgs e ) { float fSizeToDraw = m_SliderRectangle.Width * (Value - VisibleRangeMin) / (VisibleRangeMax - VisibleRangeMin); if ( m_ColorMin.A == 255 && m_ColorMax.A == 255 ) e.Graphics.FillRectangle( m_BackgroundBrush, m_SliderRectangle.X + fSizeToDraw, m_SliderRectangle.Y, m_SliderRectangle.Width - fSizeToDraw, m_SliderRectangle.Height ); else { // Draw a nice checker box background System.Drawing.Drawing2D.HatchBrush Checker = new System.Drawing.Drawing2D.HatchBrush( System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, Color.Gray, Color.DarkGray ); e.Graphics.FillRectangle( Checker, m_SliderRectangle ); Checker.Dispose(); } // Draw a gradient box if ( fSizeToDraw < 1.0f ) return; // Crashes if empty! RectangleF Rect = new RectangleF( m_SliderRectangle.X, m_SliderRectangle.Y, fSizeToDraw, m_SliderRectangle.Height ); System.Drawing.Drawing2D.GraphicsPath Path = new System.Drawing.Drawing2D.GraphicsPath(); Path.AddRectangle( Rect ); System.Drawing.Drawing2D.PathGradientBrush Gradient = new System.Drawing.Drawing2D.PathGradientBrush( Path ); Gradient.SurroundColors = new Color[] { m_ColorMin, m_ColorMax, m_ColorMax, m_ColorMin }; Gradient.CenterPoint = new PointF( 0.5f * (Rect.Left + Rect.Right), .5f * (Rect.Bottom + Rect.Top) ); Gradient.CenterColor = Color.FromArgb( (m_ColorMin.A + m_ColorMax.A) / 2, (m_ColorMin.R + m_ColorMax.R) / 2, (m_ColorMin.G + m_ColorMax.G) / 2, (m_ColorMin.B + m_ColorMax.B) / 2 ); e.Graphics.FillRectangle( Gradient, Rect ); Gradient.Dispose(); Path.Dispose(); }
/// <summary> /// ������֤�룬����һ�� Image ���� /// </summary> /// <param name="code"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="fontFamily"></param> /// <returns></returns> public Image CreateImage( String code, int width, int height, String fontFamily ) { Bitmap bm = new Bitmap( width, height ); using (Graphics g = Graphics.FromImage( bm )) { g.SmoothingMode = SmoothingMode.AntiAlias; HatchBrush brush = new HatchBrush( HatchStyle.SmallConfetti, Color.LightGray, Color.White ); Rectangle rect = new Rectangle( 0, 0, width, height ); g.FillRectangle( brush, rect ); int fontsize = rect.Height + 1; FontAndSize size = FontAndSize.GetValue( g, code, fontFamily, fontsize, bm.Width ); GraphicsPath gpath = getGraphicsPath( code, size.font, rect ); Color brushColor = ColorTranslator.FromHtml( "#000000" ); brush = new HatchBrush( HatchStyle.Divot, brushColor, Color.DarkGray ); g.FillPath( brush, gpath ); addRandomNoise( g, rect ); } return bm; }
// This is basically the same as Example1_5 except that it uses // a page unit of Inches public override void DrawRect(System.Drawing.RectangleF dirtyRect) { Graphics g = new Graphics(); g.Clear(Color.Wheat); // Create a pen object: Pen aPen = new Pen(Color.Blue, 1 / g.DpiX); // Create a brush object with a transparent red color: SolidBrush aBrush = new SolidBrush(Color.Red); g.PageUnit = GraphicsUnit.Inch; g.PageScale = 2; g.RenderingOrigin = new PointF(0.5f,0.0f); // Draw a rectangle: g.DrawRectangle(aPen, .20f, .20f, 1.00f, .50f); // Draw a filled rectangle: g.FillRectangle(aBrush, .20f, .90f, 1.00f, .50f); // Draw ellipse: g.DrawEllipse(aPen, new RectangleF(.20f, 1.60f, 1.00f, .50f)); // Draw filled ellipse: HatchBrush hBrush = new HatchBrush(HatchStyle.Horizontal, Color.Blue, Color.LightCoral); g.FillEllipse(hBrush, new RectangleF(1.70f, .20f, 1.00f, .50f)); //g.FillEllipse(aBrush, new RectangleF(1.70f, .20f, 1.00f, .50f)); // Draw arc: g.DrawArc(aPen, new RectangleF(1.70f, .90f, 1.00f, .50f), -90, 180); // Draw filled pie pieces g.FillPie(aBrush, 1.70f, 1.60f, 1.00f, 1.00f, -90, 90); g.FillPie(Brushes.Green, 1.70f, 1.60f, 1.00f, 1.00f, -90, -90); g.Dispose(); }
public override void PaintValue(PaintValueEventArgs e) { Hatcher hatch = e.Value as Hatcher; using (HatchBrush brush = new HatchBrush(hatch.HatchType, hatch.ForeColor, hatch.BackColor)) { e.Graphics.FillRectangle(brush, e.Bounds); } }
/// <summary> /// Constructor</summary> /// <param name="font">Font to use for rendering timeline text</param> public DefaultTimelineRenderer(Font font) : base(font) { m_selectedPen = new Pen(Color.Tomato, 3); Color lightGray = Color.LightGray; m_collapsedBrush = new SolidBrush(lightGray); m_invalidBrush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.DimGray, Color.FromArgb(0, 0, 0, 0)); }
public override System.Drawing.Brush CreateGDIBrush(RectangleF rc) { System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush( _hatchStyle, _foreColor, _backColor); return(brush); }
private void GenerateImage() { Bitmap bitmap = new Bitmap (this.width, this.height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(0, 0, this.width, this.height); HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(this.text, font); } while (size.Width > rect.Width); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; GraphicsPath path = new GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(this.text, font.FontFamily, (int)font.Style, 75, rect, format); float v = 4F; PointF[] points = { new PointF(this.random.Next(rect.Width) / v, this.random.Next( rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v), new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v), new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v) }; Matrix matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++) { int x = this.random.Next(rect.Width); int y = this.random.Next(rect.Height); int w = this.random.Next(m / 50); int h = this.random.Next(m / 50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); this.image = bitmap; }
public override Bitmap Build(string text) { var random = new Random(); var bitmap = new Bitmap (Width, Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bitmap); g.SmoothingMode = SmoothingMode.AntiAlias; var rect = new Rectangle(0, 0, Width, Height); var hatchBrush = new HatchBrush(HatchStyle.SmallConfetti, Color.LightGray, Color.White); g.FillRectangle(hatchBrush, rect); SizeF size; float fontSize = rect.Height + 1; Font font; do { fontSize--; font = new Font(FontFamily.GenericSansSerif, fontSize, FontStyle.Bold); size = g.MeasureString(text, font); } while (size.Width > rect.Width); var format = new StringFormat {Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center}; var path = new GraphicsPath(); //path.AddString(this.text, font.FontFamily, (int) font.Style, // font.Size, rect, format); path.AddString(text, font.FontFamily, (int) font.Style, 75, rect, format); float v = 4F; PointF[] points = { new PointF(random.Next(rect.Width)/v, random.Next( rect.Height)/v), new PointF(rect.Width - random.Next(rect.Width)/v, random.Next(rect.Height)/v), new PointF(random.Next(rect.Width)/v, rect.Height - random.Next(rect.Height)/v), new PointF(rect.Width - random.Next(rect.Width)/v, rect.Height - random.Next(rect.Height)/v) }; var matrix = new Matrix(); matrix.Translate(0F, 0F); path.Warp(points, rect, matrix, WarpMode.Perspective, 0F); hatchBrush = new HatchBrush(HatchStyle.Percent10, Color.Black, Color.SkyBlue); g.FillPath(hatchBrush, path); int m = Math.Max(rect.Width, rect.Height); for (int i = 0; i < (int) (rect.Width*rect.Height/30F); i++) { int x = random.Next(rect.Width); int y = random.Next(rect.Height); int w = random.Next(m/50); int h = random.Next(m/50); g.FillEllipse(hatchBrush, x, y, w, h); } font.Dispose(); hatchBrush.Dispose(); g.Dispose(); return bitmap; }
Pen CreateHatchPen(Color color, float width) { Brush brush = new HatchBrush(HatchStyle.DarkUpwardDiagonal, // WideDownwardDiagonal, // Color.FromArgb(0, 255, 255, 255), Color.FromArgb(0, 254, 254, 254), Color.FromArgb(255, color) ); // back return new Pen(brush, width); // 可修改 }
public static void Draw(Graphics g) { Point[] p = { new Point(240, 110), new Point(440, 110), new Point(510, 150), new Point(300, 150) }; TextureBrush tBrush = new TextureBrush(Image.FromFile(@"Images\0073.jpg")); g.FillPolygon(tBrush, p); Point[] p1 = { new Point(240, 110), new Point(300, 150), new Point(300, 360), new Point(240, 310) }; HatchBrush hBrush = new HatchBrush(HatchStyle.DashedDownwardDiagonal, Color.Violet, Color.White); g.FillPolygon(hBrush, p1); }
/// <summary>デフォルトコンストラクタ。</summary> public GlobalRenderingSettingData() { BackgroundColor = new ColorEx( 255, 0, 0, 0 ); SelectedObjectBorder = Pens.Yellow; SelectedObjectFill = new HatchBrush( HatchStyle.Percent25, Color.Yellow ); InvalidObjectBorder = Pens.Red; InvalidObjectFill = new HatchBrush( HatchStyle.Percent25, Color.Red ); DisabledObjectBorder = Pens.Gray; DisabledObjectFill = new HatchBrush( HatchStyle.Percent25, Color.Gray ); }
public override void DrawRect(CGRect dirtyRect) { Graphics g = Graphics.FromCurrentContext(); g.Clear(Color.White); g.SmoothingMode = SmoothingMode.AntiAlias; // Create a pen object: Pen aPen = new Pen(Color.Blue, 2); // Create a brush object with a transparent red color: SolidBrush aBrush = new SolidBrush(Color.Red); HatchBrush hBrush = new HatchBrush(HatchStyle.Shingle, Color.Blue, Color.LightCoral); HatchBrush hBrush2 = new HatchBrush(HatchStyle.Cross, Color.Blue, Color.LightCoral); HatchBrush hBrush3 = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Blue, Color.LightCoral); HatchBrush hBrush4 = new HatchBrush(HatchStyle.Sphere, Color.Blue, Color.LightCoral); // Draw a rectangle: g.DrawRectangle(aPen, 20, 20, 100, 50); // Draw a filled rectangle: g.FillRectangle(hBrush, 20, 90, 100, 50); // Draw ellipse: g.DrawEllipse(aPen, new Rectangle(20, 160, 100, 50)); // Draw filled ellipse: g.FillEllipse(hBrush2, new Rectangle(170, 20, 100, 50)); // Draw arc: g.DrawArc(aPen, new Rectangle(170, 90, 100, 50), -90, 180); // Draw filled pie pieces g.FillPie(aBrush, new Rectangle(170, 160, 100, 100), -90, 90); g.FillPie(hBrush4, new Rectangle(170, 160, 100, 100), -90, -90); // Create pens. Pen redPen = new Pen(Color.Red, 3); Pen greenPen = new Pen(Color.Green, 3); greenPen.DashStyle = DashStyle.DashDotDot; SolidBrush transparentBrush = new SolidBrush(Color.FromArgb(150, Color.Wheat)); // define point array to draw a curve: Point point1 = new Point(300, 250); Point point2 = new Point(350, 125); Point point3 = new Point(400, 110); Point point4 = new Point(450, 210); Point point5 = new Point(500, 300); Point[] curvePoints ={ point1, point2, point3, point4, point5}; // Draw lines between original points to screen. g.DrawLines(redPen, curvePoints); // Fill Curve g.FillClosedCurve(transparentBrush, curvePoints); // Draw closed curve to screen. g.DrawClosedCurve(greenPen, curvePoints); g.Dispose(); }
private void bPaint_Paint(object sender, PaintEventArgs e) { // komponensre rajzolas - iratkozzunk fel a Paint esemenyere. A komponens minden frissitesekor meghivja ezt az esemenyt. Graphics iGraphics = e.Graphics; Brush iBrush = new HatchBrush(HatchStyle.DashedHorizontal,Color.Chocolate); Pen iPen = new Pen(iBrush); iGraphics.DrawRectangle(iPen,10,10,50,50); iGraphics.FillRectangle(iBrush, 30, 30, 70, 70); iGraphics.DrawLine(iPen, 0, 0, bDraw.Width - 1, bDraw.Height - 1); }
public void DrawHighlight(Graphics g, Matrix xformWorldToPixel) { using (Pen redPen = new Pen(Color.Red, penWidth)) using (Brush blueBrush = new HatchBrush(HatchStyle.Percent25, Color.DarkBlue, Color.Transparent)) { PointF[] pts = { new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top) }; xformWorldToPixel.TransformPoints(pts); RectangleF rectPixel = RectangleF.FromLTRB(pts[0].X, pts[0].Y, pts[1].X, pts[1].Y); g.FillRectangle(blueBrush, rectPixel.X, rectPixel.Y, rectPixel.Width, rectPixel.Height); g.DrawRectangle(redPen, rectPixel.X, rectPixel.Y, rectPixel.Width, rectPixel.Height); } }
private void picIcon_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { using (System.Drawing.Brush brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeCheckerBoard, System.Drawing.Color.LightGray, System.Drawing.Color.White)) { e.Graphics.FillRectangle(brush, picIcon.ClientRectangle); } if (lstFormats.SelectedItem != null) { e.Graphics.DrawImage(IconFile.ToBitmap((Skybound.Drawing.Design.IconFormat)lstFormats.SelectedItem), 0, 0); } }
public static void GenerateFunctionBoxWithPreview( HttpContext context, string functionTitle, Bitmap previewImage, bool showEditButton, Stream outputStream) { using (var header = new FunctionHeader(functionTitle, false, showEditButton)) { var headerSize = header.HeaderSize; Size totalSize = new Size(Math.Max(header.HeaderSize.Width, previewImage.Width), headerSize.Height + previewImage.Height); using (var bitmap = new Bitmap(totalSize.Width, totalSize.Height)) using (var graphics = Graphics.FromImage(bitmap)) { header.DrawHeader(bitmap, graphics, totalSize.Width); Point previewImageOffset = new Point( (Math.Max(totalSize.Width - 10, previewImage.Width) - previewImage.Width) / 2, headerSize.Height); // Preview image graphics.DrawImage(previewImage, previewImageOffset); // Image outline using (var brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.FromArgb(190, 190, 190), Color.Transparent)) using (var pen = new Pen(brush)) { graphics.DrawRectangle(pen, new Rectangle(previewImageOffset, new Size(previewImage.Width - 1, previewImage.Height - 1))); } context.Response.ContentType = "image/png"; context.Response.Cache.SetExpires(DateTime.Now.AddDays(10)); string tempFileName = Path.GetTempFileName(); try { // Saving to a temporary file, as Image.Save() sometimes on a not seekable stream throws // an "A generic error occurred in GDI+." exception bitmap.Save(tempFileName, ImageFormat.Png); context.Response.WriteFile(tempFileName); context.Response.Flush(); } finally { C1File.Delete(tempFileName); } } } }
public void DrawFocusRectangle(Graphics g) { HatchBrush b = new HatchBrush(HatchStyle.LightUpwardDiagonal, Color.FromArgb(HATCH_ALPHA, Color.Black), Color.FromArgb(0, Color.White)); using (b) g.DrawRectangle(new Pen(b, HATCH_WIDTH), hatchRectangle); using (Pen borderPen = new Pen(Color.FromArgb(BORDER_ALPHA, Color.Black), 1)) g.DrawRectangle(borderPen, borderRectangle); }
void gradient_Paint(object sender, PaintEventArgs e) { var c = (UserControl)sender; using (Brush checkerBrush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.White, Color.LightGray)) e.Graphics.FillRectangle(checkerBrush, e.ClipRectangle); using (Brush linearGradiant = new LinearGradientBrush(c.ClientRectangle, Color.FromArgb(0, _value), Color.FromArgb(255, _value), 0f)) e.Graphics.FillRectangle(linearGradiant, e.ClipRectangle); var thumb = new Rectangle(_value.A - 5, 0, 10, _c.Height); ControlPaint.DrawBorder3D(e.Graphics, thumb, Border3DStyle.RaisedInner); }
public void PaintPath(Graphics g, System.Drawing.Drawing2D.GraphicsPath path) { HatchBrush brush = new HatchBrush(style, color1, color2); g.FillPath(brush, path); brush.Dispose(); if(numericUpDown1.Value != 0) { Pen pen = new Pen(colorBorder, (float)numericUpDown1.Value); g.DrawPath(pen, path); pen.Dispose(); } }
private void frmDonate_Paint(object sender, PaintEventArgs e) { using (HatchBrush h1 = new HatchBrush(HatchStyle.Percent20, BackgroundColors.BackgroundDotsLight, BackgroundColors.BackgroundColor)) { e.Graphics.FillRectangle(h1, e.ClipRectangle); } using (HatchBrush h2 = new HatchBrush(HatchStyle.Percent20, BackgroundColors.BackgroundDotsDark, Color.Transparent)) { e.Graphics.RenderingOrigin = new Point(0, -1); e.Graphics.FillRectangle(h2, e.ClipRectangle); e.Graphics.RenderingOrigin = Point.Empty; } }
public override void Render(Graphics g) { var colorRect = new Rectangle(0, (Slider.Height / 2) - 3, Slider.Width - 6, 4); System.Drawing.Brush brush = new HatchBrush(HatchStyle.LargeCheckerBoard, Color.Gray, Color.LightGray); g.FillRectangle(brush, colorRect); brush = new LinearGradientBrush(colorRect, Color.FromArgb(0, EndColor), EndColor, LinearGradientMode.Horizontal); g.FillRectangle(brush, colorRect); g.DrawRectangle(Pens.Black, colorRect); DrawThumb(g); }
//private static readonly Point ImageIndent = new Point(2, 2); public override void Render(MetroRendererInfo renderingInfo) { MetroTileItem item = (MetroTileItem)renderingInfo.Control; if (item.Frames.Count == 0) { using (HatchBrush brush = new HatchBrush(HatchStyle.ForwardDiagonal, Color.Red)) renderingInfo.PaintEventArgs.Graphics.FillRectangle(brush, item.Bounds); return; } Matrix currentTransform = null; float zoom = 0.95f; System.Drawing.Drawing2D.Matrix mx = null; if (renderingInfo.ItemPaintArgs.DragInProgress) { currentTransform = renderingInfo.PaintEventArgs.Graphics.Transform; mx = new System.Drawing.Drawing2D.Matrix(zoom, 0, 0, zoom, 0, 0); float offsetX = (item.WidthInternal * (1.0f / zoom) - item.WidthInternal) / 2; float offsetY = (item.HeightInternal * (1.0f / zoom) - item.HeightInternal) / 2; mx.Translate(offsetX, offsetY); renderingInfo.PaintEventArgs.Graphics.Transform = mx; } if (item.CurrentFrameOffset != 0 && item.LastFrame != item.CurrentFrame) { Graphics g = renderingInfo.PaintEventArgs.Graphics; if (currentTransform == null) currentTransform = g.Transform; g.TranslateTransform(0, -(item.HeightInternal - item.CurrentFrameOffset - InflatePixels * 2), MatrixOrder.Append); // Draw last frame first then offset the current frame RenderFrame(renderingInfo, item.LastFrame); if (mx != null) g.Transform = mx; else g.Transform = currentTransform; g.TranslateTransform(0, item.CurrentFrameOffset, MatrixOrder.Append); RenderFrame(renderingInfo, item.CurrentFrame); } else RenderFrame(renderingInfo, item.CurrentFrame); if (currentTransform != null) { renderingInfo.PaintEventArgs.Graphics.Transform = currentTransform; currentTransform.Dispose(); } }
/// <summary> /// Creates the captcha image with noise. /// </summary> public byte[] DrawCaptcha(string message, float fontSize, string fontName) { message = message.Replace(",", string.Empty); const int margin = 8; var captchaFont = new Font(fontName, fontSize, FontStyle.Bold, GraphicsUnit.Pixel); var captchaSize = measureString(message, captchaFont); var height = (int)captchaSize.Height + margin; var width = (int)captchaSize.Width + margin; using (var pic = new Bitmap(width, height, PixelFormat.Format24bppRgb)) { using (var graphics = Graphics.FromImage(pic)) { using (var backgroundBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard, Color.DimGray, Color.WhiteSmoke)) graphics.FillRectangle(backgroundBrush, 0, 0, width, height); var horizontalPosition = 0; var characterSpacing = (width / message.Length) - 1; foreach (var item in message) { var brush = new SolidBrush(ColorTranslator.FromHtml(colors[_randomNumberProvider.Next(0, colors.Count - 1)])); var maxVerticalPosition = height - Convert.ToInt32(graphics.MeasureString(item.ToString(), captchaFont).Height); graphics.DrawString(item.ToString(), captchaFont, brush, horizontalPosition, _randomNumberProvider.Next(0, maxVerticalPosition)); horizontalPosition += characterSpacing + _randomNumberProvider.Next(-1, 1); } for (var i = 0; i < 30; i++) { var start = _randomNumberProvider.Next(1, 4); var brush = new SolidBrush(ColorTranslator.FromHtml(colors[_randomNumberProvider.Next(0, colors.Count - 1)])); graphics.FillEllipse(brush, _randomNumberProvider.Next(start, width), _randomNumberProvider.Next(1, height), _randomNumberProvider.Next(1, 4), _randomNumberProvider.Next(2, 5)); var x0 = _randomNumberProvider.Next(0, width); var y0 = _randomNumberProvider.Next(0, height); var x1 = _randomNumberProvider.Next(0, width); var y1 = _randomNumberProvider.Next(0, height); graphics.DrawLine(Pens.Black, x0, y0, x1, x1); } } using (var stream = new MemoryStream()) { distortImage(height, width, pic); pic.Save(stream, ImageFormat.Png); return(stream.ToArray()); } } }
protected override void OnPaint(PaintEventArgs e) { if (DesignMode) { Graphics gr = e.Graphics; { HatchBrush hb = null; Pen p = null; try { switch (this.StartLocation) { case AddonWindowLocation.Right: hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowHorizontal, Color.Black, Color.Red); p = new Pen(hb, 5); gr.DrawLine(p, 0, 0, 0, this.Height); break; case AddonWindowLocation.Bottom: hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.NarrowVertical, Color.Black, Color.Red); p = new Pen(hb, 5); gr.DrawLine(p, 0, 0, this.Width, 0); break; case AddonWindowLocation.BottomRight: default: hb = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.Sphere, Color.Black, Color.Red); p = new Pen(hb, 5); gr.DrawLine(p, 0, 0, 4, 4); break; } } finally { if (p != null) { p.Dispose(); } if (hb != null) { hb.Dispose(); } } } } base.OnPaint(e); }
private void _DrawColumns(Graphics graphics) { // draw column lines graphics.DrawRectangles(this.HeaderFormat.Border, _mHeaderInfo.Columns.ToArray()); // fill weekend columns for (int i = 0; i < _mHeaderInfo.DateTimes.Count; i++) { var date = _mHeaderInfo.DateTimes[i]; // highlight weekends for day time scale if (date.DayOfWeek == DayOfWeek.Sunday || date.DayOfWeek == DayOfWeek.Saturday) { var pattern = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent20, this.HeaderFormat.Border.Color, Color.Transparent); graphics.FillRectangle(pattern, _mHeaderInfo.Columns[i]); } } }
public void Draw2() { if (g == null) { g = this.CreateGraphics(); } g.Clear(Color.Olive); g.DrawEllipse(Pens.Tan, new Rectangle(0, 0, this.Width - 10, this.Height / 5)); g.DrawIcon(SystemIcons.Exclamation, new Rectangle(this.Width / 2, this.Height / 2, this.Width / 4, this.Height / 4)); g.DrawIconUnstretched(SystemIcons.WinLogo, new Rectangle(0, this.Height / 2, this.Width / 4, this.Height / 4)); Brush b = new System.Drawing.Drawing2D.HatchBrush(HatchStyle.DiagonalBrick, Color.Maroon); Pen p = new Pen(b, 3); p.StartCap = LineCap.Triangle; p.EndCap = LineCap.RoundAnchor; g.DrawLine(p, new Point(5, this.Height / 2), new Point(this.Width - 20, this.Height / 2)); g.DrawArc(p, new RectangleF(new Point(this.Width / 2, this.Height / 2), new Size(100, 100)), (float)13.3, (float)180); }
private void DoInstructions(Single recX, Single recY, Single recWidth, Single recHeight, Brush b, Single StartAngle, Single SweepAngle) { PagePie pl = new PagePie(); pl.StartAngle = StartAngle; pl.SweepAngle = SweepAngle; StyleInfo SI = new StyleInfo(); pl.X = X + recX * SCALEFACTOR; pl.Y = Y + recY * SCALEFACTOR; pl.W = recWidth * SCALEFACTOR; pl.H = recHeight * SCALEFACTOR; switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
private void DoInstructions(PointF[] Ps, Brush b) { PagePolygon pl = new PagePolygon(); //pl.X = X * SCALEFACTOR; //pl.Y = Y * SCALEFACTOR; pl.Points = Ps; StyleInfo SI = new StyleInfo(); switch (b.GetType().Name) { case "SolidBrush": System.Drawing.SolidBrush theBrush = (System.Drawing.SolidBrush)b; SI.Color = theBrush.Color; SI.BackgroundColor = theBrush.Color; break; case "LinearGradientBrush": System.Drawing.Drawing2D.LinearGradientBrush linBrush = (System.Drawing.Drawing2D.LinearGradientBrush)b; SI.BackgroundGradientType = BackgroundGradientTypeEnum.LeftRight; SI.BackgroundColor = linBrush.LinearColors[0]; SI.BackgroundGradientEndColor = linBrush.LinearColors[1]; break; case "HatchBrush": System.Drawing.Drawing2D.HatchBrush hatBrush = (System.Drawing.Drawing2D.HatchBrush)b; SI.BackgroundColor = hatBrush.BackgroundColor; SI.Color = hatBrush.ForegroundColor; SI.PatternType = StyleInfo.GetPatternType(hatBrush.HatchStyle); break; default: break; } pl.SI = SI; items.Add(pl); }
public void DrawSelectionTrackers(Bitmap bm) { Brush b = new SolidBrush(Color.Black); InitTrackerRects(); Graphics g = Graphics.FromImage(bm); System.Drawing.Drawing2D.HatchBrush aHatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal, Color.Red, Color.White); g.DrawRectangle(new Pen(aHatchBrush, m_nOffset), rc.X - m_nOffset / 2, rc.Y - m_nOffset / 2, rc.Width + m_nOffset, rc.Height + m_nOffset); g.FillRectangle(b, m_TopLeft); g.FillRectangle(b, m_TopCenter); g.FillRectangle(b, m_TopRight); g.FillRectangle(b, m_CenterLeft); g.FillRectangle(b, m_CenterRight); g.FillRectangle(b, m_BottomLeft); g.FillRectangle(b, m_BottomCenter); g.FillRectangle(b, m_BottomRight); // Disposing resources b.Dispose(); g.Dispose(); }
/*public static void generateCaptcha(HttpContext context, int length, randomType type, int width, int height, System.Drawing.Color top_color, System.Drawing.Color bottom_color, System.Drawing.Color text_color) * { * System.Drawing.Drawing2D.HatchBrush hatchBrush = null; * * string embedded_string = commonFunctions.generateRandom(length, type); * * commonVariables.SetSessionVariable("vCode", commonEncryption.encrypting(embedded_string)); * * char[] char_array = null; * * char_array = new char[embedded_string.Length + embedded_string.Length]; * * for (int int_count = 0; int_count < embedded_string.Length; int_count++) * { * char_array[int_count + int_count] = embedded_string[int_count]; * char_array[int_count + int_count + 1] = " "[0]; * } * * //Captcha String * System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily("Comic Sans MS"); * // - Generate Random * //int randomsize = 5; * Random random = new Random(DateTime.Now.Millisecond); * * // Create a new 32-bit bitmap image. * using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) * { * // Create a graphics object for drawing. * using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) * { * g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; * System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height); * * // Fill in the background. * using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, top_color, bottom_color)) * { * g.FillRectangle(hatchBrush, rect); * * // Set up the text font. * System.Drawing.SizeF size = default(System.Drawing.SizeF); * float fontSize = rect.Height + 25; * System.Drawing.Font font = null; * System.Drawing.StringFormat format = new System.Drawing.StringFormat(); * format.Alignment = System.Drawing.StringAlignment.Center; * format.LineAlignment = System.Drawing.StringAlignment.Center; * * // Adjust the font size until the text fits within the image. * do * { * fontSize -= 5; * font = new System.Drawing.Font(fontFamily, fontSize, System.Drawing.FontStyle.Bold); * size = g.MeasureString(new string(char_array), font, new System.Drawing.SizeF(width, height), format); * } while (size.Width > rect.Width); * * // Create a path using the text and warp it randomly. * System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); * path.AddString(new string(char_array), font.FontFamily, Convert.ToInt32(font.Style), font.Size, rect, format); * * float v = 6f; * System.Drawing.PointF[] points = { * new System.Drawing.PointF(random.Next(rect.Width) / v, random.Next(rect.Height) / v), * new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v), * new System.Drawing.PointF(random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v), * new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v) * }; * System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); * matrix.Translate(0f, 0f); * path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0f); * * // Draw the text. * using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal, text_color, text_color)) * { * g.FillPath(hatchBrush, path); * } * * font.Dispose(); * } * } * * context.Response.ContentType = "image/png"; * bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); * } * }*/ public static string generateCaptcha(HttpContext context, int length, randomType type, int width, int height, System.Drawing.Color top_color, System.Drawing.Color bottom_color, System.Drawing.Color text_color) { System.Drawing.Drawing2D.HatchBrush hatchBrush = null; string strCode = commonFunctions.generateRandom(length, type); commonVariables.SetSessionVariable("vCode", commonEncryption.encrypting(strCode)); string strProcessRemark = "CommonFunction:" + strCode; int intProcessSerialId = 0; intProcessSerialId += 1; commonAuditTrail.appendLog("system", "CommonFunction", "ParameterValidation", "DataBaseManager.DLL", "", "", "", "", strProcessRemark, Convert.ToString(intProcessSerialId), "", true); //context.Session["vCode"] = commonEncryption.encrypting(strCode); char[] char_array = null; char_array = new char[strCode.Length + strCode.Length]; for (int int_count = 0; int_count < strCode.Length; int_count++) { char_array[int_count + int_count] = strCode[int_count]; char_array[int_count + int_count + 1] = " "[0]; } //Captcha String System.Drawing.FontFamily fontFamily = new System.Drawing.FontFamily("Comic Sans MS"); // - Generate Random //int randomsize = 5; Random random = new Random(DateTime.Now.Millisecond); // Create a new 32-bit bitmap image. using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { // Create a graphics object for drawing. using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, width, height); // Fill in the background. using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.DiagonalCross, top_color, bottom_color)) { g.FillRectangle(hatchBrush, rect); // Set up the text font. System.Drawing.SizeF size = default(System.Drawing.SizeF); float fontSize = rect.Height + 25; System.Drawing.Font font = null; System.Drawing.StringFormat format = new System.Drawing.StringFormat(); format.Alignment = System.Drawing.StringAlignment.Center; format.LineAlignment = System.Drawing.StringAlignment.Center; // Adjust the font size until the text fits within the image. do { fontSize -= 5; font = new System.Drawing.Font(fontFamily, fontSize, System.Drawing.FontStyle.Bold); size = g.MeasureString(new string(char_array), font, new System.Drawing.SizeF(width, height), format); } while (size.Width > rect.Width); // Create a path using the text and warp it randomly. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(new string(char_array), font.FontFamily, Convert.ToInt32(font.Style), font.Size, rect, format); float v = 6f; System.Drawing.PointF[] points = { new System.Drawing.PointF(random.Next(rect.Width) / v, random.Next(rect.Height) / v), new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, random.Next(rect.Height) / v), new System.Drawing.PointF(random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v), new System.Drawing.PointF(rect.Width - random.Next(rect.Width) / v, rect.Height - random.Next(rect.Height) / v) }; System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); matrix.Translate(0f, 0f); path.Warp(points, rect, matrix, System.Drawing.Drawing2D.WarpMode.Perspective, 0f); // Draw the text. using (hatchBrush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal, text_color, text_color)) { g.FillPath(hatchBrush, path); } font.Dispose(); } } context.Response.ContentType = "image/png"; bitmap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png); return(strCode); } }
public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, int gripWidth) { StringFormat m_Format = new StringFormat(); m_Format.Alignment = StringAlignment.Near; m_Format.LineAlignment = StringAlignment.Near; Color start = InterpolateColors(appointment.Color, Color.White, 0.4f); Color end = InterpolateColors(appointment.Color, Color.FromArgb(191, 210, 234), 0.7f); if ((appointment.Locked)) { // Draw back using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Blue, appointment.Color)) g.FillRectangle(m_Brush, rect); // little transparent start = Color.FromArgb(230, start); end = Color.FromArgb(180, end); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, rect); } else { // Draw back using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, rect); } if (isSelected) { Rectangle m_BorderRectangle = rect; using (Pen m_Pen = new Pen(appointment.BorderColor, 4)) g.DrawRectangle(m_Pen, rect); m_BorderRectangle.Inflate(2, 2); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); m_BorderRectangle.Inflate(-4, -4); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); } else { // Draw gripper Rectangle m_GripRectangle = rect; m_GripRectangle.Width = gripWidth + 1; start = InterpolateColors(appointment.BorderColor, appointment.Color, 0.2f); end = InterpolateColors(appointment.BorderColor, Color.White, 0.6f); using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, m_GripRectangle); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, rect); // Draw shadow lines int xLeft = rect.X + 6; int xRight = rect.Right + 1; int yTop = rect.Y + 1; int yButton = rect.Bottom + 1; for (int i = 0; i < 5; i++) { using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black))) { g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical } } } rect.X += gripWidth; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.DrawString(appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, m_Format); g.TextRenderingHint = TextRenderingHint.SystemDefault; }
public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect) { if (appointment == null) { throw new ArgumentNullException("appointment"); } if (g == null) { throw new ArgumentNullException("g"); } /* * Logic for drawing the appointment: * 1) Do something messy with the colours * * 2) Determine background pattern * 2.1) App is locked -> HatchBrush * 2.2) Normal app -> Nothing * * 3) Draw the background of appointment * * 4) Draw the edges of appointment * 4.1) If app is selected -> just draw the selection rectangle * 4.2) If not -> draw the gripper, border (if required) and shadows */ if (rect.Width != 0 && rect.Height != 0) { using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; Color start = InterpolateColors(appointment.Color, Color.White, 0.4f); Color end = InterpolateColors(appointment.Color, Color.FromArgb(175, 50, 175), 0.7f); // if appointment is locked, draw different background pattern if ((appointment.Locked && !appointment.AllDayEvent)) { // Draw back using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LargeConfetti, Color.Pink, appointment.Color)) g.FillRectangle(m_Brush, rect); // little transparent start = Color.FromArgb(230, start); end = Color.FromArgb(180, end); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); } else if (appointment.UseCustomHatchStyle) { using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(appointment.CustomHatch, Color.Pink, appointment.Color)) g.FillRectangle(m_Brush, rect); // little transparent start = Color.FromArgb(230, start); end = Color.FromArgb(180, end); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); } // Draw the background of the appointment using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, rect); // If the appointment is selected, only need to draw the selection frame if (isSelected) { Rectangle m_BorderRectangle = rect; using (Pen m_Pen = new Pen(appointment.BorderColor, 3)) g.DrawRectangle(m_Pen, rect); m_BorderRectangle.Inflate(2, 2); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); m_BorderRectangle.Inflate(-4, -4); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); } else { // Draw gripper gripRect.Width += 1; start = BackColor; // InterpolateColors(appointment.BorderColor, appointment.BorderColor, 0.2f); end = BackColor; //InterpolateColors(appointment.BorderColor, appointment.BorderColor, 0.6f); using (LinearGradientBrush aGB = new LinearGradientBrush(rect, start, end, LinearGradientMode.Vertical)) g.FillRectangle(aGB, gripRect); // Draw border if needed if (appointment.DrawBorder) { using (Pen m_Pen = new Pen(Color.Pink, 1)) g.DrawRectangle(m_Pen, rect); } // Draw shadow lines int xLeft = rect.X + 6; int xRight = rect.Right + 1; int yTop = rect.Y + 1; int yButton = rect.Bottom + 1; for (int i = 0; i < 5; i++) { using (Pen shadow_Pen = new Pen(Color.FromArgb(70 - 12 * i, Color.Black))) { g.DrawLine(shadow_Pen, xLeft + i, yButton + i, xRight + i - 1, yButton + i); //horisontal lines g.DrawLine(shadow_Pen, xRight + i, yTop + i, xRight + i, yButton + i); //vertical } } } // draw appointment text rect.X += gripRect.Width; // width of shadow is 6. rect.Width -= 6; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; int oldRectY = rect.Y; if (dayView.AlwaysShowAppointmentText) { if ((rect.Height - rect.Y) > 100 && rect.Y < dayView.HeaderHeight) { if (rect.Y + dayView.HeaderHeight < rect.Height) { rect.Y = dayView.HeaderHeight; if ((rect.Y - oldRectY) > (rect.Height - 40)) { rect.Y = oldRectY; } } } } g.DrawString(appointment.Title, this.BaseFont, new SolidBrush(appointment.TextColor), rect, format); rect.Y = oldRectY; g.TextRenderingHint = TextRenderingHint.SystemDefault; //Partial Owner Draw Appointment Here DoAfterDrawAppointment(g, rect, appointment, isSelected, gripRect); } } }
public void FillRectangle(HatchStyle style, SolidColor hatchColor, SolidColor bgColor, float x, float y, float width, float height) { System.Drawing.Drawing2D.HatchBrush hb = this.resourceManager.GetHatchBrush(style, hatchColor, bgColor); this.g.FillRectangle(hb, x, y, width, height); }
/// <summary> /// Paints the drop-down, including all items within the scrolled region /// and, if appropriate, the scrollbar. /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (scrollBarVisible) { Rectangle upper = new Rectangle(scrollBar.DisplayRectangle.Left, scrollBar.DisplayRectangle.Top, scrollBar.DisplayRectangle.Width, scrollBar.Thumb.Top - scrollBar.DisplayRectangle.Top); Rectangle lower = new Rectangle(scrollBar.DisplayRectangle.Left, scrollBar.Thumb.Bottom, scrollBar.DisplayRectangle.Width, scrollBar.DisplayRectangle.Bottom - scrollBar.Thumb.Bottom); if (sourceControl.DrawWithVisualStyles && ScrollBarRenderer.IsSupported) { ScrollBarRenderer.DrawUpperVerticalTrack(e.Graphics, upper, GetScrollBarState(upper)); ScrollBarRenderer.DrawLowerVerticalTrack(e.Graphics, lower, GetScrollBarState(lower)); ScrollBarRenderer.DrawArrowButton(e.Graphics, scrollBar.UpArrow, GetScrollBarStateUp()); ScrollBarRenderer.DrawArrowButton(e.Graphics, scrollBar.DownArrow, GetScrollBarStateDown()); ScrollBarRenderer.DrawVerticalThumb(e.Graphics, scrollBar.Thumb, GetScrollBarThumbState()); ScrollBarRenderer.DrawVerticalThumbGrip(e.Graphics, scrollBar.Thumb, GetScrollBarThumbState()); } else { Rectangle bounds = scrollBar.DisplayRectangle; bounds.Offset(1, 0); Rectangle up = scrollBar.UpArrow; up.Offset(1, 0); Rectangle down = scrollBar.DownArrow; down.Offset(1, 0); Rectangle thumb = scrollBar.Thumb; thumb.Offset(1, 0); System.Drawing.Drawing2D.HatchBrush brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Percent50, SystemColors.ControlLightLight, SystemColors.Control); e.Graphics.FillRectangle(brush, bounds); ControlPaint.DrawScrollButton(e.Graphics, up, ScrollButton.Up, GetButtonState(scrollBar.UpArrow)); ControlPaint.DrawScrollButton(e.Graphics, down, ScrollButton.Down, GetButtonState(scrollBar.DownArrow)); ControlPaint.DrawButton(e.Graphics, thumb, ButtonState.Normal); } } for (int i = scrollOffset; i < (scrollOffset + numItemsDisplayed); i++) { bool highlighted = (highlightedItemIndex == i); NodeInfo item = visibleItems[i]; // background if (highlighted) { e.Graphics.FillRectangle(SystemBrushes.Highlight, item.DisplayRectangle); } // image and glyphs if (item.Image != null) { e.Graphics.DrawImage(item.Image, new Rectangle(item.DisplayRectangle.Location, item.Image.Size)); } Font font = new Font(Font, visibleItems[i].Node.FontStyle); Rectangle textBounds = new Rectangle(item.DisplayRectangle.X + item.Image.Width + 2, item.DisplayRectangle.Y, item.DisplayRectangle.Width - item.Image.Width - 4, itemHeight); TextRenderer.DrawText(e.Graphics, item.Node.Text, font, textBounds, highlighted ? SystemColors.HighlightText : ForeColor, TEXT_FORMAT_FLAGS); } }
void DrawTimeline(Graphics g, ref float yOffset) { float height = this.ClientRectangle.Height - SPLITTER_HEIGHT; _timelineRectangle = new RectangleF(0.0f, yOffset, this.ClientSize.Width, height); Maranate.Statistics.Block currentBlock = null; foreach (var block in StatisticsProcessor.Data.Blocks.Reverse <Maranate.Statistics.Block>()) { if ((currentBlock == null) && (block.StartFieldNumber <= FieldNumber)) { currentBlock = block; } } using (var font = new Font(this.Font.FontFamily, 10.0f, FontStyle.Bold)) { // Fill Show blocks using (var brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.LightUpwardDiagonal, Color.Gray, Color.Black)) { foreach (var block in StatisticsProcessor.Data.Blocks) { var isCommercial = ((block.IsCommercialOverride.HasValue) ? block.IsCommercialOverride.Value : block.IsCommercial); if (!isCommercial) { float x1 = (block.StartFieldNumber / (float)TotalFields) * this.ClientSize.Width; float x2 = (block.EndField.FieldNumber / (float)TotalFields) * this.ClientSize.Width; var cutPointRect = new RectangleF(x1, yOffset, x2 - x1, height); g.FillRectangle(brush, cutPointRect); } } } // Draw cut points foreach (var block in StatisticsProcessor.Data.Blocks) { var brush = Brushes.Brown; float x = (block.StartFieldNumber / (float)TotalFields) * this.ClientSize.Width; var cutPointRect = new RectangleF(x, yOffset, 1.0f, height); g.FillRectangle(brush, cutPointRect); g.DrawString(block.BlockNumber.ToString(), font, brush, cutPointRect.Location); } // Draw current cut point if (currentBlock != null) { var block = currentBlock; var brush = Brushes.Orange; float x = (block.StartFieldNumber / (float)TotalFields) * this.ClientSize.Width; var cutPointRect = new RectangleF(x, yOffset, 1.0f, height); g.FillRectangle(brush, cutPointRect); g.DrawString(block.BlockNumber.ToString(), font, brush, cutPointRect.Location); } // Draw visible markers if (_secondsVisible > 0.0) { var totalSeconds = (TotalFields / (float)FieldsPerSecond); var pixelsPerSecond = this.ClientSize.Width / totalSeconds; var pixelsVisibleOffset = _secondsVisible * pixelsPerSecond / 2.0; if (pixelsVisibleOffset > 10) { var pixelOffsetCurrent = (int)((FieldNumber / (float)TotalFields) * this.ClientSize.Width) + 1; var pixelOffsetStart = (int)(pixelOffsetCurrent - pixelsVisibleOffset); var pixelOffsetEnd = (int)(pixelOffsetCurrent + pixelsVisibleOffset); int size = 8; int bottom = (int)yOffset + (int)height - 0; var brush = Brushes.Wheat; using (var pen = new Pen(Color.FromArgb(255, 243, 222))) { g.DrawLine(pen, pixelOffsetStart, bottom - 1, pixelOffsetEnd, bottom - 1); if (pixelOffsetStart >= 0) { using (var path = new GraphicsPath()) { int x = (int)pixelOffsetStart; var pt1 = new Point(x, bottom - size); var pt2 = new Point(x + size, bottom); var pt3 = new Point(x, bottom); var points = new Point[] { pt2, pt3, pt1, pt2 }; path.AddLines(points); g.FillPath(brush, path); g.DrawPath(pen, path); } } if (pixelOffsetEnd <= this.ClientSize.Width) { using (var path = new GraphicsPath()) { int x = (int)pixelOffsetEnd; var pt1 = new Point(x, bottom - size); var pt2 = new Point(x, bottom); var pt3 = new Point(x - size, bottom); var points = new Point[] { pt2, pt3, pt1, pt2 }; path.AddLines(points); g.FillPath(brush, path); g.DrawPath(pen, path); } } } } } // Draw current position marker { using (var path = new GraphicsPath()) { int x = (int)((FieldNumber / (float)TotalFields) * this.ClientSize.Width) + 1; int bottom = (int)yOffset + (int)height - 0; int size = 8; var pt1 = new Point(x, bottom - size); var pt2 = new Point(x + size, bottom); var pt3 = new Point(x - size, bottom); var points = new Point[] { pt2, pt3, pt1, pt2 }; path.AddLines(points); g.FillPath(Brushes.Wheat, path); g.DrawPath(Pens.White, path); } } } yOffset += height; }
public override void DrawAppointment(Graphics g, Rectangle rect, AgendamentoDTO appointment, bool isSelected, Rectangle gripRect) { if (appointment == null) { throw new ArgumentNullException("appointment"); } if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width != 0 && rect.Height != 0) { using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; if ((appointment.Locked) && isSelected) { // Draw back using (Brush m_Brush = new System.Drawing.Drawing2D.HatchBrush(System.Drawing.Drawing2D.HatchStyle.Wave, Color.LightGray, appointment.Color)) g.FillRectangle(m_Brush, rect); } else { // Draw back using (SolidBrush m_Brush = new SolidBrush(appointment.Color)) g.FillRectangle(m_Brush, rect); } if (isSelected) { using (Pen m_Pen = new Pen(appointment.BorderColor, 4)) g.DrawRectangle(m_Pen, rect); Rectangle m_BorderRectangle = rect; m_BorderRectangle.Inflate(2, 2); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); m_BorderRectangle.Inflate(-4, -4); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, m_BorderRectangle); } else { // Draw gripper gripRect.Width += 1; using (SolidBrush m_Brush = new SolidBrush(appointment.BorderColor)) g.FillRectangle(m_Brush, gripRect); using (Pen m_Pen = new Pen(SystemColors.WindowFrame, 1)) g.DrawRectangle(m_Pen, rect); } //O que é impresso no retângulo rect.X += gripRect.Width; /*g.DrawString("Cliente: " + appointment.Cliente.Pessoa.NomePessoa, this.BaseFont, SystemBrushes.WindowText, rect, format); * g.DrawString("\nServiços: " + appointment.Title, this.BaseFont, SystemBrushes.WindowText, rect, format); * g.DrawString("\n\nObservações: " + appointment.Observacoes, this.BaseFont, SystemBrushes.WindowText, rect, format);*/ g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.DrawString("Cliente:", this.BaseFont2, Brushes.Black, rect, format); g.DrawString(" " + appointment.Cliente.Pessoa.NomePessoa, this.BaseFont, Brushes.Black, rect, format); g.DrawString("\nServiços:", this.BaseFont2, Brushes.Black, rect, format); g.DrawString("\n " + appointment.Title, this.BaseFont, Brushes.Black, rect, format); g.DrawString("\n\nObservações:", this.BaseFont2, Brushes.Black, rect, format); g.DrawString("\n\n " + appointment.Observacoes, this.BaseFont, Brushes.Black, rect, format); g.TextRenderingHint = TextRenderingHint.SystemDefault; } } }
protected void DrawLigne(Graphics g, bool bSelection) { Point[] pts = Points; if (pts.Length < 2) { List <Point> listePoints = new List <Point>(); Rectangle rectSize = new Rectangle(Position, Size); Point newPoint1 = new Point(rectSize.Left, rectSize.Top); Point newPoint2 = new Point(rectSize.Right, rectSize.Bottom); listePoints.Add(newPoint1); listePoints.Add(newPoint2); pts = listePoints.ToArray(); Points = pts; } if (Parent != null && bSelection) { for (int i = 0; i < pts.Length; i++) { pts[i] = Parent.ClientToGlobal(pts[i]); } } Brush b; if (m_hatchStyle != null) { b = new System.Drawing.Drawing2D.HatchBrush(m_hatchStyle.Value, ForeColor, BackColor); } else { b = new SolidBrush(BackColor); } Pen pen; if (bSelection) { pen = new Pen(Color.Red, 2); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; } else { pen = new Pen(ForeColor); pen.Width = LineWidth; pen.DashStyle = m_lineStyle; if (m_lineStyle == System.Drawing.Drawing2D.DashStyle.Custom) { pen.DashPattern = m_customDashPattern; } } if (m_bBezier) { if (pts.Length < 4 || ((pts.Length - 4) % 3 != 0)) { List <Point> listePoints = new List <Point>(pts); while (listePoints.Count < 4 || ((listePoints.Count - 4) % 3 != 0)) { listePoints.Add(pts[pts.Length - 1]); } Point[] tabBezier = listePoints.ToArray(); g.DrawBeziers(pen, tabBezier); } else { g.DrawBeziers(pen, pts); } } else { if (m_bClosed) { g.FillPolygon(b, pts); } Point previousPoint = pts[0]; //dessin du premier segment de la ligne if (!m_bClosed) { pen.StartCap = m_startCap; } //dessin de la flèche de début si la ligne n'est pas fermée //dessin de la flèche de fin si l'on n'a que deux points if (!m_bClosed && (pts.Length == 2)) { pen.EndCap = m_endCap; } g.DrawLine(pen, previousPoint, pts[1]); //dessin des segments intermédiaires (toujours sans flèche) pen.StartCap = LineCap.Flat; if (m_arrayPoints.Count > 3) { for (int i = 1; i < pts.Length - 1; i++) { g.DrawLine(pen, previousPoint, pts[i]); previousPoint = pts[i]; } } //dessin du dernier segment (avec la flèche de fin) if (m_arrayPoints.Count > 2) { if (!m_bClosed) { pen.EndCap = m_endCap; } g.DrawLine(pen, pts[pts.Length - 2], pts[pts.Length - 1]); } //on ferme la forme si la ligne est fermée if (m_bClosed) { g.DrawLine(pen, pts[pts.Length - 1], pts[0]); } } pen.Dispose(); }
static int RunAndReturnExitCode(Options opts) { if (!Directory.Exists(opts.OutputPath)) { Directory.CreateDirectory(opts.OutputPath); } CASCHandler cascHandler; if (opts.UseOnline) { cascHandler = CASCHandler.OpenOnlineStorage(opts.OnlineProduct, opts.OnlineRegion); } else if (opts.StoragePath != null) { cascHandler = CASCHandler.OpenLocalStorage(opts.StoragePath); } else { throw new Exception("StoragePath required if not using online mode!"); } cascHandler.Root.SetFlags(LocaleFlags.All_WoW, ContentFlags.None); foreach (var map in opts.Maps) { try { Console.WriteLine("-- processing {0}", map); System.Drawing.Bitmap[,] tiles = new System.Drawing.Bitmap[64, 64]; bool[,] had_tile = new bool[64, 64]; bool[,] wdt_claims_tile = new bool[64, 64]; var wdt_name = Path.Combine("world", "maps", map, String.Format("{0}.wdt", map)); try { using (Stream stream = cascHandler.OpenFile(wdt_name)) { using (BinaryReader reader = new BinaryReader(stream)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { var magic = reader.ReadUInt32(); var size = reader.ReadUInt32(); var pos = reader.BaseStream.Position; if (magic == mk("MPHD")) { var flags = reader.ReadUInt32(); if ((flags & 1) == 1) { throw new Exception("map claims to be WMO only, skipping!"); } } else if (magic == mk("MAIN")) { for (int x = 0; x < 64; ++x) { for (int y = 0; y < 64; ++y) { wdt_claims_tile[y, x] = (reader.ReadUInt32() & 1) == 1; reader.ReadUInt32(); } } } reader.BaseStream.Position = pos + size; } } } } catch (FileNotFoundException) { throw new Exception(String.Format("failed loading {0}, skipping!", wdt_name)); } var tile_size = 256; for (int x = 0; x < 64; ++x) { for (int y = 0; y < 64; ++y) { had_tile[x, y] = false; try { var blp_name = Path.Combine("world", "minimaps", map, String.Format("map{0:00}_{1:00}.blp", x, y)); using (Stream stream = cascHandler.OpenFile(blp_name)) { var blp = new SereniaBLPLib.BlpFile(stream); tiles[x, y] = blp.GetBitmap(0); if (tiles[x, y].Height != tiles[x, y].Width) { throw new Exception("non-square minimap?!"); } } had_tile[x, y] = true; } catch (FileNotFoundException) { tiles[x, y] = new System.Drawing.Bitmap(tile_size, tile_size); } var size_per_mcnk = tiles[x, y].Height / 16f; var g = System.Drawing.Graphics.FromImage(tiles[x, y]); var impassable_brush = new System.Drawing.Drawing2D.HatchBrush (System.Drawing.Drawing2D.HatchStyle.DiagonalCross , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.Yellow) , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.Red) ); var wdt_border_brush = new System.Drawing.Drawing2D.HatchBrush (System.Drawing.Drawing2D.HatchStyle.DiagonalCross , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.DarkBlue) , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.Red) ); var wdt_border_pen = new System.Drawing.Pen (wdt_border_brush, size_per_mcnk); var unreferenced_brush = new System.Drawing.Drawing2D.HatchBrush (System.Drawing.Drawing2D.HatchStyle.DiagonalCross , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.DarkBlue) , System.Drawing.Color.FromArgb(255 / 2, System.Drawing.Color.Green) ); try { var adt_name = Path.Combine("World", "Maps", map, String.Format("{0}_{1}_{2}.adt", map, x, y)); using (Stream stream = cascHandler.OpenFile(adt_name)) { using (BinaryReader reader = new BinaryReader(stream)) { while (reader.BaseStream.Position != reader.BaseStream.Length) { var magic = reader.ReadUInt32(); var size = reader.ReadUInt32(); var pos = reader.BaseStream.Position; if (magic == mk("MCNK")) { var flags = reader.ReadUInt32(); var sub_x = reader.ReadUInt32(); var sub_y = reader.ReadUInt32(); if ((flags & 2) == 2) { g.FillRectangle(impassable_brush, size_per_mcnk * sub_x, size_per_mcnk * sub_y, size_per_mcnk, size_per_mcnk); } } reader.BaseStream.Position = pos + size; } } } had_tile[x, y] = true; } catch (FileNotFoundException) { g.FillRectangle(wdt_border_brush, 0, 0, tiles[x, y].Height, tiles[x, y].Height); } if (wdt_claims_tile[x, y]) { if (x == 0 || !wdt_claims_tile[x - 1, y]) { g.DrawLine(wdt_border_pen, 0, 0, 0, tiles[x, y].Height); } if (x == 63 || !wdt_claims_tile[x + 1, y]) { g.DrawLine(wdt_border_pen, tiles[x, y].Height, 0, tiles[x, y].Height, tiles[x, y].Height); } if (y == 0 || !wdt_claims_tile[x, y - 1]) { g.DrawLine(wdt_border_pen, 0, 0, tiles[x, y].Height, 0); } if (y == 63 || !wdt_claims_tile[x, y + 1]) { g.DrawLine(wdt_border_pen, 0, tiles[x, y].Height, tiles[x, y].Height, tiles[x, y].Height); } } else if (had_tile[x, y]) { g.FillRectangle(unreferenced_brush, 0, 0, tiles[x, y].Height, tiles[x, y].Height); } } } int min_x = 64; int min_y = 64; int max_x = -1; int max_y = -1; for (int x = 0; x < 64; ++x) { for (int y = 0; y < 64; ++y) { if (had_tile[x, y]) { min_x = Math.Min(min_x, x); min_y = Math.Min(min_y, y); max_x = Math.Max(max_x, x + 1); max_y = Math.Max(max_y, y + 1); } } } var overall = new System.Drawing.Bitmap(tile_size * (max_x - min_x), tile_size * (max_y - min_y)); var overall_graphics = System.Drawing.Graphics.FromImage(overall); for (int x = min_x; x <= max_x; ++x) { for (int y = min_y; y <= max_y; ++y) { if (had_tile[x, y]) { overall_graphics.DrawImage(tiles[x, y], (x - min_x) * tile_size, (y - min_y) * tile_size, tile_size, tile_size); } } } var output_file = Path.Combine(opts.OutputPath, String.Format("{0}.png", map)); System.IO.File.Delete(output_file); overall.Save(output_file, System.Drawing.Imaging.ImageFormat.Png); } catch (Exception ex) { Console.WriteLine("--- {0}", ex.Message); } } return(0); }