当前位置: 首页>>代码示例>>C#>>正文


C# Font.MeasureText方法代码示例

本文整理汇总了C#中SharpDX.Direct3D9.Font.MeasureText方法的典型用法代码示例。如果您正苦于以下问题:C# Font.MeasureText方法的具体用法?C# Font.MeasureText怎么用?C# Font.MeasureText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SharpDX.Direct3D9.Font的用法示例。


在下文中一共展示了Font.MeasureText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawText

		public static void DrawText(Font font, string text, int posX, int posY, Color color)
		{
			Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
			font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
			font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
			font.DrawText(null, text, posX + rec.X, posY, color);
		}
开发者ID:MeteTR,项目名称:LeagueSharp2,代码行数:9,代码来源:Helper.cs

示例2: GetMeasured

		private static Rectangle GetMeasured(Font font, string text) {
			Rectangle rec;
			var key = font.Description.FaceName + font.Description.Width + font.Description.Height +
					  font.Description.Weight + text;
			if (!Measured.TryGetValue(key, out rec))
			{
				rec = font.MeasureText(null, text, FontDrawFlags.Center);
				Measured.Add(key, rec);
			}
			return rec;
		}
开发者ID:rickson22,项目名称:LeagueSharp,代码行数:11,代码来源:Extension.cs

示例3: GetCenteredText

 /// <summary>
 ///     Calculates the center position for the given text on within a rectangle boundaries.
 /// </summary>
 /// <param name="rectangle">Rectangle boundaries</param>
 /// <param name="sprite">Sprite which is being drawn on</param>
 /// <param name="font">Text Font</param>
 /// <param name="text">The Text</param>
 /// <param name="flags">Centered Flags</param>
 /// <returns>Returns the center position of the text on the rectangle.</returns>
 public static Vector2 GetCenteredText(
     this Rectangle rectangle, 
     Sprite sprite, 
     Font font, 
     string text, 
     CenteredFlags flags)
 {
     return font == null
                ? rectangle.GetCenteredText(sprite, text, flags)
                : rectangle.GetCenter(sprite, font.MeasureText(sprite, text, 0), flags);
 }
开发者ID:8569482,项目名称:LeagueSharp.SDK,代码行数:20,代码来源:Geometry.cs

示例4: Main

        static void Main()
        {
            var form = new RenderForm("SharpDX - Direct3D9 Font Sample");
            int width = form.ClientSize.Width;
            int height = form.ClientSize.Height;
            var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });

            // Initialize the Font
            FontDescription fontDescription = new FontDescription()
            {
                Height = 72,
                Italic = false,
                CharacterSet = FontCharacterSet.Ansi,
                FaceName = "Arial",
                MipLevels = 0,
                OutputPrecision = FontPrecision.TrueType,
                PitchAndFamily = FontPitchAndFamily.Default,
                Quality = FontQuality.ClearType,
                Weight = FontWeight.Bold
            };



            var font = new Font(device, fontDescription);

            var displayText = "Direct3D9 Text!";

            // Measure the text to display
            var fontDimension = font.MeasureText(null, displayText, new Rectangle(0, 0, width, height), FontDrawFlags.Center | FontDrawFlags.VerticalCenter);

            int xDir = 1;
            int yDir = 1;

            RenderLoop.Run(form, () =>
            {
                device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
                device.BeginScene();

                // Make the text boucing on the screen limits
                if ((fontDimension.Right + xDir) > width)
                    xDir = -1;
                else if ((fontDimension.Left + xDir) <= 0)
                    xDir = 1;

                if ((fontDimension.Bottom + yDir) > height)
                    yDir = -1;
                else if ((fontDimension.Top + yDir) <= 0)
                    yDir = 1;

                fontDimension.Left += (int)xDir;
                fontDimension.Top += (int)yDir;
                fontDimension.Bottom += (int)yDir;
                fontDimension.Right += (int)xDir;

                // Draw the text
                font.DrawText(null, displayText, fontDimension, FontDrawFlags.Center | FontDrawFlags.VerticalCenter, Color.White);

                device.EndScene();
                device.Present();
            });
        }
开发者ID:MaybeMars,项目名称:SharpDX-Samples,代码行数:61,代码来源:Program.cs

示例5: DrawText

 public static void DrawText(Font font, String text, int posX, int posY, Color color)
 {
     if (font == null || font.IsDisposed)
     {
         throw new SharpDXException("");
         return;
     }
     Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
     font.DrawText(null, text, posX + 1 + rec.X, posY, Color.Black);
     font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
     font.DrawText(null, text, posX - 1 + rec.X, posY, Color.Black);
     font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
     font.DrawText(null, text, posX + rec.X, posY, color);
 }
开发者ID:hhhmmm2,项目名称:SAwareness,代码行数:16,代码来源:Utils.cs

示例6: DrawText

 public static void DrawText(Font font, String text, int posX, int posY, Color color)
 {
     Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
     font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpColor.White);
 }
开发者ID:Sthephanfelix,项目名称:LeagueSharp-4,代码行数:5,代码来源:Program.cs

示例7: UpvoteItem

 public UpvoteItem(string name)
 {
     _text = string.Format("Please consider to upvote {0} in the Assembly Database.", name);
     _font = new Font(
         Drawing.Direct3DDevice,
         new FontDescription
         {
             FaceName = "Calibri",
             Height = 20,
             OutputPrecision = FontPrecision.Default,
             Quality = FontQuality.Default
         });
     _measured = _font.MeasureText(null, _text, FontDrawFlags.Center);
     _line = new Line(Drawing.Direct3DDevice) { Width = _measured.Height + (Padding * 2) };
 }
开发者ID:iHeartZigg,项目名称:LeagueSharp-Dev,代码行数:15,代码来源:Upvote.cs


注:本文中的SharpDX.Direct3D9.Font.MeasureText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。