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


C# Microsoft.MeasureString方法代码示例

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


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

示例1: DrawCenteredText

        public bool DrawCenteredText(Microsoft.DirectX.Direct3D.Font font, string text, int x, int y, int color)
        {
            int centeredX = 0;
            int centeredY = 0;
            Rectangle rect;

            if ((font == null) || (text == null) || (text.Length <= 0))
            {
                return false;
            }

            rect = font.MeasureString(null, text, DrawTextFormat.None, color);

            centeredX = x - rect.Width / 2;
            centeredY = y - rect.Height / 2;
            if (font.DrawText(null, text, centeredX, centeredY, color) == 0)
            {
                return false;
            }

            return true;
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:22,代码来源:MapPlayfieldContainer.cs

示例2: DrawObjectID

 public void DrawObjectID(Canvas canvas, Microsoft.DirectX.Direct3D.Font font)
 {
     if (ID != string.Empty)
     {
         _text_rect = font.MeasureString(null, ID, DrawTextFormat.Center, TextColor);
         _text_rect.X = (SpriteArea.X + ((SpriteArea.Width - _text_rect.Width) / 2)) - 5;
         _text_rect.Y = SpriteArea.Bottom;
         _text_rect.Width += 10;
         canvas.DrawFillRect(_text_rect, _textbox_color_material);
    
         font.DrawText(null, ID, _text_rect, DrawTextFormat.Center, TextColor);
     }
 }
开发者ID:wshanshan,项目名称:DDD,代码行数:13,代码来源:MappableObject.cs

示例3: DrawSpecial

        public override void DrawSpecial(Microsoft.DirectX.Direct3D.Font font, RectangleF overlay_rect, Rectangle text_rect, Canvas canvas)
        {

            _overlay_rect = overlay_rect;
            _text_rect = text_rect;
            _progressbar_rect = text_rect;
            _border_rect = text_rect;

           

            if ((OwnerID == DDD_Global.Instance.PlayerID) && (DrawProgressBar))
            {

                _progressbar_rect.Y += text_rect.Height;
                _progressbar_rect.Height = _ProgressBarHeight_;
                _progressbar_rect.Width = _ProgressBarWidth_;
                _progressbar_rect.X += ((text_rect.Width - _progressbar_rect.Width) / 2);

                _border_rect.Height = _ProgressBarHeight_ + _text_rect.Height + 2;

                canvas.DrawFillRect(_border_rect, _textbox_color_material);

                DrawObjectID(canvas, font);
                canvas.DrawRect(_border_rect, BorderColor);

                if (FuelCapacity > 0)
                {
                    canvas.DrawProgressBar(_progressbar_rect,
                        progress_bar_background_material,
                        progress_bar_foreground_material,
                        FuelAmount / FuelCapacity);
                }
                else
                {
                    canvas.DrawProgressBar(_progressbar_rect,
                        progress_bar_background_material,
                        progress_bar_foreground_material,
                        0);
                }
            }
            else
            {
                if (DrawUnmanagedAssetLabel)
                {
                    DrawObjectID(canvas, font);
                    canvas.DrawRect(_border_rect, BorderColor);
                }

            }



            foreach (DDDObjects attacker in Attackers)
            {
                float _destinationX = attacker.SpriteArea.X + (attacker.SpriteArea.Width / 2);
                float _destinationY = attacker.SpriteArea.Y + (attacker.SpriteArea.Height / 2);
                canvas.DrawLine(Color.Red, 1,
                    SpriteArea.X + (SpriteArea.Width / 2),
                    SpriteArea.Y + (SpriteArea.Height / 2),
                    _destinationX,
                    _destinationY
                    );
                //engagment_rect.X = (int)(_destinationX - 3);
                //engagment_rect.Y = (int)(_destinationY - 3);
                //engagment_rect.Height = 6;
                //engagment_rect.Width = 6;
                //canvas.DrawFillRect(engagment_rect, red_material);
            }

            if (IsBeingAttacked)
            {
                engagment_rect = font.MeasureString(null, _engagementTimeStr, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.Red);
                engagment_rect.Width += 10;
                engagment_rect.X = (int)(_overlay_rect.X + (_overlay_rect.Width - engagment_rect.Width) / 2);
                engagment_rect.Y = (int)(_overlay_rect.Y + (_overlay_rect.Height - engagment_rect.Height) / 2);
                canvas.DrawFillRect(engagment_rect, black_material);
                canvas.DrawRect(engagment_rect, Color.Red);
                font.DrawText(null, _engagementTimeStr, engagment_rect, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.Red);
            }


            // Draw object "Tags"
            if (Tag != string.Empty && (DDD_Global.Instance.TagPosition != TagPositionEnum.INVISIBLE))
            {
                Rectangle tag_rect = font.MeasureString(null, Tag, DrawTextFormat.Center, Color.Black);

                switch (DDD_Global.Instance.TagPosition)
                {
                    case TagPositionEnum.ABOVE:
                        tag_rect.Y = (int)(overlay_rect.Y - tag_rect.Height);
                        tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                        break;
                    case TagPositionEnum.BELOW:
                        if (!DrawUnmanagedAssetLabel && (OwnerID != DDD_Global.Instance.PlayerID))
                        {
                            tag_rect.Y = (int)(overlay_rect.Bottom + 1);
                            tag_rect.X = (int)(overlay_rect.X + ((overlay_rect.Width - tag_rect.Width) * .5f));
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:wshanshan,项目名称:DDD,代码行数:101,代码来源:MapObjects.cs

示例4: AGT_Text

 public AGT_Text(string message, Microsoft.DirectX.Direct3D.Font label_font)
 {
     _font = label_font;
     _label_message = message;
     _message_rect = label_font.MeasureString(null, message, DrawTextFormat.Center | DrawTextFormat.VerticalCenter, Color.White);
     _message_rect.X = 0;
     _message_rect.Y = 0;
     _label_rect.X = 0;
     _label_rect.Y = 0;
     _label_rect.Height = _message_rect.Height;
     _label_rect.Width = (int)(_message_rect.Width + (_message_rect.Width * .2));
 }
开发者ID:wshanshan,项目名称:DDD,代码行数:12,代码来源:AGT_Text.cs

示例5: Render

			public int Render(DrawArgs drawArgs, int x, int y, int yOffset, int width, int height, 
				Microsoft.DirectX.Direct3D.Font drawingFont,
				Microsoft.DirectX.Direct3D.Font wingdingsFont,
				Microsoft.DirectX.Direct3D.Font worldwinddingsFont, 
				LayerMenuItem mouseOverItem)
			{
				if(ParentControl == null)
					ParentControl = drawArgs.parentControl;

				this._x = x;
				this._y = y + yOffset;
				this._width = width;

				int consumedHeight = 20;
				
				System.Drawing.Rectangle textRect = drawingFont.MeasureString(null,
					m_renderableObject.Name,
					DrawTextFormat.None,
					System.Drawing.Color.White.ToArgb());

				consumedHeight = textRect.Height;

				if (m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is WorldWind.Renderable.Icon))
				{
					System.Drawing.SizeF rectF = DrawArgs.Graphics.MeasureString(
						m_renderableObject.Description,
						drawArgs.defaultSubTitleFont,
						width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset)
						);
				
					consumedHeight += (int)rectF.Height + 15;
				}

				lastConsumedHeight = consumedHeight;
				// Layer manager client area height
				int totalHeight = height - y;

				updateList();

				if(yOffset >= -consumedHeight)
				{
					// Part of item or whole item visible
					int color = m_renderableObject.IsOn ? itemOnColor : itemOffColor;
					if(mouseOverItem==this)
					{
						if(!m_renderableObject.IsOn)
							// mouseover + inactive color (black)
							color = 0xff << 24;
						MenuUtils.DrawBox(m_parent.ClientLeft,_y,m_parent.ClientWidth,consumedHeight,0,
							World.Settings.menuOutlineColor, drawArgs.device);
					}

					if(m_renderableObject is WorldWind.Renderable.RenderableObjectList)
					{
						RenderableObjectList rol = (RenderableObjectList)m_renderableObject;
						if(!rol.DisableExpansion)
						{
							worldwinddingsFont.DrawText(
								null,
								(this.isExpanded ? "L" : "A"),
								new System.Drawing.Rectangle(x + this._itemXOffset, _y, this._expandArrowXSize, height),
								DrawTextFormat.None,
								color );
						}
					}

					string checkSymbol = null;
					if(m_renderableObject.ParentList != null && m_renderableObject.ParentList.ShowOnlyOneLayer)
						// Radio check
						checkSymbol = m_renderableObject.IsOn ? "O" : "P";
					else				
						// Normal check
						checkSymbol = m_renderableObject.IsOn ? "N" : "F";

					worldwinddingsFont.DrawText(
							null,
							checkSymbol,
							new System.Drawing.Rectangle(
							x + this._itemXOffset + this._expandArrowXSize,
							_y,
							this._checkBoxXOffset,
							height),
							DrawTextFormat.NoClip,
							color );


					drawingFont.DrawText(
						null,
						m_renderableObject.Name,
						new System.Drawing.Rectangle(
						x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset,
						_y,
						width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset),
						height),
						DrawTextFormat.None,
						color );

					if(m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is WorldWind.Renderable.Icon))
					{
						drawArgs.defaultSubTitleDrawingFont.DrawText(
//.........这里部分代码省略.........
开发者ID:jpespartero,项目名称:WorldWind,代码行数:101,代码来源:Menu.cs


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