當前位置: 首頁>>代碼示例>>C#>>正文


C# Drawing.StringFormat類代碼示例

本文整理匯總了C#中System.Drawing.StringFormat的典型用法代碼示例。如果您正苦於以下問題:C# StringFormat類的具體用法?C# StringFormat怎麽用?C# StringFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringFormat類屬於System.Drawing命名空間,在下文中一共展示了StringFormat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: WaterMarkerImage

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <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);
        }
開發者ID:corner87,項目名稱:CSIT555_Class_Project,代碼行數:41,代碼來源:CopyrightProtectionForm.cs

示例2: BaseTextItem

		public BaseTextItem():base() {
			this.dataType = "System.String";
			this.stringFormat = StringFormat.GenericTypographic;
			this.contentAlignment = ContentAlignment.TopLeft;
			this.stringTrimming = StringTrimming.None;
			VisibleInReport = true;
		}
開發者ID:OmerRaviv,項目名稱:SharpDevelop,代碼行數:7,代碼來源:BaseTextItem.cs

示例3: EDSToolTip_Draw

        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);
                    }
                }
            }
        }
開發者ID:vineelkovvuri,項目名稱:ExtendableDesktopSearch,代碼行數:31,代碼來源:EDSToolTip.cs

示例4: Text

 public void Text(string text, Font font, uint argb, Rectangle rect, StringFormat format)
 {
     graphics.DrawString(
         text, font,
         new SolidBrush(argb.ToColor()),
         rect, format);
 }
開發者ID:matheus2984,項目名稱:SoulEngine,代碼行數:7,代碼來源:GraphicsHelper.cs

示例5: DiffViewer

        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;
            }
        }
開發者ID:kg,項目名稱:HeapProfiler,代碼行數:28,代碼來源:DiffViewer.cs

示例6: Print

		/// <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;
		}
開發者ID:andrepontesmelo,項目名稱:imjoias,代碼行數:39,代碼來源:Header.cs

示例7: CreateNativeLabel

        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;
		}
開發者ID:Karunp,項目名稱:cocos2d-xna,代碼行數:60,代碼來源:CCLabelUtilities-Gdi.cs

示例8: Draw

        /// <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)
        }
開發者ID:WillMoreland,項目名稱:BalloonCup,代碼行數:32,代碼來源:Card.cs

示例9: OnDrawItem

        /// <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);
                }
            }
        }
開發者ID:meandthewallaby,項目名稱:Edrych,代碼行數:30,代碼來源:TabControlExt.cs

示例10: GetEyeOfSightImage

        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;
        }
開發者ID:geobabbler,項目名稱:SharpMap,代碼行數:25,代碼來源:EyeOfSight.cs

示例11: RepertoryImage

        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();
        }
開發者ID:xueliu,項目名稱:MSC_Generator,代碼行數:31,代碼來源:LostMessageExtension.cs

示例12: DrawMenuItem

        /// <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);
        }
開發者ID:algz,項目名稱:GDIDrawFlow,代碼行數:35,代碼來源:MainMenuItemDrawing.cs

示例13: DrawString

 public abstract void DrawString(
     string s,
     Font font,
     Brush brush,
     RectangleF layoutRectangle,
     StringFormat format
 );
開發者ID:jrahhali,項目名稱:squirrely,代碼行數:7,代碼來源:Game.cs

示例14: SnakePit

        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();
        }
開發者ID:memsom,項目名稱:dotNetAnywhere-wb,代碼行數:35,代碼來源:SnakePit.cs

示例15: TextBoxTextRenderer

		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 ();
		}
開發者ID:Profit0004,項目名稱:mono,代碼行數:27,代碼來源:TextBoxTextRenderer.cs


注:本文中的System.Drawing.StringFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。