WinVistaOrLater() static private method

static private WinVistaOrLater ( ) : bool
return bool
Exemplo n.º 1
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
            case NativeMethods.WM_DWMCOMPOSITIONCHANGED:
                if (this.glassSet)
                {
                    this.ExtendFrameIntoClientArea();
                }

                break;

            case NativeMethods.WM_NCHITTEST:
                this.DefWndProc(ref m);

                if (OsUtils.WinVistaOrLater() && VisualStyleRenderer.IsSupported && this.glassSet)
                {
                    if ((int)m.Result == NativeMethods.HTCLIENT)
                    {
                        // Pretend that the mouse was over the title bar, making the form draggable
                        m.Result = (IntPtr)NativeMethods.HTCAPTION;
                        return;
                    }
                }

                break;
            }

            base.WndProc(ref m);
        }
Exemplo n.º 2
0
        private void SearchBox_Resize(object sender, EventArgs e)
        {
            if (this.Height != this.themeHeight)
            {
                // Force the height to always be set to that specified from the theme
                this.Height = this.themeHeight;
            }

            // Vertically center the search / cancel button on the right hand side
            this.button.Left = this.Width - (this.button.Width + 6);
            this.button.Top  = Convert.ToInt32((this.Height - this.button.Height) / 2) + 1;

            // Use the rest of the space for the textbox
            this.textBox.Top   = 4;
            this.textBox.Width = this.button.Left - (this.textBox.Left + 4);

            if (OsUtils.WinVistaOrLater() && VisualStyleRenderer.IsSupported)
            {
                // The textbox is given extra padding as part of the visual style
                this.textBox.Left = 2;
            }
            else
            {
                this.textBox.Left = 6;
            }
        }
Exemplo n.º 3
0
 private void SearchBox_HandleCreated(object sender, EventArgs e)
 {
     if (OsUtils.WinVistaOrLater())
     {
         // Set the theme of this parent control and the edit control, so they are rendered correctly
         Marshal.ThrowExceptionForHR(NativeMethods.SetWindowTheme(this.Handle, "SearchBoxComposited", null));
         Marshal.ThrowExceptionForHR(NativeMethods.SetWindowTheme(this.textBox.Handle, "SearchBoxEditComposited", null));
     }
 }
