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


C# Graphics.SelectFont方法代码示例

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


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

示例1: CharSpan

		// Calculate and draw the string by drawing each line.
		public void Draw
					(Graphics graphics, String text, Font font,
					 Rectangle drawLayout, StringFormat format, Brush brush)
				{
					// set the current graphics
					this.graphics = graphics;

					// set the current toolkit graphics
					this.toolkitGraphics = graphics.ToolkitGraphics;

					// set the current text
					this.text = text;

					// set the current font
					this.font = font;

					// set the current layout rectangle
					this.layout = drawLayout;

					// set the current brush
					this.brush = brush;

					// ensure we have a string format
					if(format == null) { format = SF_DEFAULT; }

					// set the current string format
					this.format = format;

					// set the default hotkey index
					this.hotkeyIndex = -1;

					// set the current line height
					lineHeight = font.Height;

					// set the only whole lines flag
					onlyWholeLines = (((format.FormatFlags &
					                    StringFormatFlags.LineLimit) != 0) ||
					                  ((format.Trimming &
					                    StringTrimming.None) != 0));

					// set the index of the next character
					nextIndex = 0;

					// set the current line space usage
					lineSpaceUsedUp = 0;

					// set the current line number
					lineNumber = 0;

					// set the previous span ended in new line flag
					prevIsNewLine = false;

					// select the current font into the graphics context
					graphics.SelectFont(font);

					// select the current brush into the graphics context
					graphics.SelectBrush(brush);

					// set the current text start
					int textStart = 0;

					// set the current text length
					int textLength = 0;

					// set the current text width
					int textWidth = 0;

					// get the actual hotkey index, if needed
					if(format.HotkeyPrefix != HotkeyPrefix.None)
					{
						// get the hotkey index
						hotkeyIndex = text.IndexOf('&');

						// handle the hotkey as needed
						if(hotkeyIndex != -1)
						{
							if(hotkeyIndex >= (text.Length - 1) ||
							   Char.IsControl(text[hotkeyIndex + 1]))
							{
								// no need for this anymore
								hotkeyIndex = -1;
							}
							else
							{
								// remove the hotkey character
								text = text.Substring(0, hotkeyIndex) +
								       text.Substring(hotkeyIndex + 1);

								// set the current text
								this.text = text;

								// prepare to show or hide the underline
								if(format.HotkeyPrefix == HotkeyPrefix.Show)
								{
									// get the underline font
									underlineFont = new Font
										(font, font.Style | FontStyle.Underline);
								}
								else
//.........这里部分代码省略.........
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:101,代码来源:Graphics.cs

示例2: Size

		// Calculate text metrics information.
		//
		// Note that this is currently broken. Turn this on at your own risk.
		public Size GetBounds
					(Graphics graphics, String text, Font font,
					 SizeF layoutSize, StringFormat format,
					 out int charactersFitted, out int linesFilled)
				{
					// set the current graphics
					this.graphics = graphics;

					// set the current toolkit graphics
					this.toolkitGraphics = graphics.ToolkitGraphics;

					// set the current text
					this.text = text;

					// set the current font
					this.font = font;

					// ensure we have a string format
					if(format == null) { format = SF_DEFAULT; }

					// set the current string format
					this.format = format;

					// set the current layout rectangle
					this.layout = new Rectangle
						(0, 0, (int)layoutSize.Width, (int)layoutSize.Height);

					// set the current line height
					lineHeight = font.Height;

					// set the only whole lines flag
					onlyWholeLines = (((format.FormatFlags &
					                    StringFormatFlags.LineLimit) != 0) ||
					                  ((format.Trimming &
					                    StringTrimming.None) != 0));

					// set the index of the next character
					nextIndex = 0;

					// set the current line space usage
					lineSpaceUsedUp = 0;

					// set the previous span ended in new line flag
					prevIsNewLine = false;

					// select the current font into the graphics context
					graphics.SelectFont(font);

					// set the text width
					int textWidth = 0;

					// set the maximum width
					int maxWidth = 0;

					// set the default characters fitted
					charactersFitted = 0;

					// set the default lines filled
					linesFilled = 0;

					// remove the hotkey prefix, if needed
					if(format.HotkeyPrefix != HotkeyPrefix.None)
					{
						// get the hotkey index
						hotkeyIndex = text.IndexOf('&');

						// handle the hotkey as needed
						if(hotkeyIndex != -1)
						{
							if(hotkeyIndex < (text.Length - 1) &&
							   !Char.IsControl(text[hotkeyIndex + 1]))
							{
								// remove the hotkey character
								text = text.Substring(0, hotkeyIndex) +
								       text.Substring(hotkeyIndex + 1);

								// set the current text
								this.text = text;

								// update characters fitted
								++charactersFitted;
							}

							// no need for this anymore
							hotkeyIndex = -1;
						}
					}

					// create character spans
					CharSpan span = new CharSpan();
					CharSpan prev = new CharSpan();

					// set the first span flag
					bool firstSpan = true;

					// set the measure trailing spaces flag
					bool mts = ((format.FormatFlags &
//.........这里部分代码省略.........
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:101,代码来源:Graphics.cs

示例3:

		// Measures one full line. Updates the positions of the characters in that line relative to 0,0
		private void MeasureLine
					(ref Rectangle[] bounds, ref int currentPos,
					 ref string text, float maxX, Graphics g, Font f,
					 bool vertical, bool noWrap)
				{
					// set the initial position
					int initialPos = currentPos;

					// set the default x position
					int x = (int)(f.SizeInPoints*g.DpiX/369.7184);

					// set the default y position
					int y = 0;

					// ??
					do
					{
						// get the current character
						char c = text[currentPos];

						// check for the end of the line
						if(c == '\n')
						{
							// move past the end of the line
							currentPos++;

							// we're done
							return;
						}

						// Ignore returns
						if(c != '\r')
						{
							//TODO use Platform specific measure function & take into account kerning

							// get the size of the current character
							g.SelectFont(f);
							int charactersFitted, linesFilled;
							Size s = g.ToolkitGraphics.MeasureString(c.ToString(), null, null, out charactersFitted, out linesFilled, false);
							s.Height = f.Height;

							// ??
							int newX = x;

							// ??
							int newY = y;

							// ??
							if(vertical)
							{
								newX += s.Height;
							}
							else
							{
								newX += s.Width;
							}

							// ??
							if(newX > maxX)
							{
								// ??
								if(noWrap) { return; }

								// Backtrack to wrap the word

								// ??
								for(int i = currentPos; i > initialPos; i--)
								{
									// ??
									if(text[i] == ' ')
									{
										// Swallow the space

										// ??
										bounds[i++] = Rectangle.Empty;

										// ??
										currentPos = i;

										// ??
										return;
									}
								}

								// ??
								return;
							}
							else
							{
								// ??
								if(vertical)
								{
									bounds[currentPos] = new Rectangle
										(y, x, s.Height, s.Width - 1);
								}
								else
								{
									bounds[currentPos] = new Rectangle
										(x, y, s.Width, s.Height - 1);
//.........这里部分代码省略.........
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:101,代码来源:Graphics.cs


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