void EDSToolTip_Draw(object sender, DrawToolTipEventArgs e) { if (e.ToolTipText.Trim() != "") { //e.DrawBackground(); Graphics g = e.Graphics; //draw background LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(Point.Empty, e.Bounds.Size), Color.FromArgb(250, 252, 253), Color.FromArgb(206, 220, 240), LinearGradientMode.Vertical); g.FillRectangle(lgb, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); lgb.Dispose(); //Console.WriteLine(e.ToolTipText); //draw border ControlPaint.DrawBorder(g, e.Bounds, SystemColors.GrayText, ButtonBorderStyle.Dashed); //draw Image g.DrawImage(image, new Point(5, 5)); // Draw the custom text. // The using block will dispose the StringFormat automatically. using (StringFormat sf = new StringFormat()) { using (Font f = new Font("Tahoma", 8)) { e.Graphics.DrawString(e.ToolTipText, f, Brushes.Black, e.Bounds.X + 25, e.Bounds.Y + 30, StringFormat.GenericTypographic); } } } }
/// <summary> /// Draws the Card at its location /// </summary> /// <param name="g">The Graphics object to draw on</param> public override void Draw(Graphics g) { Color colour = this.GetColor(); g.FillRectangle(new SolidBrush(colour), _rekt); // Fill if (Selected) { g.DrawRectangle(new Pen(Brushes.Black, 2), _rekt); // Draw outline } else { g.DrawRectangle(new Pen(Brushes.White, 4), _rekt); // White 4pt g.DrawRectangle(new Pen(Brushes.Black, 1), _rekt); // Black border 1pt } // The number int fontHeight = _rekt.Height / 4; Font arial = new Font("Arial", fontHeight, FontStyle.Bold); // Fancy Centering StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; g.DrawString(this.Value.ToString(), arial, Brushes.Black, _rekt, stringFormat); // Black text (the number) }
public abstract void DrawString( string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format );
/// <summary> /// �������˵��� /// </summary> public static void DrawMenuItem(System.Windows.Forms.DrawItemEventArgs e, MenuItem mi) { if ( (e.State & DrawItemState.HotLight) == DrawItemState.HotLight ) { DrawHoverRect(e, mi); } else if ( (e.State & DrawItemState.Selected) == DrawItemState.Selected ) { DrawSelectionRect(e, mi); } else { Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height -1); e.Graphics.FillRectangle(new SolidBrush(Globals.MainColor), rect); e.Graphics.DrawRectangle(new Pen(Globals.MainColor), rect); } StringFormat sf = new StringFormat(); //�������־��� sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; //�������� e.Graphics.DrawString(mi.Text, Globals.menuFont, new SolidBrush(Globals.TextColor), e.Bounds, sf); }
public override void DrawAppointment(Graphics g, Rectangle rect, Appointment appointment, bool isSelected, Rectangle gripRect, bool enableShadows, bool useroundedCorners) { 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); } rect.X += gripRect.Width; g.DrawString(appointment.Subject, this.BaseFont, SystemBrushes.WindowText, rect, format); } }
private static Bitmap GetEyeOfSightImage() { var roestte = new Bitmap(120, 120); //Anyone for a more sophisticated roestte? using (var g = Graphics.FromImage(roestte)) { var t = new Matrix(1f, 0f, 0f, 1f, 60, 60); g.Transform = t; var f = new Font("Arial", 20, FontStyle.Bold); var b = new SolidBrush(Color.Black); var p = new Pen(Color.Black, 5); var sf = new StringFormat(StringFormat.GenericTypographic) {Alignment = StringAlignment.Center}; var rect = new RectangleF(- 45f, - 45f, 90f, 90f); foreach (var s in Directions) { g.DrawString(s, f, b, 0, -55, sf); g.DrawArc(p, rect, 290f, 50f); g.RotateTransform(90f); } } return roestte; }
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(); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { //base.OnPaint(e); Graphics g = e.Graphics; g.Clear(this.Parent.BackColor); g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rect = new Rectangle(Point.Empty, e.ClipRectangle.Size); rect.Width -= 1; rect.Height -= 1; Color coutBorder; Color cinnerBorder; Color cbackgroundTop; Color cbackgroundBottom; Color ctext; if (mouseover) { coutBorder = ButtonColor.HoverOutBorder; cinnerBorder = ButtonColor.HoverInnerBorder; cbackgroundTop = ButtonColor.HoverBackgroundTop; cbackgroundBottom = ButtonColor.HoverBackgroundBottom; ctext = mousedown ? Color.Black : ButtonColor.HoverText; } else { coutBorder = ButtonColor.OutBorder; cinnerBorder = ButtonColor.InnerBorder; cbackgroundTop = ButtonColor.BackgroundTop; cbackgroundBottom = ButtonColor.BackgroundBottom; ctext = ButtonColor.Text; } using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(rect, 2)) { using (LinearGradientBrush lgBrush = new LinearGradientBrush(Point.Empty, new Point(rect.Width, rect.Height), cbackgroundTop, cbackgroundBottom)) { g.FillPath(lgBrush, path); } g.DrawPath(new Pen(coutBorder), path); rect.Inflate(-1, -1); using (GraphicsPath path2 = GraphicsTools.CreateRoundRectangle(rect, 2)) { g.DrawPath(new Pen(cinnerBorder), path2); } } StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; g.DrawString(this.Text, this.Font, new SolidBrush(ctext), e.ClipRectangle, sf); UpdateBounds(this.Location.X, this.Location.Y, this.Width, this.Height, e.ClipRectangle.Width, e.ClipRectangle.Height); }
public void Text(string text, Font font, uint argb, Rectangle rect, StringFormat format) { graphics.DrawString( text, font, new SolidBrush(argb.ToColor()), rect, format); }
public BaseTextItem():base() { this.dataType = "System.String"; this.stringFormat = StringFormat.GenericTypographic; this.contentAlignment = ContentAlignment.TopLeft; this.stringTrimming = StringTrimming.None; VisibleInReport = true; }
public CommunicationVisualizer(SharpNeatLib.CPPNs.SubstrateDescription _sd, ModularNetwork _net) { InitializeComponent(); //zlevel = _zlevel; drawFont = new System.Drawing.Font("Arial", 8); drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); drawFormat = new System.Drawing.StringFormat(); sd = _sd; net = _net; _net.UpdateNetworkEvent += networkUpdated; activation = new activationLevels[200]; // outgoingActivation = new List<float>[200]; for (int i = 0; i < activation.Length; i++) { activation[i] = new activationLevels(); //outgoingActivation[i] = new List<float>(); } penConnection = new Pen(Color.Black); penRed = new Pen(Color.Red); this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); }
public DiffViewer(TaskScheduler scheduler, HeapRecording instance) : base(scheduler) { InitializeComponent(); ListFormat = new StringFormat { Trimming = StringTrimming.None, FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox }; Timeline.ItemValueGetter = GetBytesTotal; Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes; Instance = instance; if (Instance != null) { Timeline.Items = Instance.Snapshots; Instance.TracebacksFiltered += Instance_TracebacksFiltered; ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = true; ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = true; ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = true; } else { Timeline.Visible = false; MainSplit.Height += Timeline.Bottom - MainSplit.Bottom; ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = false; ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = false; ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = false; } }
/// <summary> /// Print header /// </summary> /// <param name="g">Graphics object where the data will be drawn</param> /// <param name="area">Area where to print</param> /// <param name="columns">Columns</param> public override void Print(Graphics g, ref RectangleF area, IList columns, int page) { StringFormat stringFormat; float height; stringFormat = new StringFormat(StringFormat.GenericDefault); height = font.GetHeight(g); // Write columns label foreach (Column column in columns) { RectangleF rect; stringFormat.Alignment = column.Alignment; rect = new RectangleF( column.X, area.Top, column.Width, height); g.DrawString( column.Label, font, brush, rect, stringFormat); } // Draw separator line g.DrawLine(pen, area.Left, area.Top + height + lineDistance, area.Right, area.Top + height + lineDistance); area.Y += height + lineDistance * 2; area.Height -= height + lineDistance * 2; }
static TextBoxTextRenderer () { // On Windows, we want to use TextRenderer (GDI) // On Linux, we want to use DrawString (GDI+) // TextRenderer provides translation from TextRenderer to // DrawString, but I doubt it's exact enough. // Another option would be to put Pango here for Linux. int platform = (int)Environment.OSVersion.Platform; if (platform == 4 || platform == 128 || platform == 6) use_textrenderer = false; else use_textrenderer = true; // windows 2000 doesn't draw with gdi if bounds are In32.MaxValue max_size = new Size (Int16.MaxValue, Int16.MaxValue); sf_nonprinting = new StringFormat (StringFormat.GenericTypographic); sf_nonprinting.Trimming = StringTrimming.None; sf_nonprinting.FormatFlags = StringFormatFlags.DisplayFormatControl; sf_nonprinting.HotkeyPrefix = HotkeyPrefix.None; sf_printing = StringFormat.GenericTypographic; sf_printing.HotkeyPrefix = HotkeyPrefix.None; measure_cache = new Hashtable (); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Method to watermark image /// </summary> /// /// <remarks> Ken Hofgesang, 5/7/2012 </remarks> /// /// <param name="ImgPath"> Path for Source Image. </param> /// <param name="watermark"> String for watermark information. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public static Bitmap WaterMarkerImage(string ImgPath, string watermark) { Bitmap bmp; bmp = new Bitmap(ImgPath); Graphics graphicsObject; int x, y; try { //Create graphics object from bitmap graphicsObject = Graphics.FromImage(bmp); } catch (Exception e) { //Initilize new Bitmap for watermark info Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height); graphicsObject = Graphics.FromImage(bmpNew); graphicsObject.DrawImage(bmp, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel); bmp = bmpNew; } //Adjust font size based on original image size and the length of watermark text int startsize = (bmp.Width / watermark.Length); //x and y cordinates to draw watermark string x = 0; y = bmp.Height / 4; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.NoWrap); //Draw watermark on Image graphicsObject.DrawString(watermark, new Font("Times New Roman", startsize, FontStyle.Bold), new SolidBrush(Color.FromArgb(60, 255, 255, 255)), x, y, drawFormat); //return Image return (bmp); }
internal static CCTexture2D CreateNativeLabel(string text, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, string fontName, float fontSize, CCColor4B textColor) { if (string.IsNullOrEmpty(text)) { return new CCTexture2D(); } var font = CreateFont (fontName, fontSize); if (dimensions.Equals(CCSize.Zero)) { CreateBitmap(1, 1); var ms = _graphics.MeasureString(text, font); dimensions.Width = ms.Width; dimensions.Height = ms.Height; } CreateBitmap((int)dimensions.Width, (int)dimensions.Height); var stringFormat = new StringFormat(); switch (hAlignment) { case CCTextAlignment.Left: stringFormat.Alignment = StringAlignment.Near; break; case CCTextAlignment.Center: stringFormat.Alignment = StringAlignment.Center; break; case CCTextAlignment.Right: stringFormat.Alignment = StringAlignment.Far; break; } switch (vAlignment) { case CCVerticalTextAlignment.Top: stringFormat.LineAlignment = StringAlignment.Near; break; case CCVerticalTextAlignment.Center: stringFormat.LineAlignment = StringAlignment.Center; break; case CCVerticalTextAlignment.Bottom: stringFormat.LineAlignment = StringAlignment.Far; break; } _graphics.DrawString(text, font, _brush, new RectangleF(0, 0, dimensions.Width, dimensions.Height), stringFormat); _graphics.Flush(); var texture = new CCTexture2D(); texture.InitWithStream (SaveToStream(), Microsoft.Xna.Framework.Graphics.SurfaceFormat.Bgra4444); return texture; }
public static void RepertoryImage(Graphics drawDestination) { StringFormat itemStringFormat = new StringFormat(); RectangleF itemBox = new RectangleF(10, 30, 42, 10); RectangleF itemBox2 = new RectangleF(60, 48, 10, 10); itemStringFormat.Alignment = StringAlignment.Center; itemStringFormat.LineAlignment = StringAlignment.Far; drawDestination.DrawLine(Pens.LightGray,10,10,10,70); if (mMscStyle == MscStyle.SDL){ PointF[] capPolygon = new PointF[3]; capPolygon[0] = new PointF(61, 40); capPolygon[1] = new PointF(53, 44); capPolygon[2] = new PointF(53, 36); drawDestination.FillPolygon(Brushes.Black,capPolygon); drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat); drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat); drawDestination.DrawLine(Pens.Black,10, 40, 60,40); drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10)); } else if(mMscStyle == MscStyle.UML2){ drawDestination.DrawString("Lost",new Font("Arial",8),Brushes.Black,itemBox,itemStringFormat); drawDestination.DrawString("g",new Font("Arial",8),Brushes.Black,itemBox2,itemStringFormat); drawDestination.DrawLine(Pens.Black,10, 40, 60,40); drawDestination.DrawLine(Pens.Black,60, 40, 54,43); drawDestination.DrawLine(Pens.Black,60, 40, 54,37); drawDestination.FillEllipse(Brushes.Black, new RectangleF(60,35, 10,10)); } itemStringFormat.Dispose(); }
/// <summary>Override for the drawing of the control to include a Close Tab button</summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { RectangleF tabTextArea = RectangleF.Empty; for(int nIndex = 0 ; nIndex < this.TabCount ; nIndex++) { tabTextArea = (RectangleF)this.GetTabRect(nIndex); using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].BackColor)) { //Clear the tab e.Graphics.FillRectangle(brush, tabTextArea); } Bitmap bmp = nIndex == this.SelectedIndex ? Resources.activeClose : Resources.inactiveClose; e.Graphics.DrawImage(bmp, tabTextArea.X + tabTextArea.Width - (CLOSE_ICON_PADDING + CLOSE_ICON_SIZE), tabTextArea.Y + CLOSE_ICON_PADDING, CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); bmp.Dispose(); string str = this.TabPages[nIndex].Text; StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; using(SolidBrush brush = new SolidBrush(this.TabPages[nIndex].ForeColor)) { //Draw the tab header text e.Graphics.DrawString(str, this.Font, brush, tabTextArea,stringFormat); } } }
/// <summary> /// 主要作業方法 /// </summary> public Image Operation() { Graphics g = Graphics.FromImage(image); _mask_pos_x = (image.Width / 2) + _Xoffset; SizeF steSize = new SizeF(); for (int i = _FontMaxSize; i >= _FontMinSize; i--) { using (Font testFont = new Font(_FontFamily, i, FontStyle.Bold)) { steSize = g.MeasureString(_text, testFont); if ((ushort)steSize.Width < (ushort)_Width || i == _FontMinSize) { using (SolidBrush semiTransBrush = new SolidBrush(_fontcolor)) { StringFormat StrFormat = new StringFormat(); StrFormat.Alignment = StringAlignment.Center; g.DrawString(_text, testFont, semiTransBrush, new PointF(_mask_pos_x, _mask_pos_y), StrFormat); semiTransBrush.Dispose(); } testFont.Dispose(); break; } } } return image; }
public void Render(Graphics g, Point graphStart) { int graphBaseWidth = 400; int graphRange = (int)Math.Abs(MinRange - MaxRange); int graphHeight = 80; Pen graphColor = new Pen(Color.DeepPink, 3); g.DrawLine(graphColor, graphStart.X, graphStart.Y, graphStart.X, graphStart.Y + graphHeight); g.DrawLine(graphColor, graphStart.X, graphStart.Y + graphHeight, graphStart.X + graphBaseWidth, graphStart.Y + graphHeight); foreach (KeyValuePair <string, FuzzySet> f in MemberSets) { f.Value.Render(g, graphStart, graphBaseWidth, graphHeight, graphRange); } for (int i = 0; i < 11; i++) { g.DrawEllipse(new Pen(Color.Red), graphStart.X + (i * (graphBaseWidth / 10)) - 1, graphStart.Y + graphHeight - 1, 2, 2); g.DrawLine(new Pen(Color.Red), graphStart.X + (i * (graphBaseWidth / 10)), graphStart.Y + graphHeight, graphStart.X + (i * (graphBaseWidth / 10)), graphStart.Y); string drawString = ((graphRange / 10) * i).ToString(); System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 8); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float x = graphStart.X + (i * (graphBaseWidth / 10)); float y = graphStart.Y + graphHeight + 7; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); g.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat); drawFont.Dispose(); drawBrush.Dispose(); } }
private static void FligranEkle(draw.Bitmap bmp) { draw.Graphics graf = draw.Graphics.FromImage(bmp); draw.SolidBrush firca = new draw.SolidBrush(draw.Color.FromArgb(25, 0, 0, 0)); double kosegen = Math.Sqrt(bmp.Width * bmp.Width + bmp.Height * bmp.Height); draw.Rectangle kutu = new draw.Rectangle(); kutu.X = (int)(kosegen / 10); float yazi = (float)(kosegen / "histudymalta.com".Length * 1.2); kutu.Y = -(int)(yazi / 1.2); draw.Font fnt = new draw.Font("times new roman", yazi, draw.FontStyle.Bold);//font tipi ve boyutu float egim = (float)(Math.Atan2(bmp.Height, bmp.Width) * 180 / System.Math.PI); graf.RotateTransform(egim); draw.StringFormat sf = new draw.StringFormat(); graf.DrawString("histudymalta.com", fnt, firca, kutu, sf); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> the Draw method. </summary> /// /// <remarks> Tony Davidson, 2018-03-28. </remarks> /// /// <param name="graphics"> The graphics object. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public override void Draw(Graphics graphics) { formGraphics = graphics; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); formGraphics.DrawString(text, font, brush, startPoint.X, startPoint.Y, drawFormat); }
// listbox的表现效果,也许Qt和WPF可以写的很简单 private void fileListBox_DrawItem(object sender, DrawItemEventArgs e) { Color foreColor; Font font; e.DrawBackground(); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {//如果当前行为选中行。 //绘制选中时要显示的蓝色边框。 Color c = SystemColors.ControlDark; foreColor = Color.Black; //Color.FromArgb(6, 82, 121); font = new Font("黑体", 11, FontStyle.Bold); e.Graphics.FillRectangle(new SolidBrush(c), e.Bounds); //绘制背景 } else { font = e.Font; foreColor = e.ForeColor; } // e.DrawFocusRectangle(); StringFormat strFmt = new System.Drawing.StringFormat(); strFmt.Alignment = StringAlignment.Center; //文本垂直居中 strFmt.LineAlignment = StringAlignment.Center; //文本水平居中 e.Graphics.DrawString(fileListBox.Items[e.Index].ToString(), font, new SolidBrush(foreColor), e.Bounds, strFmt); }
protected override void OnPaint(PaintEventArgs e) { int y = Math.Max(0, (base.ClientRectangle.Height - 2) / 2); int x = 0; string text = base.Text; if (!string.IsNullOrEmpty(text)) { x = (int)Math.Ceiling((double)(e.Graphics.MeasureString(text, base.Font).Width)); using (SolidBrush brush = new SolidBrush(textColor)) using (var sformat = new StringFormat()) { sformat.Alignment = StringAlignment.Near; sformat.LineAlignment = StringAlignment.Center; RectangleF rectf = new RectangleF( 0f, 0f, (float)base.ClientRectangle.Width, (float)base.ClientRectangle.Height); e.Graphics.DrawString(text, base.Font, brush, rectf, sformat); } } // NB : -1f indique que le crayon fait exactement 1 pixel d'épaisseur using (Pen p1 = new Pen(color1, -1f)) e.Graphics.DrawLine(p1, x, y, ClientRectangle.Width, y); using (Pen p2 = new Pen(color2, -1f)) e.Graphics.DrawLine(p2, x, y + 1, ClientRectangle.Width, y + 1); }
static public Rect Rect(string text, Emugen.Image.Primitive.Font efont, PointF position) { var frameSize = 0.0; var frameSizeMax = 0.0; var rfontFrames = new List <Emugen.Image.Primitive.Font.FontFrame>(); foreach (var frame in efont.fontFrames) { frameSizeMax += frame.size / 2; rfontFrames.Insert(0, frame); } frameSize = frameSizeMax; // Todo : フォントフレームの幅分だけマージンの対応が必要 var margin = (int)System.Math.Floor(frameSize + subMargin); var font = CreateFont(efont.fontPath, efont.fontSize); var emFontFize = (float)font.Height * font.FontFamily.GetEmHeight(font.Style) / font.FontFamily.GetLineSpacing(font.Style); var stringFormat = new System.Drawing.StringFormat(); // 描画 var path = new System.Drawing.Drawing2D.GraphicsPath(); path.AddString(text, font.FontFamily, (int)font.Style, emFontFize, //path.AddString(text, font.FontFamily, (int)font.Style, (float)efont.fontSize, new System.Drawing.PointF((float)(position.X), (float)(position.Y)), stringFormat); var bound = path.GetBounds(); //var result = new Rect(new Vector2D(bound.X - margin, bound.Y - margin), new Vector2D(bound.Width + margin * 2, bound.Height + margin * 2)); var result = new Rect(new Vector2D(bound.X, bound.Y), new Vector2D(bound.Width, bound.Height)); return(result); }
/// <summary> /// <see cref="Control.OnPaint"/> /// </summary> protected override void OnPaint(PaintEventArgs pe) { StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Center; string panValue; if(pan == 0.0) { pe.Graphics.FillRectangle(Brushes.Orange,(this.Width/2) - 1 ,1,3,this.Height-2); panValue = "C"; } else if(pan > 0) { pe.Graphics.FillRectangle(Brushes.Orange,(this.Width/2),1,(int) ((this.Width/2) * pan),this.Height-2); panValue = String.Format("{0:F0}%R",pan*100); } else { pe.Graphics.FillRectangle(Brushes.Orange,(int)((this.Width/2) * (pan+1)),1,(int) ((this.Width/2) * (0-pan)),this.Height-2); panValue = String.Format("{0:F0}%L",pan*-100); } pe.Graphics.DrawRectangle(Pens.Black,0,0,this.Width-1,this.Height-1); pe.Graphics.DrawString(panValue,this.Font, Brushes.Black,this.ClientRectangle,format); // Calling the base class OnPaint //base.OnPaint(pe); }
public static RectangleF MeasureDisplayStringF(Graphics graphics, string text, Font font, int width, int height) { if (text == string.Empty || text == null) { return(new RectangleF(0, 0, 0, 0)); } System.Drawing.StringFormat format = new System.Drawing.StringFormat(); System.Drawing.RectangleF rect = new System.Drawing.RectangleF(0, 0, width, height); System.Drawing.CharacterRange[] ranges = { new System.Drawing.CharacterRange(0, text.Length) }; System.Drawing.Region[] regions = new System.Drawing.Region[1]; format.SetMeasurableCharacterRanges(ranges); regions = graphics.MeasureCharacterRanges(text, font, rect, format); rect = regions[0].GetBounds(graphics); //cleanup format.Dispose(); ranges = null; regions[0].Dispose(); regions = null; return(rect); }
private void DrawCaption(Graphics gfx, string text, Brush brush, RectangleF layoutRect, bool showAccelerator, bool shortCut, bool isEnabled) { System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); sf.FormatFlags = StringFormatFlags.NoWrap; sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide; sf.LineAlignment = StringAlignment.Center; if (showAccelerator) { sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; } if (shortCut) { SizeF size = gfx.MeasureString(text, m_font); layoutRect.X = layoutRect.Width - size.Width - textToEdgeSeparatorWidth; sf.Alignment = StringAlignment.Near; } else { sf.Alignment = StringAlignment.Near; } if (isEnabled) { gfx.DrawString(text, m_font, brush, layoutRect, sf); } else { Brush disabledBrush = SystemBrushes.ControlDark; gfx.DrawString(text, m_font, disabledBrush, layoutRect, sf); //ControlPaint.DrawStringDisabled(gfx, text, m_font, // Color.FromKnownColor(KnownColor.ControlDark), layoutRect, sf); } }
public override bool DrawString( System.Drawing.Graphics graphics, System.Drawing.FontFamily fontFamily, System.Drawing.FontStyle fontStyle, int fontSize, string strText, System.Drawing.Point ptDraw, System.Drawing.StringFormat strFormat) { using (GraphicsPath path = new GraphicsPath()) { path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat); using (Pen pen = new Pen(m_clrOutline, m_nThickness)) { pen.LineJoin = LineJoin.Round; graphics.DrawPath(pen, path); } if (m_bClrText) { using (SolidBrush brush = new SolidBrush(m_clrText)) { graphics.FillPath(brush, path); } } else { graphics.FillPath(m_brushText, path); } } return(true); }
private void frameBox_Paint(object sender, PaintEventArgs e) { int markerSize = 5; // put digitized points on the images if (CurrentHotFrame != null) { Feature features = CurrentHotFrame.Features.Find(x => x.DataStream == dataStream); if (features != null) { ImageFeature imageFeature = features as ImageFeature; using (Pen pen = new Pen(new SolidBrush(Color.Red), 1)) { System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 12); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); foreach (ImagePoint pt in imageFeature.Points) { Point pti = frameBox.GetOffsetPoint(pt.GetPoint()); //e.Graphics.DrawLine(pen, new Point(pti.X, pti.Y), new Point(pti.X+10, pti.Y)); e.Graphics.DrawLine(pen, pti.X - markerSize, pti.Y, pti.X + markerSize, pti.Y); e.Graphics.DrawLine(pen, pti.X, pti.Y - markerSize, pti.X, pti.Y + markerSize); e.Graphics.DrawString(pt.ID.ToString(), drawFont, drawBrush, pti.X + markerSize / 2, pti.Y + markerSize / 2, drawFormat); } } } } }
private void Create39BarCode(string binCode) { System.Drawing.Bitmap image = new System.Drawing.Bitmap(380, 190); Graphics g = Graphics.FromImage(image); try { //清空图片背景色 g.Clear(Color.White); Font font = new System.Drawing.Font("3 of 9 Barcode", 45); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); g.DrawString("*" + binCode + "*", font, drawBrush, 10, 40, drawFormat); g.DrawString(binCode, new Font("宋体", 26, System.Drawing.FontStyle.Bold), drawBrush, 110, 100, drawFormat); 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(); } }
private void DrawOtherInfo(Graphics g) { using (Pen p = new Pen(Color.Black, 2)) { g.DrawRectangle(p, new Rectangle(654, 140, 289, 145)); g.DrawRectangle(p, new Rectangle(949, 140, 179, ((dv1.Rows.Count + 9) * 20) + 5)); g.DrawRectangle(p, new Rectangle(39, 300, 905, ((dv1.Rows.Count + 1) * 20) + 5)); //g.DrawRectangle(p, new Rectangle(39, 745, 905, 40)); } using (Font f = new Font("Calibri", 11, FontStyle.Bold)) { System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; // g.DrawString("Тип: Квалификация", f, Brushes.Black, 50, 755); g.DrawString("Лучший результат месяца", f, Brushes.Black, new Rectangle(654, 140, 289, 20), drawFormat); g.DrawString("Лучший результат дня", f, Brushes.Black, new Rectangle(949, 140, 179, 20), drawFormat); drawFormat.Alignment = StringAlignment.Far; g.DrawString("Трек: " + CurrentRace.TrackName, f, Brushes.Black, 650, 195, drawFormat); g.DrawString("Дата: " + CurrentRace.Date.ToString("dd MMMM yyyy"), f, Brushes.Black, 650, 235, drawFormat); g.DrawString("Время: " + CurrentRace.Hour + ":" + CurrentRace.Minute, f, Brushes.Black, 650, 175, drawFormat); g.DrawString("Номер заезда: " + (CurrentRace.RaceNum > admin.DopRace ? (CurrentRace.RaceNum - admin.DopRace).ToString() + "a" : CurrentRace.RaceNum.ToString()), f, Brushes.Black, 650, 215, drawFormat); g.DrawString("Абсолютный рекорд трассы", f, Brushes.Black, 650, 255, drawFormat); g.DrawString(admin.model.GetRecord(CurrentRace.TrackID), f, Brushes.Black, 650, 275, drawFormat); } }
//Draws itself on node the screen. public void DrawNode(Graphics graphics, Rectangle bounds, bool isObserver) { //Draws the node ellipse graphics.FillEllipse(nodeFill, bounds); //Adds a white stroke if the given node is the observer. if (isObserver) { graphics.DrawEllipse(nodeStroke, bounds); } //Creates a reference to the node's text, which always start with it's name. string nodeText = this.name; //If the given node is not the observer, then add it's reputation to the string as well. if (!isObserver) { double truncatedRep = Math.Truncate(this.reputation * 100) / 100; nodeText = this.name + "\n" + truncatedRep; nodeText = nodeText.Replace(',', '.'); } //Draws the node text. StringFormat _StringFormat = new System.Drawing.StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; graphics.DrawString(nodeText, new System.Drawing.Font("Arial", 12), nodeFont, bounds, _StringFormat); }
public bool DrawString( System.Drawing.Graphics graphics, System.Drawing.FontFamily fontFamily, System.Drawing.FontStyle fontStyle, int fontSize, string strText, System.Drawing.Rectangle rtDraw, System.Drawing.StringFormat strFormat) { GraphicsPath path = new GraphicsPath(); path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat); Pen pen = new Pen(m_clrOutline, m_nThickness); pen.LineJoin = LineJoin.Round; graphics.DrawPath(pen, path); if (m_bClrText) { SolidBrush brush = new SolidBrush(m_clrText); graphics.FillPath(brush, path); } else { graphics.FillPath(m_brushText, path); } return(true); }
public button() { color1 = Color.White; color2 = Color.Blue; m_arrBorder = new Point[6] { new Point(0, Height - 3), new Point(0, 2),new Point(2, 0), new Point(Width - 3, 0), new Point(Width - 1, 2), new Point(Width - 1, Height - 3) }; m_arrBorder1 = new Point[6] {new Point(Width - 1, 2),new Point(Width - 1, Height - 3), new Point(Width - 3, Height - 1), new Point(2, Height - 1), new Point(2, Height - 1), new Point(0, Height - 3) }; m_arrBorder2 = new Point[9] { new Point(2, 0), new Point(Width - 3, 0), new Point(Width - 1, 2), new Point(Width - 1, Height - 3), new Point(Width - 3, Height - 1), new Point(2, Height - 1), new Point(0, Height - 3), new Point(0, 2), new Point(2, 0) }; m_pWhite = new Pen(Color.White, 2); m_pBlack = new Pen(Color.Gray, 2); m_pW = new Pen(Color.White, 2); m_bLight = new SolidBrush(GetLightColor(ControlPlusData.DrawColor)); m_bNormal = ControlPlusData.DrawBrush; m_pBorder = ControlPlusData.DrawPen; m_sFmt = new StringFormat(); m_sFmt.Alignment = StringAlignment.Center; m_sFmt.LineAlignment = StringAlignment.Center; ControlPlusData.OnColorSchemeChangeEvent += this.OnColorSchemeChanged; }
/// <summary> /// custom paint method for the label /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void LblDescription_Paint(System.Object sender, System.Windows.Forms.PaintEventArgs e) { // Getting all sorts of things for drawing the string StringFormat mStringFormat = new System.Drawing.StringFormat(); mStringFormat.FormatFlags |= System.Drawing.StringFormatFlags.NoWrap; if (this.cmbCombobox.SelectedIndex == -1) { this.lblDescription.Text = ""; } Rectangle mRectangle = this.GetLabelRectangle(); int mXCoord = mRectangle.Left + UNIT_LABEL_LEFT_OFFSET; int mYCoord = mRectangle.Top + GetYCoordStartLabel(); // Clear background e.Graphics.Clear(this.lblDescription.BackColor); // Draw String if (lblDescription.Visible) { e.Graphics.DrawString( this.lblDescription.Text, this.lblDescription.Font, new System.Drawing.SolidBrush(this.lblDescription.ForeColor), new System.Drawing.PointF(mXCoord, mYCoord), mStringFormat); } }
public SizeF MeasureString(Font font, string text) { /* BAD (but not really!?) */ var format = new SD.StringFormat(SD.StringFormat.GenericTypographic); format.FormatFlags = SD.StringFormatFlags.MeasureTrailingSpaces | SD.StringFormatFlags.NoWrap; return(Generator.Convert(this.Control.MeasureString(text, (SD.Font)font.ControlObject, SD.PointF.Empty, format))); /** * if (string.IsNullOrEmpty(text)) return Size.Empty; * * var format = new SD.StringFormat (SD.StringFormat.GenericTypographic); * SD.CharacterRange[] ranges = { new SD.CharacterRange (0, text.Length) }; * * format.FormatFlags = SD.StringFormatFlags.MeasureTrailingSpaces | SD.StringFormatFlags.NoWrap; * format.SetMeasurableCharacterRanges (ranges); * * var sdfont = (SD.Font)font.ControlObject; * var regions = this.Control.MeasureCharacterRanges (text, sdfont, SD.Rectangle.Empty, format); * var rect = regions [0].GetBounds (this.Control); * * return Generator.Convert (rect.Size); * //s.Width += 4; * //return s; * /**/ }
public virtual void DrawPanel(DrawItemEventArgs e) { string text = base.Text; if ((text != null) && (text.Length != 0)) { int num = 0; StringFormat format = new StringFormat(StringFormatFlags.NoWrap); format.LineAlignment = StringAlignment.Center; format.HotkeyPrefix = HotkeyPrefix.Hide; format.Trimming = StringTrimming.EllipsisCharacter; switch (base.Alignment) { case HorizontalAlignment.Right: format.Alignment = StringAlignment.Far; break; case HorizontalAlignment.Center: format.Alignment = StringAlignment.Center; break; default: format.Alignment = StringAlignment.Near; num = 3; break; } Rectangle layoutRectangle = new Rectangle((e.Bounds.X + 1) + num, e.Bounds.Y, (e.Bounds.Width - 2) - num, e.Bounds.Height); e.Graphics.DrawString(base.Text, base.Parent.Font, SystemBrushes.ControlText, layoutRectangle, format); format.Dispose(); } this.DrawPanelBorder(e); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; Bitmap img = new Bitmap(this.Size.Width, this.Size.Height); Graphics g = Graphics.FromImage(img); g.FillRectangle(new SolidBrush(m_keycolor), new Rectangle(0, 0, img.Width, img.Height)); if (m_touch_tip == null) { int cx = img.Width / 2; int cy = img.Height / 2; g.FillRectangle(Brushes.White, new Rectangle(cx - 300, cy - 100, 600, 200)); g.DrawString(m_msg, m_font, Brushes.Black, new Point(cx, cy), format); } else { g.DrawImage(m_touch_tip, (img.Width - m_touch_tip.Width) / 2, (img.Height - m_touch_tip.Height) / 2); } e.Graphics.DrawImage(img, 0, 0); g.Dispose(); img.Dispose(); }
private async Task ResultAnimation(bool result) { //dx ile przesunac pixeli w prawo int dx = 10; //4 - ilosc skokow napisu for (int i = 0; i < 4; i++) { string strResult = "Brawo!"; if (result == false) { strResult = "Przegrales"; } Bitmap bmp1 = new Bitmap(tableLayoutPanelAnimation.Width, tableLayoutPanelAnimation.Height); Graphics graphics = Graphics.FromImage(bmp1); graphics.TranslateTransform(dx, 0); System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); graphics.DrawString(strResult, drawFont, drawBrush, 110, 110, drawFormat); tableLayoutPanelAnimation.BackgroundImage = bmp1; dx += 100; await Task.Delay(TimeSpan.FromSeconds(1)); } }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); if (e.Index != -1) { if ((e.State & DrawItemState.Selected) != DrawItemState.None) { LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, this.MouseColor, this.mouseGradientColor, LinearGradientMode.Vertical); Rectangle rect = new Rectangle(1, e.Bounds.Y + 1, e.Bounds.Width - 2, e.Bounds.Height - 2); e.Graphics.FillRectangle(brush, rect); Pen pen = new Pen(this.ItemBorderColor); e.Graphics.DrawRectangle(pen, rect); } else { SolidBrush brush2 = new SolidBrush(this.DropBackColor); e.Graphics.FillRectangle(brush2, e.Bounds); } string s = base.Items[e.Index].ToString(); Color color = ((e.State & DrawItemState.Selected) != DrawItemState.None) ? this.ItemHoverForeColor : this.ForeColor; StringFormat format = new StringFormat { LineAlignment = StringAlignment.Center }; e.Graphics.DrawString(s, this.Font, new SolidBrush(color), e.Bounds, format); } }
static void drawText(Graphics gfx, string drawString, int fontSize, int x, int y) { System.Drawing.Font drawFont = new System.Drawing.Font("Comic Sans MS", fontSize); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); gfx.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat); }
public static float MeasureTextHeight(Font font, string text, bool bold) { using (var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near }) { using (var path = new GraphicsPath()) { var sb = new StringBuilder(text); bool newLine = false; const int leftMargin = 0; int pathPointsStart = -1; DrawText(font, sf, path, sb, false, bold, false, 0, 0, ref newLine, leftMargin, ref pathPointsStart); float height = 0; var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!! int index = list.Length - 80; if (index < 0) index = 0; for (int i = index; i < list.Length; i += 2) { if (list[i].Y > height) height = list[i].Y; } for (int i = 0; i < list.Length; i += 2) { if (list[i].Y > height) height = list[i].Y; } return height; } } }
protected override void OnPaint(PaintEventArgs e) { if (this.Focused && this.SelectedItem != null) { Rectangle itemRect = this.GetItemRectangle(this.SelectedIndex); itemRect.Height = itemRect.Height - 1; Color drawColor = Color.FromArgb(100, Color.Black); //// 定义画笔 Pen labelBorderPen = new Pen(drawColor, 0); SolidBrush labelBackColorBrush = new SolidBrush(drawColor); e.Graphics.FillRectangle(labelBackColorBrush, itemRect); } for (int i = 0; i < Items.Count; i++) { SolidBrush lb = new SolidBrush(Color.FromArgb(50, Color.Black)); Rectangle rc = this.GetItemRectangle(i); rc.Height = rc.Height - 1; e.Graphics.FillRectangle(lb, rc); StringFormat strFmt = new System.Drawing.StringFormat(); strFmt.Alignment = StringAlignment.Center; strFmt.LineAlignment = StringAlignment.Center; //文本水平居中 e.Graphics.DrawString(this.GetItemText(this.Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i), strFmt); strFmt.Alignment = StringAlignment.Far; e.Graphics.DrawString("〉", this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i), strFmt); } base.OnPaint(e); }
public MeasuredLabelItem(Graphics g, Font font, StringFormat strfmt, string itemtext) { _text = itemtext; _font = font; _strfmt = strfmt; _size = g.MeasureString(_text, _font, new PointF(0, 0), strfmt); }
public override void Draw(DocumentPaintEventArgs args) { DomContentLine line = this.OwnerLine; RectangleF rect = this.AbsBounds; if (line.ParagraphListStyle == ParagraphListStyle.BulletedList) { float size = Math.Min(rect.Width * 0.6f, rect.Height * 0.6f); RectangleF circleRect = new RectangleF(rect.Left + size / 2, rect.Top + size / 2, size, size); args.Graphics.FillEllipse(Brushes.Black, circleRect); } else if (line.ParagraphListStyle == ParagraphListStyle.NumberedList) { using (System.Drawing.StringFormat f = new System.Drawing.StringFormat()) { XFontValue font = this.RuntimeStyle.Font; f.Alignment = System.Drawing.StringAlignment.Near; f.LineAlignment = System.Drawing.StringAlignment.Center; f.FormatFlags = System.Drawing.StringFormatFlags.NoWrap; args.Graphics.DrawString( line.ParagraphStyleIndex + ".", font.Value, System.Drawing.Brushes.Black, rect, f); } } }
public void DrawConfiguration(Graphics g, Size s) { int char_base = (int)'A'; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 48); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); for (int i = 0; i < this.mChipsList.Count; i++) { int position = i; //positio = index. Brush brush = new SolidBrush(this.mChipsList[i].mChipColor); Pen pen = new Pen(Color.Black); //attain chip drawing size according to the size of the Panel. int column_number = position % this.mRowColumnConfig.Item2; int row_number = position / this.mRowColumnConfig.Item2; Point rtg_upperleft_point = new Point(s.Width / this.mRowColumnConfig.Item2 * column_number, s.Height / this.mRowColumnConfig.Item1 * row_number); Size rtg_size = new Size(s.Width / this.mRowColumnConfig.Item2, s.Height / this.mRowColumnConfig.Item1); Rectangle rtg = new Rectangle(rtg_upperleft_point, rtg_size); g.FillRectangle(brush, rtg); g.DrawRectangle(pen, rtg); if (Color.Transparent == this.mChipsList[i].mChipColor) { g.DrawLine(pen, new Point(rtg.X, rtg.Y), new Point(rtg.X + rtg.Width, rtg.Y + rtg.Height)); g.DrawLine(pen, new Point(rtg.X + rtg.Width, rtg.Y), new Point(rtg.X, rtg.Y + rtg.Height)); } string str_to_draw = ((char)(char_base + i)).ToString(); g.DrawString(str_to_draw, drawFont, drawBrush, rtg); } }
button1_Click(object sender, EventArgs e) { radioButton1.Dispose(); radioButton2.Dispose(); radioButton3.Dispose(); pictureBox1.Dispose(); textBox1.Dispose(); button3.Dispose(); button1.Dispose(); System.Drawing.Graphics formGraphics = this.CreateGraphics(); string drawString = "Les visages de Toto\n \n Application Test"; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 13); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float x = this.ClientSize.Width / 4; float y = this.ClientSize.Height / 4; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat); this.button2.Location = new System.Drawing.Point(100, 150); button2.Image = Image.FromFile("../Images/ImageOK.ico"); button2.ImageAlign = ContentAlignment.MiddleLeft; button2.TextAlign = ContentAlignment.MiddleRight; button2.Text = "Ok"; }
private void pictureBox4_Paint(object sender, PaintEventArgs e) { SolidBrush b = new SolidBrush(Color.Black); int xPos, yPos; xPos = 5; yPos = 5; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 10); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); List <int> ordered = distV.Keys.ToList(); ordered.Sort(); foreach (var item in ordered) { b.Color = colorMap[item - 1]; e.Graphics.FillRectangle(b, xPos, yPos, 15, 10); e.Graphics.DrawString(item.ToString(), drawFont, drawBrush, xPos + 25, yPos - 3); yPos += 25; if (yPos > pictureBox4.Height) { yPos = 5; xPos += 40; } } }
//this fuction takes an Image and String for watermarking as argument //and returns an Image with watermark // watermark. Картинку загружаем по пути public static Bitmap WaterMarkToImage(Bitmap bmp, string watermark) { //Bitmap bmp; //bmp = new Bitmap(ImagePath); Graphics graphicsObject; try { //create graphics object from bitmap graphicsObject = Graphics.FromImage(bmp); } catch (Exception) { Bitmap bmpNew = new Bitmap(bmp.Width, bmp.Height); graphicsObject = Graphics.FromImage(bmpNew); graphicsObject.DrawImage(bmp, new Rectangle(0, 0, bmpNew.Width, bmpNew.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel); bmp = bmpNew; } int startsize = 10; //get the font size with respect to length of the string //System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical); -> draws a vertical string for watermark System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.NoWrap); //drawing string on Image graphicsObject.DrawString(watermark, new Font("Verdana", startsize, FontStyle.Bold), new SolidBrush(Color.FromArgb(128, 0, 0, 0)), 2, 2, drawFormat); //return a water marked image return(bmp); }
public void Text(string text, Font font, uint argb, Rectangle rect) { StringFormat format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; this.Text(text, font, argb, rect, format); }
/// <summary> /// Draw just the list of cities. /// </summary> /// <param name="cityList">The list of cities to draw.</param> private void DrawCityList(Cities cityList = null, bool flag = false) { cityImage = new Bitmap(picture.Width, picture.Height); graphics = Graphics.FromImage(cityImage); int temp = 0; if (!flag) { temp = cityList.Count; } else { temp = cityList.Count / 2; } numberCitiesValue.Text = temp.ToString(); string drawString; for (int i = 0; i < temp; i++) { // Draw a circle for the city. graphics.DrawEllipse(Pens.Black, cityList[i].Location.X - 2, cityList[i].Location.Y - 2, 12, 12); drawString = (i + 1).ToString(); System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 7, FontStyle.Regular); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); graphics.DrawString(drawString, drawFont, drawBrush, cityList[i].Location.X - 18, cityList[i].Location.Y + 5, drawFormat); } this.picture.Image = cityImage; }
public Label () :base () { // Defaults in the Spec autosize = false; TabStop = false; string_format = new StringFormat(); string_format.FormatFlags = StringFormatFlags.LineLimit; TextAlign = ContentAlignment.TopLeft; image = null; UseMnemonic = true; image_list = null; image_align = ContentAlignment.MiddleCenter; SetUseMnemonic (UseMnemonic); flat_style = FlatStyle.Standard; SetStyle (ControlStyles.Selectable, false); SetStyle (ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.OptimizedDoubleBuffer , true); HandleCreated += new EventHandler (OnHandleCreatedLB); }
public void DrawString(Graphics formGraphics) { string drawString = "New Game"; string drawString1 = "Quit"; string score = "High score"; PrivateFontCollection pfc = new PrivateFontCollection(); pfc.AddFontFile("SHOWG.TTF"); string howtoplay = "How to play"; System.Drawing.Font drawFont = new System.Drawing.Font(pfc.Families[0], 18, FontStyle.Regular); System.Drawing.Font drawFont1 = new System.Drawing.Font(pfc.Families[0], font); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green); System.Drawing.SolidBrush drawBrush1 = new System.Drawing.SolidBrush(System.Drawing.Color.Firebrick); float x = 150.0F; float y = 50.0F; System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); formGraphics.DrawString(drawString, drawFont, drawBrush, 90, 80, drawFormat); formGraphics.DrawString(drawString1, drawFont, drawBrush, 120, 180, drawFormat); formGraphics.DrawString(score, drawFont1, drawBrush1, 610, 500, drawFormat); drawFont = new System.Drawing.Font(pfc.Families[0], 14, FontStyle.Regular); formGraphics.DrawString(howtoplay, drawFont, drawBrush, 285, 285, drawFormat); drawFont.Dispose(); drawBrush.Dispose(); drawBrush1.Dispose(); }
private void pnltop_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(Color.FromArgb(207, 238, 233)); if (pnlIndex == 1) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(31, 187, 133)), rec1); } else if (pnlIndex == 2) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(31, 187, 133)), rec2); } else if (pnlIndex == 3) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(31, 187, 133)), rec3); } // var sf = new System.Drawing.StringFormat(); sf.Alignment = System.Drawing.StringAlignment.Center; sf.LineAlignment = System.Drawing.StringAlignment.Center; e.Graphics.DrawString("基础信息设置", new Font("微软雅黑", 12), Brushes.Black, rec1, sf); e.Graphics.DrawString("上传图片", new Font("微软雅黑", 12), Brushes.Black, rec2, sf); e.Graphics.DrawString("属性组定义", new Font("微软雅黑", 12), Brushes.Black, rec3, sf); }
public override bool DrawString( System.Drawing.Graphics graphics, System.Drawing.FontFamily fontFamily, System.Drawing.FontStyle fontStyle, int fontSize, string strText, System.Drawing.Point ptDraw, System.Drawing.StringFormat strFormat) { using (GraphicsPath path = new GraphicsPath()) { path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat); if (m_bClrText) { using (SolidBrush brush = new SolidBrush(m_clrText)) { graphics.FillPath(brush, path); } } else { graphics.FillPath(m_brushText, path); } } return(true); }
public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format) { var font = new Font (family.Name, emSize, (FontStyle)style); var layoutRect = RectangleF.Empty; layoutRect.Location = origin; NativeDrawString (s, font, Color.Red, layoutRect, format); }
public void Pintar() { System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); System.Drawing.Graphics formGraphics; formGraphics = this.CreateGraphics(); System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 18, FontStyle.Bold); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue); System.Drawing.SolidBrush drawBrushYellow = new System.Drawing.SolidBrush(System.Drawing.Color.Yellow); System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(); AutomationElement el = AutomationElement.FromHandle(GetForegroundWindow()); int Contador = 0; List <sAutomationElement> lst = new List <sAutomationElement>(); FindTreeAutomationElments(0, ref Contador, 0, el, lst, 7); foreach (sAutomationElement el1 in lst) { System.Windows.Point clickablePoint; try { clickablePoint = el1.el.GetClickablePoint(); formGraphics.FillRectangle(drawBrushYellow, new Rectangle((int)(clickablePoint.X), (int)(clickablePoint.X), 30, 30)); formGraphics.DrawString(el1.ID.ToString(), drawFont, drawBrush, (int)(clickablePoint.X), (int)(clickablePoint.Y), drawFormat); } catch (Exception ex) { clickablePoint = new System.Windows.Point(0, 0); } } this.Show(); }
/// <summary> /// Draw a preview of the <see cref="ColorPair"/> /// </summary> /// <param name="e">The paint event args providing the <see cref="Graphics"/> and bounding /// rectangle</param> public override void PaintValue(PaintValueEventArgs e) { ColorPair colorPair = (ColorPair)e.Value ; using ( SolidBrush b = new SolidBrush(colorPair.Background)) { e.Graphics.FillRectangle(b, e.Bounds); } // Draw the text "ab" using the Foreground/Background values from the ColorPair using(SolidBrush b = new SolidBrush(colorPair.Foreground)) { using(Font f = new Font("Arial",6)) { RectangleF temp = new RectangleF(e.Bounds.Left,e.Bounds.Top,e.Bounds.Height,e.Bounds.Width) ; temp.Inflate(-2,-2) ; // Set up how we want the text drawn StringFormat format = new StringFormat(StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap) ; format.Trimming = StringTrimming.EllipsisCharacter ; format.Alignment = StringAlignment.Center ; format.LineAlignment = StringAlignment.Center ; // save the Smoothing mode of the Graphics object so we can restore it SmoothingMode saveMode = e.Graphics.SmoothingMode ; e.Graphics.SmoothingMode = SmoothingMode.AntiAlias ; e.Graphics.DrawString("ab",f,b,temp,format) ; e.Graphics.SmoothingMode = saveMode ; } } }
public void Show(AnimateMode mode, uint time) { Image logo = Properties.Resources.image_logo; this.mBrush = new TextureBrush(logo); this.mMode = mode; this.mTime = time; this.mTextFont = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Regular, GraphicsUnit.Pixel); this.mMsgFont = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Regular, GraphicsUnit.Pixel); this.Size = logo.Size; // SizeF textArea; this.mRScreen = Screen.PrimaryScreen.Bounds; if (this.mStringFormat == null) { this.mStringFormat = new StringFormat(); this.mStringFormat.Alignment = StringAlignment.Near; this.mStringFormat.LineAlignment = StringAlignment.Near; this.mStringFormat.Trimming = StringTrimming.EllipsisWord; } base.X = mRScreen.Left + mRScreen.Width / 2 - this.Width / 2; base.Y = mRScreen.Top + mRScreen.Height / 2 - this.Height / 2; if (time > 0) { base.ShowAnimate(mode, time); } else { base.Show(); } }