Esempio n. 1
0
        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());
                }
            }
        }