Exemplo n.º 4
0
        private void SearchBox_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            if (VisualStyleRenderer.IsSupported)
            {
                VisualStyleRenderer searchBoxStyle = null;

                if (OsUtils.WinVistaOrLater())
                {
                    // Fetch the correct style based on the current state
                    searchBoxStyle = new VisualStyleRenderer(NativeMethods.SEARCHBOX, NativeMethods.SBBACKGROUND, this.boxState);
                }
                else
                {
                    searchBoxStyle = new VisualStyleRenderer(VisualStyleElement.TextBox.TextEdit.Normal);
                }

                // Paint the visual style background for the control
                searchBoxStyle.DrawBackground(e.Graphics, new Rectangle(0, 0, this.Width, this.Height));
            }
            else
            {
                // It would be simpler to use e.Graphics.Clear(SystemColors.Window), but that crashes
                // sometimes when running under terminal services due to a bug in GDI+
                using (Brush windowBrush = new SolidBrush(SystemColors.Window))
                {
                    e.Graphics.FillRectangle(windowBrush, 0, 0, this.Width - 1, this.Height - 1);
                }

                // Paint a 'classic textbox' border for the control
                using (Pen controlDark = new Pen(SystemColors.ControlDark))
                {
                    using (Pen controlDarkDark = new Pen(SystemColors.ControlDarkDark))
                    {
                        using (Pen controlLightLight = new Pen(SystemColors.ControlLightLight))
                        {
                            using (Pen controlLight = new Pen(SystemColors.ControlLight))
                            {
                                e.Graphics.DrawLine(controlDark, 0, this.Height, 0, 0);
                                e.Graphics.DrawLine(controlDark, 0, 0, this.Width, 0);
                                e.Graphics.DrawLine(controlDarkDark, 1, this.Height - 1, 1, 1);
                                e.Graphics.DrawLine(controlDarkDark, 1, 1, this.Width - 1, 1);

                                e.Graphics.DrawLine(controlLight, this.Width - 2, 1, this.Width - 2, this.Height - 2);
                                e.Graphics.DrawLine(controlLight, this.Width - 2, this.Height - 2, 1, this.Height - 2);
                                e.Graphics.DrawLine(controlLightLight, this.Width - 1, 0, this.Width - 1, this.Height - 1);
                                e.Graphics.DrawLine(controlLightLight, this.Width - 1, this.Height - 1, 0, this.Height - 1);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public SearchBox()
            : base()
        {
            this.TextChanged   += this.SearchBox_TextChanged;
            this.Resize        += this.SearchBox_Resize;
            this.Paint         += this.SearchBox_Paint;
            this.HandleCreated += this.SearchBox_HandleCreated;

            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);

            // Create the child textbox control for the user to type in, without a border
            this.textBox             = new TextBox();
            this.themeHeight         = this.textBox.Height + 2;
            this.textBox.BorderStyle = BorderStyle.None;
            this.Controls.Add(this.textBox);

            this.textBox.MouseEnter  += this.TextBox_MouseEnter;
            this.textBox.MouseLeave  += this.TextBox_MouseLeave;
            this.textBox.GotFocus    += this.TextBox_GotFocus;
            this.textBox.LostFocus   += this.TextBox_LostFocus;
            this.textBox.TextChanged += this.TextBox_TextChanged;
            this.textBox.KeyDown     += this.TextBox_KeyDown;

            // Create a picturebox to display the search icon and cancel 'button'
            this.button           = new PictureBox();
            this.button.BackColor = Color.Transparent;
            this.button.Image     = Properties.Resources.search_icon;
            this.button.SizeMode  = PictureBoxSizeMode.AutoSize;
            this.Controls.Add(this.button);

            this.button.MouseEnter += this.Button_MouseEnter;
            this.button.MouseLeave += this.Button_MouseLeave;
            this.button.MouseDown  += this.Button_MouseDown;
            this.button.MouseUp    += this.Button_MouseUp;
            this.button.MouseClick += this.Button_MouseClick;

            // Work out the height that the search box should be displayed
            if (OsUtils.WinVistaOrLater() && VisualStyleRenderer.IsSupported)
            {
                VisualStyleRenderer sizeStyle = new VisualStyleRenderer(NativeMethods.SEARCHBOX, NativeMethods.SBBACKGROUND, NativeMethods.SBB_NORMAL);

                using (Graphics sizeGraphics = this.CreateGraphics())
                {
                    this.themeHeight = sizeStyle.GetPartSize(sizeGraphics, ThemeSizeType.True).Height;
                }
            }
        }
Exemplo n.º 6
0
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if (OsUtils.WinVistaOrLater() && VisualStyleRenderer.IsSupported)
            {
                if (!OsUtils.CompositionEnabled())
                {
                    e.Graphics.DrawLine(this.nonAeroBorder, 0, e.AffectedBounds.Bottom - 1, e.ToolStrip.Width, e.AffectedBounds.Bottom - 1);
                }
            }
            else
            {
                e.Graphics.DrawLine(this.tabBorder, 0, e.AffectedBounds.Bottom - 1, e.ToolStrip.Width, e.AffectedBounds.Bottom - 1);
            }

            ToolStripButton @checked = null;

            // Find the currently checked ToolStripButton
            foreach (ToolStripItem item in e.ToolStrip.Items)
            {
                ToolStripButton buttonItem = item as ToolStripButton;

                if (buttonItem != null && buttonItem.Checked)
                {
                    @checked = buttonItem;
                    break;
                }
            }

            if (@checked != null)
            {
                // Extend the bottom of the tab over the client area border, joining the tab onto the main client area
                using (SolidBrush toolbarBkg = new SolidBrush(this.GetActiveTabBtmCol(e.ToolStrip, @checked)))
                {
                    e.Graphics.FillRectangle(toolbarBkg, new Rectangle(@checked.Bounds.Left, @checked.Bounds.Bottom, @checked.Bounds.Width - TabSeparation, e.ToolStrip.Bounds.Bottom - @checked.Bounds.Bottom));
                }

                e.Graphics.DrawLine(this.tabBorder, @checked.Bounds.Left, @checked.Bounds.Bottom, @checked.Bounds.Left, e.AffectedBounds.Bottom);
                e.Graphics.DrawLine(this.tabBorder, @checked.Bounds.Right - TabSeparation, @checked.Bounds.Bottom, @checked.Bounds.Right - TabSeparation, e.AffectedBounds.Bottom);
            }
        }
Exemplo n.º 7
0
 protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
 {
     if (OsUtils.CompositionEnabled())
     {
         // Set the background colour to transparent to make it glass
         e.Graphics.Clear(Color.Transparent);
     }
     else
     {
         if (VisualStyleRenderer.IsSupported && OsUtils.WinVistaOrLater())
         {
             // Set the background the same as the title bar to give the illusion of an extended frame
             if (this.isActive)
             {
                 // It would be simpler to use e.Graphics.Clear(SystemColors.GradientActiveCaption), but
                 // that crashes sometimes when running under terminal services due to a bug in GDI+
                 using (Brush backgroundBrush = new SolidBrush(SystemColors.GradientActiveCaption))
                 {
                     e.Graphics.FillRectangle(backgroundBrush, e.AffectedBounds);
                 }
             }
             else
             {
                 // It would be simpler to use e.Graphics.Clear(SystemColors.GradientInactiveCaption), but
                 // that crashes sometimes when running under terminal services due to a bug in GDI+
                 using (Brush backgroundBrush = new SolidBrush(SystemColors.GradientInactiveCaption))
                 {
                     e.Graphics.FillRectangle(backgroundBrush, e.AffectedBounds);
                 }
             }
         }
         else
         {
             base.OnRenderToolStripBackground(e);
         }
     }
 }