private void DrawBits() { try { string input = CleanString(toolStripTextBox1.Text); toolStripTextBox1.Text = input; byte[] buff = StringToByteArray(input); Graphics g = pb1.CreateGraphics(); g.Clear(Color.White); FontFamily fontFamily = new FontFamily("Courier New"); Font font = new Font(fontFamily, 10, FontStyle.Regular, GraphicsUnit.Pixel); Brush solidBrush = new SolidBrush(Color.FromArgb(255, 0, 0, 255)); if (!toolStripButton2.Checked) { for (int i = 0; i < 8; i++) g.DrawString((7 - i).ToString(), font, solidBrush, new PointF(10, i * 10 + 8)); for (int i = 0; i < buff.Length; i++) for (int j = 0; j < 8; j++) if (((1 << j) & buff[i]) != 0) g.FillRectangle(Brushes.Black, new Rectangle(i * 10 + 20, (7 - j) * 10 + 10, 8, 8)); } else { for (int i = 0; i < 8; i++) g.DrawString(i.ToString(), font, solidBrush, new PointF(10, i * 10 + 8)); for (int i = 0; i < buff.Length; i++) for (int j = 0; j < 8; j++) if (((0x80 >> j) & buff[i]) != 0) g.FillRectangle(Brushes.Black, new Rectangle(i * 10 + 20, (7 - j) * 10 + 10, 8, 8)); } } catch (Exception ex) { } }
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 CaptchaImage( string s, int width, int height, System.Drawing.FontFamily fontFamily ) { this.text = s; this.width = width; this.height = height; this.fontFamily = fontFamily; }
public Snake(int id) { gameWidth = 600; gameHeight = 600; snakePoints = new List<Point>(); wallPoints = new List<Point>(); snakeColour = Brushes.Goldenrod; backColour = Brushes.Gray; wallColour = Brushes.Black; appleTest = false; appleColour = Brushes.Green; snakePiece = 20; border = 2; apple = new Point(); apple.X = -1; apple.Y = -1; route = 2; point = 0; lvlPoints = 30; fontFamily = new FontFamily("Arial"); someFont = new Font(fontFamily, 16, FontStyle.Regular, GraphicsUnit.Pixel); status = 1; gameLvl = 1; endLvl = 2; IDuser = id; }
public FontMetrics(Graphics g, Font f) { _f = f; _ffm = f.FontFamily; _fs = f.Style; _g = g; }
/// <summary> /// Renders the <see cref="Duality.Resources.Font"/> using the specified system font family. /// </summary> public static void RenderGlyphs(this DualityFont font, FontFamily fontFamily) { // Determine System.Drawing font style SysDrawFontStyle style = SysDrawFontStyle.Regular; if (font.Style.HasFlag(FontStyle.Bold)) style |= SysDrawFontStyle.Bold; if (font.Style.HasFlag(FontStyle.Italic)) style |= SysDrawFontStyle.Italic; // Create a System.Drawing font SysDrawFont internalFont = null; if (fontFamily != null) { try { internalFont = new SysDrawFont(fontFamily, font.Size, style); } catch (Exception) { } } // If creating the font failed, fall back to a default one if (internalFont == null) internalFont = new SysDrawFont(FontFamily.GenericMonospace, font.Size, style); // Render the font's glyphs using (internalFont) { RenderGlyphs(font, internalFont); } }
public static Bitmap DrawSegmentNumbers(Bitmap bmp, Narray<Rect> bboxes) { int numAreaHeight = 10; Bitmap newbitmap = new Bitmap(bmp.Width, bmp.Height + numAreaHeight, bmp.PixelFormat); int height = bmp.Height; using (Graphics g = Graphics.FromImage(newbitmap)) { SolidBrush bgrnBrush = new SolidBrush(Color.White); SolidBrush txtBrush = new SolidBrush(Color.Black); Pen rectPen = new Pen(Color.DarkGray); g.FillRectangle(bgrnBrush, new Rectangle(Point.Empty, newbitmap.Size)); g.DrawImage(bmp, Point.Empty); bgrnBrush.Dispose(); FontFamily fontFam; try { fontFam = new FontFamily("Tahoma"); } catch { fontFam = FontFamily.GenericSansSerif; } Font font = new Font(fontFam, 5f); for (int i = 1; i < bboxes.Length(); i++) { Rect b = bboxes[i]; int bposY = (height - b.y1); // draw bounding rects g.DrawRectangle(rectPen, Math.Max(0, b.x0-1), Math.Max(0, bposY-1), b.W, b.H+1); // draw numbers g.DrawString(i.ToString(), font, txtBrush, b.x0, height + 1); } txtBrush.Dispose(); } return newbitmap; }
private void GenerateImage( HttpResponse response, string textToInsert, int width, int height, Color backgroundColor, FontFamily fontFamily, float emSize, Brush brush, float x, float y, string contentType, ImageFormat imageFormat) { using (Bitmap bitmap = new Bitmap(width, height)) { using (Graphics graphics = Graphics.FromImage(bitmap)) { graphics.Clear(backgroundColor); graphics.DrawString(textToInsert, new Font(fontFamily, emSize), brush, x, y); response.ContentType = contentType; bitmap.Save(response.OutputStream, imageFormat); } } }
public MainForm() { InitializeComponent(); splitContainer1.FixedPanel = FixedPanel.Panel1; splitContainer2.FixedPanel = FixedPanel.Panel2; AcceptButton = button5; //Send CancelButton = button4; //Close outputList_Initialize(); Settings.Read(); TopMost = Settings.Option.StayOnTop; // let form use multiple fonts origFont = Font; FontFamily ff = new FontFamily("Courier New"); monoFont = new Font(ff, 8, FontStyle.Regular); Font = Settings.Option.MonoFont ? monoFont : origFont; CommPort com = CommPort.Instance; com.StatusChanged += OnStatusChanged; com.DataReceived += OnDataReceived; com.Open(); }
public AddChipsWhenLost() { FontFamily fontFamily = new FontFamily("Arial"); InitializeComponent(); ControlBox = false; label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; }
public override void ShowDialog(object sender, EventArgs e) { FontDlg dlg = new FontDlg(FontFamily.Families); if (dlg.ShowDialog() == DialogResult.OK) { string path = dlg.DestPath; FontFamily[] fonts = dlg.SelectedFonts(); ProgressDlg pd = new ProgressDlg(DevStringTable.Instance["GUI:Converting"]); pd.MinVal = 0; pd.Value = 0; pd.MaxVal = fonts.Length; pd.Show(); for (int i = 0; i < fonts.Length; i++) { string dest = Path.Combine(path, Path.GetFileNameWithoutExtension(fonts[i].Name) + ".fnt"); currentFont = fonts[i]; Convert(null, new DevFileLocation(dest)); pd.Value = i; } pd.Close(); pd.Dispose(); } }
protected override void OnDrawItem(DrawItemEventArgs e) { if (!this.Enabled) { e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds); } else { e.DrawBackground(); string fontName = null; if (e.Index == -1) { // Text shown in the combobox itself fontName = this.Text; } else { fontName = (string)this.Items[e.Index]; } Font font = null; if ((fontName != null) && (fontName.Length != 0)) { try { FontFamily fontFamily = new FontFamily(fontName); FontStyle fontStyle = FontStyle.Regular; if (!fontFamily.IsStyleAvailable(fontStyle)) { fontStyle = FontStyle.Italic; if (!fontFamily.IsStyleAvailable(fontStyle)) { fontStyle = FontStyle.Bold; if (!fontFamily.IsStyleAvailable(fontStyle)) { throw new NotSupportedException(); } } } font = new Font(fontName, (float)((e.Bounds.Height - 2) / 1.2), fontStyle, GraphicsUnit.Pixel); } catch (Exception) { } } Rectangle textBounds = new Rectangle(e.Bounds.Left + 2, e.Bounds.Top, e.Bounds.Width - 2, e.Bounds.Height); using (TextGraphics textGraphics = new TextGraphics(e.Graphics)) { textGraphics.DrawText(fontName, textBounds.Location, (font != null) ? font : e.Font, e.ForeColor); } if (font != null) { font.Dispose(); } } }
/// <summary> /// Draw the symbols on the map /// </summary> /// <param name="p"></param> /// <param name="g"></param> public void Draw(Pen p, Graphics g) { var mouseX = Coords.X; var mouseY = Coords.Y; var currentObservationType = LogicCollection.ObservationTypeLogic.GetById(WTID); var fontFamily = new FontFamily("Arial"); var font = new Font(fontFamily, 12, FontStyle.Regular, GraphicsUnit.Pixel); var bounds = new Rectangle(mouseX - 10, mouseY - 10, 20, 20); this.Bound = bounds; /** Extensible for updates. If there is a new ObservatioType with his unique symbol use this method to draw his symbol. You need to abbrevation to verify the symbol **/ switch (currentObservationType.Name) { case "VA": g.DrawLine(p, mouseX - 10, mouseY - 7, mouseX + 5, mouseY - 7); g.DrawString(currentObservationType.Name, font, p.Brush, mouseX, mouseY, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); break; case "NI": g.DrawEllipse(p, mouseX - 13, mouseY - 13, 25, 25); g.DrawString(currentObservationType.Name, font, p.Brush, mouseX, mouseY, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); break; default: g.DrawString(currentObservationType.Name, font, p.Brush, mouseX, mouseY, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); break; } }
private void FontCollection() { // Create the byte array and get its length byte[] fontArray = Resources.gill_sans_ultra_bold_condensed; int dataLength = Resources.gill_sans_ultra_bold_condensed.Length; // ASSIGN MEMORY AND COPY BYTE[] ON THAT MEMORY ADDRESS IntPtr ptrData = Marshal.AllocCoTaskMem(dataLength); Marshal.Copy(fontArray, 0, ptrData, dataLength); uint cFonts = 0; AddFontMemResourceEx(ptrData, (uint)fontArray.Length, IntPtr.Zero, ref cFonts); PrivateFontCollection pfc = new PrivateFontCollection(); //PASS THE FONT TO THE PRIVATEFONTCOLLECTION OBJECT pfc.AddMemoryFont(ptrData, dataLength); //FREE THE "UNSAFE" MEMORY Marshal.FreeCoTaskMem(ptrData); ff = pfc.Families[0]; font = new Font(ff, 15f, FontStyle.Bold); fontButtonRegular = new Font(ff, 25f, FontStyle.Bold); fontButtonSelected = new Font(ff, 30f, FontStyle.Bold); fontRankings = new Font(ff, 25f, FontStyle.Bold); MyButton._normalFont = fontButtonRegular; MyButton._hoverFont = fontButtonSelected; }
public TileImage(int _x, int _y, int _scale, string _filename) { X = _x; Y = _y; Scale = _scale; FileName = _filename; Int32 Width = 256; Int32 Height = 256; RectangleF RectF = new RectangleF(0, 0, Width, Height); Bitmap Pic = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(Pic); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Color fontColor = Color.Black; Color rectColor = Color.White; SolidBrush fgBrush = new SolidBrush(fontColor); SolidBrush bgBrush = new SolidBrush(rectColor); g.FillRectangle(bgBrush, RectF); Pen pen = new Pen(Color.Blue); g.DrawRectangle(pen, 0, 0, Width - 1, Height - 1); string text = "xyz=" + _x.ToString() + "," + _y.ToString() + "," + _scale.ToString(); FontFamily fontFamily = new FontFamily("Arial"); Font font = new Font(fontFamily,18,FontStyle.Regular,GraphicsUnit.Pixel); g.DrawString(text, font, fgBrush, RectF); if (_filename != null && _filename.Length != 0) Pic.Save(_filename, ImageFormat.Png); }
public void AddPoint(DateTime dt, int nb) { TimeSpan ts = dt.Subtract(dt_start); PointF new_p = new PointF((float)ts.TotalMinutes * x_mod / 60f, y_tab + height - (y_mod * (nb + 1f))); if (last_p == PointF.Empty) last_p = new_p; using (Graphics g = Graphics.FromImage(Graphique)) { using (Pen p = new Pen(Color.Red, 4f)) g.DrawLine(p, last_p, new_p); using (SolidBrush sb = new SolidBrush(Color.Black)) using (FontFamily ff = new FontFamily("Trebuchet MS")) using (Font f = new Font(ff, 8, FontStyle.Regular)) g.DrawString(nb + "", f, sb, new_p); } if (new_p.X > width) { Save(); DrawGraphBackground(); new_p.X = new_p.X - width; last_p.X = last_p.X - width; AddPoint(dt, nb); } else last_p = new_p; }
public AddChips() { FontFamily fontFamily = new FontFamily("Arial"); InitializeComponent(); ControlBox = false; label1.BorderStyle = BorderStyle.FixedSingle; }
/// <summary> /// Renders text along the path /// </summary> /// <param name="self">The graphics object</param> /// <param name="halo">The pen to render the halo outline</param> /// <param name="fill">The brush to fill the text</param> /// <param name="text">The text to render</param> /// <param name="fontFamily">The font family to use</param> /// <param name="style">The style</param> /// <param name="emSize">The size</param> /// <param name="format">The format</param> /// <param name="ignoreLength"></param> /// <param name="path"></param> public static void DrawString(this Graphics self, Pen halo, Brush fill, string text, FontFamily fontFamily, int style, float emSize, StringFormat format, bool ignoreLength, GraphicsPath path) { if (path == null || path.PointCount == 0) return; var gp = new GraphicsPath(); gp.AddString(text, fontFamily, style, emSize, new Point(0, 0), format); SortedList<float, GraphSegment> edges; var totalLength = GetPathLength(path, out edges); var warpedPath = PrepareTextPathToWarp(gp, totalLength, ignoreLength, format); if (warpedPath == null) return; var wp = Warp(path, warpedPath, false, 0f); if (wp != null) { if (halo != null) self.DrawPath(halo, wp); if (fill != null) self.FillPath(fill, wp); } }
private static Bitmap CreateInfomationBitmap(string content, int width, int height, StringAlignment hAlign = StringAlignment.Near, StringAlignment vAlign = StringAlignment.Near) { Bitmap b = new Bitmap(width, height); Graphics g = Graphics.FromImage(b); GraphicsPath path = new GraphicsPath(); FontFamily fontFamily = new FontFamily("微软雅黑"); StringFormat format = new StringFormat(); format.Alignment = hAlign; format.LineAlignment = vAlign; path.AddString(content, fontFamily, (int)FontStyle.Bold, 16, new Rectangle(0, 0, width, height), format); fontFamily.Dispose(); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(Brushes.Black, path); Pen pen = new Pen(Color.Black, 2); g.DrawPath(pen, path); g.Dispose(); pen.Dispose(); Bitmap infoBitmap = RenderUtils.BoxBlur(b, 1); g = Graphics.FromImage(infoBitmap); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(Brushes.White, path); g.Dispose(); return infoBitmap; }
static FontFamily() { Container = new awt.Container(); _installedFonts = new InstalledFontCollection(); _genericMonospace = new FontFamily(GenericFontFamilies.Monospace); _genericSansSerif = new FontFamily(GenericFontFamilies.SansSerif); _genericSerif = new FontFamily(GenericFontFamilies.Serif); }
private void CreateFont (string familyName, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) { #if ONLY_1_1 if (familyName == null) throw new ArgumentNullException ("familyName"); #endif originalFontName = familyName; FontFamily family; // NOTE: If family name is null, empty or invalid, // MS creates Microsoft Sans Serif font. try { family = new FontFamily (familyName); } catch (Exception){ family = FontFamily.GenericSansSerif; } setProperties (family, emSize, style, unit, charSet, isVertical); Status status = GDIPlus.GdipCreateFont (family.NativeObject, emSize, style, unit, out fontObject); if (status == Status.FontStyleNotFound) throw new ArgumentException (Locale.GetText ("Style {0} isn't supported by font {1}.", style.ToString (), familyName)); GDIPlus.CheckStatus (status); }
private void xxcbDrawItem(object sender, DrawItemEventArgs e) { //drawItems here if (sender == null) return; if (e.Index < 0) return; //Get the Combo from the sender object ComboBox cbo = (ComboBox)sender; //Get the FontFamily from put in constructor FontFamily ff = new FontFamily(cbo.Items[e.Index].ToString()); //Set font style FontStyle fs = FontStyle.Regular; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Italic; if (!ff.IsStyleAvailable(fs)) fs = FontStyle.Bold; //Set font for drawing with (wich is the font itself) Font font = new Font(ff, 8, fs); //draw the background and focus rectangle e.DrawBackground(); e.DrawFocusRectangle(); //get graphics Graphics g = e.Graphics; //And draw with whatever font and brush we wish g.DrawString(font.Name, font, Brushes.ForestGreen, e.Bounds.X, e.Bounds.Y); }
public AddChips() { FontFamily fontFamily = new FontFamily("Arial"); this.InitializeComponent(); this.ControlBox = false; this.outOfChipsLabel.BorderStyle = BorderStyle.FixedSingle; }
public TileImage(int x, int y, int scale, string filename) { X = x; Y = y; Scale = scale; FileName = filename; const int width = 256; const int height = 256; RectangleF rectF = new RectangleF(0, 0, width, height); Pic = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(Pic); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Color fontColor = Color.Black; Color rectColor = Color.White; SolidBrush fgBrush = new SolidBrush(fontColor); SolidBrush bgBrush = new SolidBrush(rectColor); g.FillRectangle(bgBrush, rectF); Pen pen = new Pen(Color.Blue); g.DrawRectangle(pen, 0, 0, width - 1, height - 1); string text = string.Format("xyz={0},{1},{2}", x, y, scale); FontFamily fontFamily = new FontFamily("Arial"); Font font = new Font(fontFamily,18,FontStyle.Regular,GraphicsUnit.Pixel); g.DrawString(text, font, fgBrush, rectF); }
public static Bitmap DrawSegmentTranscript(Bitmap bmp, Narray<Rect> bboxes, string trans) { if (String.IsNullOrEmpty(trans) || bboxes.Length() - 1 != trans.Length) return bmp; int numAreaHeight = 15; Bitmap newbitmap = new Bitmap(bmp.Width, bmp.Height + numAreaHeight, bmp.PixelFormat); int height = bmp.Height; using (Graphics g = Graphics.FromImage(newbitmap)) { SolidBrush bgrnBrush = new SolidBrush(Color.White); SolidBrush txtBrush = new SolidBrush(Color.Black); Pen rectPen = new Pen(Color.DarkGray); g.FillRectangle(bgrnBrush, new Rectangle(Point.Empty, newbitmap.Size)); g.DrawImage(bmp, Point.Empty); bgrnBrush.Dispose(); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; FontFamily fontFam; try { fontFam = new FontFamily("Tahoma"); } catch { fontFam = FontFamily.GenericSansSerif; } Font font = new Font(fontFam, 6f); for (int i = 1; i < bboxes.Length(); i++) { Rect b = bboxes[i]; g.DrawString(trans[i-1].ToString(), font, txtBrush, b.x0, height + 1); } txtBrush.Dispose(); } return newbitmap; }
public static Font FromName(string fontName) { Font font = null; var fontFamilyDesc = Pango.FontDescription.FromString (fontName); FontStyle style = FromPangoStyle (fontFamilyDesc.Style, fontFamilyDesc.Weight); /// Seriously, what the f**k? int notBullshitSize = (int)(fontFamilyDesc.Size / Pango.Scale.PangoScale); /// The chooser shows these options but they won't resolve automagically /// a installed font. Bit balls. if (fontFamilyDesc.Family == "Mono") { font = new Font (FontFamily.GenericMonospace, notBullshitSize, style); } else if (fontFamilyDesc.Family == "Sans") { font = new Font (FontFamily.GenericSansSerif, notBullshitSize, style); } else if (fontFamilyDesc.Family == "Serif") { font = new Font (FontFamily.GenericSerif, notBullshitSize, style); } else { InstalledFontCollection installedFonts = new InstalledFontCollection (); var test = new FontFamily (fontFamilyDesc.Family, installedFonts); font = new Font (test, fontFamilyDesc.Size); } return font; }
public BitmapTypeface(string Name, bool Bold, bool Italic) : base(Name, Bold, Italic) { this.GlyphMap = new Dictionary<char, Glyph>(); this.FontFamily = GetFamily(Name); this._CreateSheet(ASCIICharacters); }
public static Font CreateFont(FontFamily ff, float fEmSize, FontStyle fs) { try { return new Font(ff, fEmSize, fs); } catch(Exception) { Debug.Assert(false); } // Style unsupported? return new Font(ff, fEmSize); }
public void DrawText(int x, int y, string message, Color? color = null, int? fontsize = null, string fontfamily = null, string fontstyle = null) { var family = FontFamily.GenericMonospace; if (fontfamily != null) { family = new FontFamily(fontfamily); } var fstyle = FontStyle.Regular; if (fontstyle != null) { switch (fontstyle.ToLower()) { default: case "regular": break; case "bold": fstyle = FontStyle.Bold; break; case "italic": fstyle = FontStyle.Italic; break; case "strikethrough": fstyle = FontStyle.Strikeout; break; case "underline": fstyle = FontStyle.Underline; break; } } var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel); graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; graphics.DrawString(message, font, new SolidBrush(color ?? Color.White), x, y); }
/// <summary> /// Occurs during the drawing of an item /// </summary> /// <param name="e"></param> protected override void OnDrawItem(DrawItemEventArgs e) { Rectangle outer = e.Bounds; outer.Inflate(1, 1); e.Graphics.FillRectangle(Brushes.White, outer); Brush fontBrush = Brushes.Black; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { Rectangle r = e.Bounds; r.Inflate(-1, -1); e.Graphics.FillRectangle(Global.HighlightBrush(r, Color.FromArgb(215, 238, 252)), r); Pen p = new Pen(Color.FromArgb(215, 238, 252)); Global.DrawRoundedRectangle(e.Graphics, p, e.Bounds); p.Dispose(); } string name = Items[e.Index].ToString(); FontFamily ff = new FontFamily(name); Font fnt = new Font("Arial", 10, FontStyle.Regular); if (ff.IsStyleAvailable(FontStyle.Regular)) { fnt = new Font(name, 10, FontStyle.Regular); } else if (ff.IsStyleAvailable(FontStyle.Italic)) { fnt = new Font(name, 10, FontStyle.Italic); } SizeF box = e.Graphics.MeasureString(name, Font); e.Graphics.DrawString(name, Font, fontBrush, e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString("ABC", fnt, fontBrush, e.Bounds.X + box.Width, e.Bounds.Y); }
public TextContext() { fontFamily = new System.Drawing.FontFamily("Arial"); fontStyle = System.Drawing.FontStyle.Regular; nfontSize = 20; pszText = null; ptDraw = new System.Drawing.Point(0, 0); strFormat = new System.Drawing.StringFormat(); }
/// <summary> /// Método para cambiar el estilo del texto según el cambio que se le pida desde la botonera. /// </summary> /// <param name="rtb">RichTextBox en el que producir los cambios</param> /// <param name="family">Fuente a la que cambiar el texto</param> /// <param name="size">Tamaño al que cambiar el texto</param> /// <param name="style">Estilo a modificar en el texto</param> private void ChangeFontStyle(RichTextBox rtb, string family, float?size, FontStyle?style) { int selectedStart = rtb.SelectionStart; int selectedLength = rtb.SelectionLength; if (selectedLength > 0) { using (RichTextBox rtbTemp = new RichTextBox()) { rtbTemp.Rtf = rtb.SelectedRtf; for (int i = 0; i < selectedLength; ++i) { rtbTemp.Select(i, 1); FontFamily newfamily; float newsize; if (string.IsNullOrEmpty(family)) { newfamily = rtbTemp.SelectionFont.FontFamily; } else { newfamily = new FontFamily(family); } newsize = size ?? rtbTemp.SelectionFont.Size; FontStyle newstyle = rtbTemp.SelectionFont.Style; if (style != null) { rtbTemp.SelectionFont = new Font(newfamily, newsize, newstyle ^ (FontStyle)style); } else { rtbTemp.SelectionFont = new Font(newfamily, newsize, newstyle); } } rtbTemp.Select(0, selectedLength); rtb.SelectedRtf = rtbTemp.SelectedRtf; rtb.Select(selectedStart, selectedLength); } } else { string newfamily = family ?? rtb.SelectionFont.FontFamily.Name; float newsize = size ?? rtb.SelectionFont.Size; FontStyle newstyle = rtb.SelectionFont.Style; if (style != null) { rtb.SelectionFont = new Font(newfamily, newsize, newstyle ^ (FontStyle)style); } else { rtb.SelectionFont = new Font(newfamily, newsize, newstyle); } } }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.FontFamily. /// </summary> /// <param name="fontFamily">The System.Drawing.FontFamily.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(GdiFontFamily fontFamily, double emSize, XFontStyle style, XPdfFontOptions pdfOptions) { _familyName = fontFamily.Name; _gdiFontFamily = fontFamily; _emSize = emSize; _style = style; _pdfOptions = pdfOptions; InitializeFromGdi(); }
/// <summary> /// Evento que se ejecuta cuando cambia el índice de selección del combo de fuentes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cbFonts_SelectedIndexChanged(object sender, EventArgs e) { // Cambiar la fuente del texto seleccionado FontFamily f = (FontFamily)cbFonts.SelectedItem; ChangeFontStyle(rtbPad, f.Name, null, null); //changeSelectedFont(cbFonts, cbFontSize); rtbPad.Select(); }
public override 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) { int nOffset = Math.Abs(m_nOffsetX); if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetX); } else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetY); } else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetX); } for (int i = 0; i < nOffset; ++i) { using (GraphicsPath path = new GraphicsPath()) { path.AddString(strText, fontFamily, (int)fontStyle, fontSize, new Rectangle(rtDraw.X + ((i * (-m_nOffsetX)) / nOffset), rtDraw.Y + ((i * (-m_nOffsetY)) / nOffset), rtDraw.Width, rtDraw.Height), 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); }
/// <summary> /// Evento que se ejecuta cuando se modifica la selección (o posición) del RTB. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void rtbPad_SelectionChanged(object sender, EventArgs e) { // Poner en el combo la fuente adecuada y el tamaño adecuado Font seleccionado = rtbPad.SelectionFont; if (seleccionado != null) { FontFamily f = searchFontPosition(cbFonts, rtbPad.SelectionFont.FontFamily.Name); if (f != null) { cbFonts.SelectedItem = f; cbFontSize.SelectedIndex = cbFontSize.FindStringExact(rtbPad.SelectionFont.Size.ToString()); } } }
public 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) { int nOffset = Math.Abs(m_nOffsetX); if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetX); } else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetY); } else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY)) { nOffset = Math.Abs(m_nOffsetX); } for (int i = 0; i < nOffset; ++i) { GraphicsPath path = new GraphicsPath(); path.AddString(strText, fontFamily, (int)fontStyle, fontSize, new Point(ptDraw.X + ((i * (-m_nOffsetX)) / nOffset), ptDraw.Y + ((i * (-m_nOffsetY)) / nOffset)), 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 static Font GetLegacyFont(TextBlock element) { System.Drawing.FontStyle style = 0; FontStyle[] s = new System.Drawing.FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Strikeout, FontStyle.Underline }; // Find the first default style that will work with this font... var family = new System.Drawing.FontFamily(element.FontFamily.Source); foreach (FontStyle fs in s) { if (family.IsStyleAvailable(fs)) { style = fs; break; } } // Scale the font from 96 DPI to 72 DPI double size = PixelsToPoints(element, element.FontSize); if (element.FontWeight == System.Windows.FontWeights.Bold) { style |= System.Drawing.FontStyle.Bold; } if (element.FontStyle == System.Windows.FontStyles.Italic || element.FontStyle == System.Windows.FontStyles.Oblique) { style |= System.Drawing.FontStyle.Italic; } if (element.TextDecorations.Contains(System.Windows.TextDecorations.Underline[0])) { style |= System.Drawing.FontStyle.Underline; } if (element.TextDecorations.Contains(System.Windows.TextDecorations.Strikethrough[0])) { style |= System.Drawing.FontStyle.Strikeout; } var font = new Font(family, (float)size, style); return(font); }
static WordEx() { _calibri = new System.Drawing.FontFamily("Calibri"); _titleFormat = new Formatting(); _titleFormat.FontFamily = _calibri; _titleFormat.Size = 12D; _titleFormat.FontColor = System.Drawing.Color.DarkBlue; _headerFormat = new Formatting(); _headerFormat.FontFamily = _calibri; _headerFormat.Size = 12D; _headerFormat.FontColor = System.Drawing.Color.Blue; //_headerFormat.Position = 12; // A formatting object for our normal paragraph text: _textFormat = new Formatting(); _textFormat.FontFamily = _calibri; _textFormat.Size = 10D; }
public bool MeasureString( System.Drawing.Graphics graphics, System.Drawing.FontFamily fontFamily, System.Drawing.FontStyle fontStyle, int fontSize, string strText, System.Drawing.Rectangle rtDraw, System.Drawing.StringFormat strFormat, ref float fStartX, ref float fStartY, ref float fDestWidth, ref float fDestHeight) { using (GraphicsPath path = new GraphicsPath()) { path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat); fDestWidth = rtDraw.Width; fDestHeight = rtDraw.Height; bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight); if (false == b) { return(false); } float pixelThick = 0.0f; float pixelThick2 = 0.0f; float fStartX2 = 0.0f; float fStartY2 = 0.0f; b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2); if (false == b) { return(false); } fDestWidth += pixelThick; fDestHeight += pixelThick; } return(true); }
/// <summary> /// Método para rellenar un combobox con todos los tipos de fuente presentes en el sistema. /// </summary> /// <param name="comboBoxFonts">Combobox a rellenar con las fuentes del sistema</param> private void FillFontComboBox(ComboBox comboBoxFonts) { comboBoxFonts.DrawMode = DrawMode.OwnerDrawFixed; comboBoxFonts.DrawItem += new DrawItemEventHandler(cbFonts_DrawItem); comboBoxFonts.DataSource = System.Drawing.FontFamily.Families.ToList(); comboBoxFonts.SelectedIndex = 0; FontFamily f = searchFontPosition(comboBoxFonts, "Arial"); if (f != null) { comboBoxFonts.SelectedItem = f; } else { comboBoxFonts.SelectedIndex = 0; } }
//protected override void OnMeasureItem(System.Windows.Forms.MeasureItemEventArgs e) //{ // base.OnMeasureItem(e); // e.ItemHeight = e.ItemHeight - 2; //} protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e) { base.OnDrawItem(e); if (e.Index < 0) { return; } float size = this.Font.Size; System.Drawing.Font myFont; System.Drawing.FontFamily family = this.Font.FontFamily; System.Drawing.Color animalColor = this.ForeColor; // Draw the background of the item. e.DrawBackground(); // Create a square filled with the animals color. Vary the size // of the rectangle based on the length of the animals name. //System.Drawing.Rectangle rectangle = new Rectangle(2, e.Bounds.Top + 2, // e.Bounds.Height, e.Bounds.Height - 4); //e.Graphics.FillRectangle(new SolidBrush(animalColor), rectangle); // Draw each string in the array, using a different size, color, // and font for each item. myFont = new Font(family, size, FontStyle.Regular); e.Graphics.DrawString(this.GetItemText(Items[e.Index]), myFont, System.Drawing.Brushes.Black, new PointF(e.Bounds.X + 5, e.Bounds.Y + 2)); //new RectangleF(e.Bounds.X + e.Bounds.Height, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height)); //弹出下拉 //if (e.State == (System.Windows.Forms.DrawItemState.NoAccelerator | System.Windows.Forms.DrawItemState.NoFocusRect)) //{ // e.Graphics.DrawRectangle(new Pen(_borderColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); //} //else//选择时 //{ // e.Graphics.DrawRectangle(new Pen(_borderColor), e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1); //} // Draw the focus rectangle if the mouse hovers over an item. e.DrawFocusRectangle(); }
public override 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) { using (GraphicsPath path = new GraphicsPath()) { path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat); using (Pen pen = new Pen(m_clrOutline, m_nThickness)) { pen.LineJoin = LineJoin.Round; graphics.DrawPath(pen, path); } } return(true); }
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 pen2 = new Pen(m_clrOutline2, m_nThickness1 + m_nThickness2)) { pen2.LineJoin = LineJoin.Round; graphics.DrawPath(pen2, path); } using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1)) { pen1.LineJoin = LineJoin.Round; graphics.DrawPath(pen1, path); } if (m_bClrText) { using (SolidBrush brush = new SolidBrush(m_clrText)) { graphics.FillPath(brush, path); } } else { graphics.FillPath(m_brushText, path); } } return(true); }