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


C# VisualStyleRenderer.DrawBackgroundExcludingArea方法代码示例

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


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

示例1: DrawGroupBox

		public static void DrawGroupBox (Graphics g, Rectangle bounds, string groupBoxText, Font font, Color textColor, TextFormatFlags flags, GroupBoxState state)
		{
			Size font_size = TextRenderer.MeasureText (groupBoxText, font);

			if (Application.RenderWithVisualStyles || always_use_visual_styles == true) {
				VisualStyleRenderer vsr;
				Rectangle new_bounds;

				switch (state) {
					case GroupBoxState.Normal:
					default:
						vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Normal);
						new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 1, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 1);
						break;
					case GroupBoxState.Disabled:
						vsr = new VisualStyleRenderer (VisualStyleElement.Button.GroupBox.Disabled);
						new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2) - 2, bounds.Width, bounds.Height - (int)(font_size.Height / 2) + 2);
						break;
				}

				if (groupBoxText == String.Empty)
					vsr.DrawBackground (g, bounds);
				else
					vsr.DrawBackgroundExcludingArea (g, new_bounds, new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height));

				if (textColor == Color.Empty)
					textColor = vsr.GetColor (ColorProperty.TextColor);

				if (groupBoxText != String.Empty)
					TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
			}
			else {
				// MS has a pretty big bug when rendering the non-visual styles group box.  Instead of using the height
				// part of the bounds as height, they use it as the bottom, so the boxes are drawn in completely different
				// places.  Rather than emulate this bug, we do it correctly.  After googling for a while, I don't think
				// anyone has ever actually used this class for anything, so it should be fine.  :)
				Rectangle new_bounds = new Rectangle (bounds.Left, bounds.Top + (int)(font_size.Height / 2), bounds.Width, bounds.Height - (int)(font_size.Height / 2));
				
				// Don't paint over the background where we are going to put the text
				Region old_clip = g.Clip;
				g.SetClip (new Rectangle (bounds.Left + 9, bounds.Top, font_size.Width - 3, font_size.Height), System.Drawing.Drawing2D.CombineMode.Exclude);
				
				ControlPaint.DrawBorder3D (g, new_bounds, Border3DStyle.Etched);
				
				g.Clip = old_clip;

				if (groupBoxText != String.Empty) {
					if (textColor == Color.Empty)
						textColor = state == GroupBoxState.Normal ? SystemColors.ControlText :
							SystemColors.GrayText;
					TextRenderer.DrawText (g, groupBoxText, font, new Point (bounds.Left + 8, bounds.Top), textColor, flags);
				}
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:54,代码来源:GroupBoxRenderer.cs


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