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


C# Font.GetHashCode方法代码示例

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


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

示例1: MeasureText

		public static SizeF MeasureText (Graphics g, string text, Font font)
		{
			// Due to the way the TextBox currently works, it measures each
			// character one at a time.  And it does this alot.  So here we
			// are implementing a cache for each font/character combination
			// measurement.  Since the number of fonts and number of characters
			// used tends to be small, this is a good performance gain for
			// not too much memory.
			if (text.Length == 1) {
				// If g.VisibleClipBounds is {X=0, Y=0, Width=1, Height=1}, then some characters
				// (in some fonts for some point sizes) return a different width then when the
				// VisibleClipBounds has a different (usually but not always more reasonable) value.
				// This state of the Graphics object can occur during initialization of text boxes
				// with preset Text values. See https://bugzilla.xamarin.com/show_bug.cgi?id=26258
				// for more details.
				string sep;
				var bounds = g.VisibleClipBounds;
				if (bounds.Width == 1 && bounds.Height == 1 && bounds.X == 0 && bounds.Y == 0)
					sep = "-1x1|";
				else
					sep = "|";
				string key = font.GetHashCode ().ToString () + sep + text;
				
				if (measure_cache.ContainsKey (key)) {
					return (SizeF)measure_cache[key];
				} else {
					SizeF size;
					
					if (!use_textrenderer)
						size = g.MeasureString (text, font, 10000, sf_nonprinting);
					else
						size = TextRenderer.MeasureTextInternal (g, text, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix, false);
				
					measure_cache[key] = size;
				
					return size;
				}
			}
			
			if (!use_textrenderer)
				return g.MeasureString (text, font, 10000, sf_nonprinting);
			else
				return TextRenderer.MeasureTextInternal (g, text, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix, false);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:44,代码来源:TextBoxTextRenderer.cs

示例2: MeasureText

		public static SizeF MeasureText (Graphics g, string text, Font font)
		{
			// Due to the way the TextBox currently works, it measures each
			// character one at a time.  And it does this alot.  So here we
			// are implementing a cache for each font/character combination
			// measurement.  Since the number of fonts and number of characters
			// used tends to be small, this is a good performance gain for
			// not too much memory.
			if (text.Length == 1) {
				string key = font.GetHashCode ().ToString () + "|" + text;
				
				if (measure_cache.ContainsKey (key)) {
					return (SizeF)measure_cache[key];
				} else {
					SizeF size;
					
					if (!use_textrenderer)
						size = g.MeasureString (text, font, 10000, sf_nonprinting);
					else
						size = TextRenderer.MeasureTextInternal (g, text, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix, false);
				
					measure_cache[key] = size;
				
					return size;
				}
			}
			
			if (!use_textrenderer)
				return g.MeasureString (text, font, 10000, sf_nonprinting);
			else
				return TextRenderer.MeasureTextInternal (g, text, font, Size.Empty, TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix, false);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:32,代码来源:TextBoxTextRenderer.cs

示例3: GetHashCode_NameDiffers_HashesNotEqual

        public void GetHashCode_NameDiffers_HashesNotEqual()
        {
            Font f1 = new Font("Arial", 8.25F, GraphicsUnit.Point);
            Font f2 = new Font("Courier New", 8.25F, GraphicsUnit.Point);

            Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
                "Hashcodes should differ if _name member differs");
        }
开发者ID:frje,项目名称:SharpLang,代码行数:8,代码来源:TestFont.cs

示例4: GetHashCode_StyleEqualsGdiCharSet_HashesNotEqual

        public void GetHashCode_StyleEqualsGdiCharSet_HashesNotEqual()
        {
            Font f1 = new Font("Arial", 8.25F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
            Font f2 = new Font("Arial", 8.25F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(1)));

            Assert.IsFalse(f1.GetHashCode() == f2.GetHashCode(),
                "Hashcodes should differ if _style member differs");
        }
开发者ID:frje,项目名称:SharpLang,代码行数:8,代码来源:TestFont.cs

示例5: FontUniqueHashCode

		public void FontUniqueHashCode ()
		{
			Font f1 = new Font ("Arial", 14);
			Font f2 = new Font ("Arial", 12);
			Font f3 = new Font (f1, FontStyle.Bold);

			Assert.IsFalse (f1.GetHashCode () == f2.GetHashCode (), "1) Fonts with different sizes should have different HashCodes");
			Assert.IsFalse (f1.GetHashCode () == f3.GetHashCode (), "2) Fonts with different styles should have different HashCodes");
		}
开发者ID:frje,项目名称:SharpLang,代码行数:9,代码来源:TestFont.cs


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