// <Snippet30> // Calculate and set the clipping region for the control // so that the corners of the title bar are rounded. private void SetClipRegion() { if (!Application.RenderWithVisualStyles) { return; } using (Graphics g = this.CreateGraphics()) { // Get the current region for the window caption. if (SetRenderer(windowElements["windowCaption"])) { Region clipRegion = renderer.GetBackgroundRegion( g, elementRectangles["windowCaption"]); // Get the client rectangle, but exclude the region // of the window caption. int height = (int)clipRegion.GetBounds(g).Height; Rectangle nonCaptionRect = new Rectangle( ClientRectangle.X, ClientRectangle.Y + height, ClientRectangle.Width, ClientRectangle.Height - height); // Add the rectangle to the caption region, and // make this region the form's clipping region. clipRegion.Union(nonCaptionRect); this.Region = clipRegion; } } }
public override Region GetRegion(Graphics dc, Rectangle rect) { Region ret; if (IsDefined(VisualStyleElement.ToolTip.Balloon.Normal)) { VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal); ret = renderer.GetBackgroundRegion(dc, rect); } else { ret = new Region(rect); } return(ret); }
protected void UpdateRegion() { if (BackgroundRenderer == null) { return; } try { if (BackgroundRenderer.IsBackgroundPartiallyTransparent()) { using (var g = this.CreateGraphics()) this.Region = BackgroundRenderer.GetBackgroundRegion(g, ClientRectangle); } } catch { } }
public static Region GetRegion(IDeviceContext dc, Size minSize, Size maxSize, string title, string text, ToolTipIcon icon, Padding padding) { Region ret; Rectangle titleRect; Rectangle rect = GetRect(dc, minSize, maxSize, title, text, out titleRect, icon, padding); if (Application.RenderWithVisualStyles) { VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ToolTip.Balloon.Normal); ret = renderer.GetBackgroundRegion(dc, rect); } else { throw new NotImplementedException(); } return(ret); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { if (treeView1.SelectedNode != null) { Graphics g = Graphics.FromHwnd(this.Handle); g.Clear(this.BackColor); TextY = 0; if (VisualStyleInformation.IsSupportedByOS) { DrawText(g, "VisualStyles supported by OS"); } else { DrawText(g, "VisualStyles not supported by OS."); return; } if (VisualStyleInformation.IsEnabledByUser) { DrawText(g, "VisualStyles enabled by user."); } else { DrawText(g, "VisualStyles not enabled by user."); return; } // Create the VisualStyleElement MethodInfo m = (MethodInfo)treeView1.SelectedNode.Tag; VisualStyleElement vse = (VisualStyleElement)m.Invoke(null, null); if (!VisualStyleRenderer.IsElementDefined(vse)) { DrawText(g, treeView1.SelectedNode.Text + " is not defined by the current style."); return; } try { // Create the VisualStyleRenderer if (vsr == null) { vsr = new VisualStyleRenderer(vse); } else { vsr.SetParameters(vse); } // Draw some pretty graphics TextY += 25; vsr.DrawBackground(g, new Rectangle(250, TextY, 25, 25)); vsr.DrawBackground(g, new Rectangle(350, TextY, 50, 50)); vsr.DrawBackground(g, new Rectangle(450, TextY, 50, 50), new Rectangle(450, TextY, 25, 25)); TextY += 75; // Test some other methods DrawText(g, "GetBackgroundContentRectangle: " + vsr.GetBackgroundContentRectangle(g, new Rectangle(300, 0, 300, 50)).ToString()); DrawText(g, "GetBackgroundExtent: " + vsr.GetBackgroundExtent(g, new Rectangle(300, 0, 300, 50)).ToString()); DrawText(g, "GetBoolean: " + vsr.GetBoolean(BooleanProperty.MirrorImage).ToString()); DrawText(g, "GetEnumValue: " + vsr.GetEnumValue(EnumProperty.VerticalAlignment).ToString()); DrawText(g, "GetFilename: " + vsr.GetFilename(FilenameProperty.ImageFile).ToString()); DrawText(g, "GetInteger: " + vsr.GetInteger(IntegerProperty.BorderSize).ToString()); DrawText(g, "GetMargins: " + vsr.GetMargins(g, MarginProperty.CaptionMargins).ToString()); DrawText(g, "GetPartSize: " + vsr.GetPartSize(g, ThemeSizeType.Draw).ToString()); DrawText(g, "GetPoint: " + vsr.GetPoint(PointProperty.MinSize).ToString()); DrawText(g, "GetString: " + vsr.GetString(StringProperty.Text).ToString()); DrawText(g, "GetTextExtent: " + vsr.GetTextExtent(g, "HeyThere!", TextFormatFlags.Default).ToString()); DrawText(g, "GetTextMetrics: " + vsr.GetTextMetrics(g).Ascent.ToString()); DrawText(g, "GetBackgroundRegion: " + vsr.GetBackgroundRegion(g, this.ClientRectangle).GetBounds(g).ToString()); DrawText(g, "HitTestBackground: " + vsr.HitTestBackground(g, this.ClientRectangle, new Point(300, 300), HitTestOptions.Caption).ToString()); DrawText(g, "Author: " + VisualStyleInformation.Author); DrawText(g, "ColorScheme: " + VisualStyleInformation.ColorScheme); DrawText(g, "Company: " + VisualStyleInformation.Company); DrawText(g, "ControlHighlightHot: " + VisualStyleInformation.ControlHighlightHot.ToString()); DrawText(g, "Copyright: " + VisualStyleInformation.Copyright); DrawText(g, "Description: " + VisualStyleInformation.Description); DrawText(g, "DisplayName: " + VisualStyleInformation.DisplayName); DrawText(g, "MinimumColorDepth: " + VisualStyleInformation.MinimumColorDepth.ToString()); DrawText(g, "Size: " + VisualStyleInformation.Size.ToString()); DrawText(g, "SupportsFlatMenus: " + VisualStyleInformation.SupportsFlatMenus.ToString()); DrawText(g, "TextControlBorder: " + VisualStyleInformation.TextControlBorder.ToString()); DrawText(g, "Url: " + VisualStyleInformation.Url); DrawText(g, "Version: " + VisualStyleInformation.Version.ToString()); } catch (Exception ex) { System.Console.WriteLine(ex.ToString()); } } }