/// ------------------------------------------------------------------------------------
		public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
		{
			Debug.Assert(col != null);
			Debug.Assert(col is DataGridViewCheckBoxColumn);
			Debug.Assert(col.DataGridView != null);

			_col = col;
			_owningGrid = col.DataGridView;
			_owningGrid.HandleDestroyed += HandleHandleDestroyed;
			_owningGrid.CellPainting += HandleHeaderCellPainting;
			_owningGrid.CellMouseMove += HandleHeaderCellMouseMove;
			_owningGrid.CellMouseClick += HandleHeaderCellMouseClick;
			_owningGrid.CellContentClick += HandleDataCellCellContentClick;
			_owningGrid.Scroll += HandleGridScroll;
			_owningGrid.RowsAdded += HandleGridRowsAdded;
			_owningGrid.RowsRemoved += HandleGridRowsRemoved;

			if (!BetterGrid.CanPaintVisualStyle())
				_szCheckBox = new Size(13, 13);
			else
			{
				var element = VisualStyleElement.Button.CheckBox.CheckedNormal;
				var renderer = new VisualStyleRenderer(element);
				using (var g = _owningGrid.CreateGraphics())
					_szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public CheckBoxColumnHeaderHandler(DataGridViewColumn col)
		{
			Debug.Assert(col != null);
			Debug.Assert(col is DataGridViewCheckBoxColumn);
			Debug.Assert(col.DataGridView != null);

			m_col = col;
			m_grid = col.DataGridView;
			m_grid.HandleDestroyed += HandleHandleDestroyed;
			m_grid.CellPainting += HandleHeaderCellPainting;
			m_grid.CellMouseMove += HandleHeaderCellMouseMove;
			m_grid.ColumnHeaderMouseClick += HandleHeaderCellMouseClick;
			m_grid.CellContentClick += HandleDataCellCellContentClick;
			m_grid.Scroll += HandleGridScroll;
			m_grid.RowsAdded += HandleGridRowsAdded;
			m_grid.RowsRemoved += HandleGridRowsRemoved;

			if (!Application.RenderWithVisualStyles)
			{
				m_szCheckBox = new Size(13, 13);
			}
			else
			{
				var element = VisualStyleElement.Button.CheckBox.CheckedNormal;
				var renderer = new VisualStyleRenderer(element);
				using (var g = m_grid.CreateGraphics())
					m_szCheckBox = renderer.GetPartSize(g, ThemeSizeType.True);
			}

			m_stringFormat = new StringFormat(StringFormat.GenericTypographic);
			m_stringFormat.Alignment = StringAlignment.Center;
			m_stringFormat.LineAlignment = StringAlignment.Center;
			m_stringFormat.Trimming = StringTrimming.EllipsisCharacter;
			m_stringFormat.FormatFlags |= StringFormatFlags.NoWrap;
		}
示例#3
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;
                }
            }
        }
示例#4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Draws the button in the cell.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void DrawButton(Graphics g, Rectangle rcbtn, int rowIndex)
		{
			if (!InternalShowButton(rowIndex))
				return;

			bool paintComboButton = (OwningButtonColumn == null ? false :
				OwningButtonColumn.UseComboButtonStyle);

			VisualStyleElement element = (paintComboButton ?
				GetVisualStyleComboButton() : GetVisualStylePushButton());

			if (PaintingHelper.CanPaintVisualStyle(element))
			{
				VisualStyleRenderer renderer = new VisualStyleRenderer(element);

				if (!OwningButtonColumn.DrawDefaultComboButtonWidth)
					renderer.DrawBackground(g, rcbtn);
				else
				{
					Rectangle rc = rcbtn;
					Size sz = renderer.GetPartSize(g, rc, ThemeSizeType.True);
					rc.Width = sz.Width + 2;
					rc.X = (rcbtn.Right - rc.Width);
					renderer.DrawBackground(g, rc);
				}
			}
			else
			{
				ButtonState state = (m_mouseDownOnButton && m_mouseOverButton && m_enabled ?
					ButtonState.Pushed : ButtonState.Normal);

				if (!m_enabled)
					state |= ButtonState.Inactive;

				if (paintComboButton)
					ControlPaint.DrawComboButton(g, rcbtn, state);
				else
					ControlPaint.DrawButton(g, rcbtn, state);
			}

			string buttonText = (OwningButtonColumn == null ? null : OwningButtonColumn.ButtonText);
			if (string.IsNullOrEmpty(buttonText))
				return;

			Font buttonFont = (OwningButtonColumn == null ?
				SystemInformation.MenuFont : OwningButtonColumn.ButtonFont);

			// Draw text
			TextFormatFlags flags = TextFormatFlags.HorizontalCenter |
				TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine |
				TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis |
				TextFormatFlags.NoPadding | TextFormatFlags.PreserveGraphicsClipping;

			Color clrText = (m_enabled ? SystemColors.ControlText : SystemColors.GrayText);
			TextRenderer.DrawText(g, buttonText, buttonFont, rcbtn, clrText, flags);
		}
示例#5
0
		private void SetLayout()
		{
			if (isMin6 && Application.RenderWithVisualStyles)
			{
				VisualStyleRenderer theme;
				using (Graphics g = this.CreateGraphics())
				{
					// Back button
					theme = new VisualStyleRenderer(VisualStyleElementEx.Navigation.BackButton.Normal);
					Size bbSize = theme.GetPartSize(g, ThemeSizeType.Draw);

					// Title
					theme.SetParameters(VisualStyleElementEx.AeroWizard.TitleBar.Active);
					titleBar.Height = Math.Max(theme.GetMargins2(g, MarginProperty.ContentMargins).Top, bbSize.Height + 2);
					titleBar.ColumnStyles[0].Width = bbSize.Width + 4F;
					titleBar.ColumnStyles[1].Width = titleImageIcon != null ? titleImageList.ImageSize.Width + 4F : 0;
					backButton.Size = bbSize;

					// Header
					theme.SetParameters(VisualStyleElementEx.AeroWizard.HeaderArea.Normal);
					headerLabel.Margin = theme.GetMargins2(g, MarginProperty.ContentMargins);
					headerLabel.ForeColor = theme.GetColor(ColorProperty.TextColor);

					// Content
					theme.SetParameters(VisualStyleElementEx.AeroWizard.ContentArea.Normal);
					this.BackColor = theme.GetColor(ColorProperty.FillColor);
					Padding cp = theme.GetMargins2(g, MarginProperty.ContentMargins);
					contentArea.ColumnStyles[0].Width = cp.Left;
					contentArea.RowStyles[1].Height = cp.Bottom;

					// Command
					theme.SetParameters(VisualStyleElementEx.AeroWizard.CommandArea.Normal);
					cp = theme.GetMargins2(g, MarginProperty.ContentMargins);
					commandArea.RowStyles[0].Height = cp.Top;
					commandArea.RowStyles[2].Height = cp.Bottom;
					commandArea.ColumnStyles[2].Width = contentArea.ColumnStyles[2].Width = cp.Right;
				}
			}
			else
			{
				backButton.Size = new Size(Properties.Resources.BackBtnStrip.Width, Properties.Resources.BackBtnStrip.Height / 4);
			}
		}
示例#6
0
        private void DrawGlyph( Graphics g, Point p, bool expanded )
        {
            if( VisualStyleRenderer.IsSupported )
            {
                VisualStyleElement vse = expanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                VisualStyleRenderer vsr = new VisualStyleRenderer( vse );
                Size ecSize = vsr.GetPartSize( g, ThemeSizeType.Draw );

                vsr.DrawBackground( g, new Rectangle( p.X, p.Y, ecSize.Width, ecSize.Height ) );
            }
            else
            {
                g.FillRectangle( SystemBrushes.Window, new Rectangle( p.X, p.Y, 8, 8 ) );

                using( Pen pen = new Pen( Color.FromArgb( 128, 128, 128 ) ))
                {
                    g.DrawRectangle( pen, new Rectangle( p.X, p.Y, 8, 8 ) );
                }

                using( Pen pen = new Pen( Color.Black ) )
                {
                    g.DrawLine( pen, new Point( p.X + 2, p.Y + 4 ), new Point( p.X + 6, p.Y + 4 ) );

                    if( !expanded )
                    {
                        g.DrawLine( pen, new Point( p.X + 4, p.Y + 2 ), new Point( p.X + 4, p.Y + 6 ) );
                    }
                }
            }
        }
		public static Size GetSizeBoxSize (Graphics g, ScrollBarState state)
		{
			if (!IsSupported)
				throw new InvalidOperationException ();

			VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.SizeBox.LeftAlign);
			
			return vsr.GetPartSize(g, ThemeSizeType.Draw);
		}
		protected override void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
		{
			if (!RenderClientAreas) {
				base.DrawStatusBarSizingGrip (dc, clip, sb, area);
				return;
			}
			VisualStyleElement element = VisualStyleElement.Status.Gripper.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.DrawStatusBarSizingGrip (dc, clip, sb, area);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			Rectangle sizing_grip_rectangle = new Rectangle (Point.Empty, renderer.GetPartSize (dc, ThemeSizeType.True));
			sizing_grip_rectangle.X = sb.Width - sizing_grip_rectangle.Width;
			sizing_grip_rectangle.Y = sb.Height - sizing_grip_rectangle.Height;
			renderer.DrawBackground (dc, sizing_grip_rectangle, clip);
		}
		public static Size GetTopPointingThumbSize (Graphics g, TrackBarThumbState state)
		{
			if (!IsSupported)
				throw new InvalidOperationException ();

			VisualStyleRenderer vsr;

			switch (state) {
				case TrackBarThumbState.Disabled:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Disabled);
					break;
				case TrackBarThumbState.Hot:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Hot);
					break;
				case TrackBarThumbState.Normal:
				default:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Normal);
					break;
				case TrackBarThumbState.Pressed:
					vsr = new VisualStyleRenderer (VisualStyleElement.TrackBar.ThumbTop.Pressed);
					break;
			}

			return vsr.GetPartSize (g, ThemeSizeType.Draw);
		}
 protected override Size GetCloseButtonSize(Graphics dc, TooltipCloseButtonState buttonState)
 {
     VisualStyleElement btn = GetCloseButtonVS(buttonState);
     if (IsDefined(btn))
     {
         VisualStyleRenderer renderer = new VisualStyleRenderer(btn);
         return renderer.GetPartSize(dc, ThemeSizeType.True);
     }
     else
         return new Size(10, 10);
 }
			protected override void OnPaint(PaintEventArgs e)
			{
				if (VisualStyleRenderer.IsSupported
				    && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Normal)
				    && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Hot)
				    && VisualStyleRenderer.IsElementDefined(VisualStyleElement.ExplorerBar.HeaderClose.Pressed))
				{
					VisualStyleElement element;
					if (!this.ShowGreyed && IsMouseOver(this.ClientRectangle))
						element = IsLeftMouseButtonPressed() ? VisualStyleElement.ExplorerBar.HeaderClose.Pressed : VisualStyleElement.ExplorerBar.HeaderClose.Hot;
					else
						element = VisualStyleElement.ExplorerBar.HeaderClose.Normal;

					VisualStyleRenderer renderer = new VisualStyleRenderer(element);
					Size size = renderer.GetPartSize(e.Graphics, this.ClientRectangle, ThemeSizeType.True);
					using (Bitmap bmp = new Bitmap(size.Width, size.Height))
					{
						using (Graphics g = Graphics.FromImage(bmp))
						{
							renderer.DrawBackground(g, this.ClientRectangle);
						}
						e.Graphics.DrawImage(bmp, this.ClientRectangle);
					}
				}
				else
				{
					const int lineWidth = 2;

					if (this.ShowGreyed)
						ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Inactive);
					else if (IsMouseOver(this.ClientRectangle) && IsLeftMouseButtonPressed())
						ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Pushed);
					else
						ControlPaint.DrawButton(e.Graphics, this.ClientRectangle, ButtonState.Normal);

					using (Pen p = new Pen(this.ShowGreyed ? SystemBrushes.GrayText : SystemBrushes.ControlText, lineWidth))
					{
						Rectangle crossBounds = this.ClientRectangle;
						crossBounds.Location += new Size(2*lineWidth, 2*lineWidth);
						crossBounds.Size -= new Size(4*lineWidth + 1, 4*lineWidth + 1);
						e.Graphics.DrawLine(p, crossBounds.Left, crossBounds.Top, crossBounds.Right, crossBounds.Bottom);
						e.Graphics.DrawLine(p, crossBounds.Left, crossBounds.Bottom, crossBounds.Right, crossBounds.Top);
					}
				}
			}
 public static Rectangle GetCloseButtonRect(IDeviceContext dc, Rectangle rect, Padding padding, ToolTipBalloonCloseButtonState buttonState)
 {
     VisualStyleElement btn = GetCloseButtonVS(buttonState);
     VisualStyleRenderer renderer = new VisualStyleRenderer(btn);
     Size btnSize = renderer.GetPartSize(dc, ThemeSizeType.True);
     Point btnPos = new Point(rect.Right - padding.Right - btnSize.Width, rect.Top + padding.Top);
     Rectangle btnRect = new Rectangle(btnPos, btnSize);
     return btnRect;
 }
        protected override void OnRenderImageMargin(ToolStripRenderEventArgs e)
        {
            if (e.ToolStrip.IsDropDown && IsSupported)
            {
                var renderer = new VisualStyleRenderer("menu", 13, 0);


                var themeMargins = renderer.GetMargins(e.Graphics, MarginProperty.CaptionMargins);

                themeMargins.Right+=2;

                int num = e.ToolStrip.Width - e.ToolStrip.DisplayRectangle.Width - themeMargins.Left - themeMargins.Right - 1 - e.AffectedBounds.Width;
                var bounds = e.AffectedBounds;
                bounds.Y += 2;
                bounds.Height -= 4;
                int width = renderer.GetPartSize(e.Graphics, ThemeSizeType.True).Width;
                if (e.ToolStrip.RightToLeft == RightToLeft.Yes)
                {
                    bounds = new Rectangle(bounds.X - num, bounds.Y, width, bounds.Height);
                    bounds.X += width;
                }
                else
                {
                    bounds = new Rectangle(bounds.Width + num - width, bounds.Y, width, bounds.Height);
                }
                renderer.DrawBackground(e.Graphics, bounds);
            }
            else
            {
                base.OnRenderImageMargin(e);
            }
        }
示例#14
0
            public Size MeasureTreeNode( Graphics g, SuperTree.ITreeInfo treeInfo, SuperTree.TreeNode treeNode, bool needsWidth, bool needsHeight )
            {
                string text = treeNode.Text.Replace( "&", "&&" );

                Size textSize = WinFormsUtility.Drawing.GdiPlusEx.MeasureString( g, text, treeNode.Font, int.MaxValue );
                Size ecSize;

                if( VisualStyleRenderer.IsSupported )
                {
                    VisualStyleElement vse = VisualStyleElement.TreeView.Glyph.Opened;
                    VisualStyleRenderer vsr = new VisualStyleRenderer( vse );

                    ecSize = vsr.GetPartSize( g, ThemeSizeType.Draw );
                }
                else
                {
                    ecSize = new Size( 9, 9 );
                }

                int width = (int) textSize.Width + _leftSep + _ecSep + ecSize.Width + _rightSep + 16;
                int height = (int) textSize.Height;

                if( treeNode.Icon != null )
                {
                    width += _imageSep + treeNode.Icon.Size.Width;
                    height = Math.Max( height, treeNode.Icon.Size.Height );
                }

                height += _verticalSep;

                return new Size( width, height );
            }
示例#15
0
 private static void CalcSize(Graphics g)
 {
     if (VisualStyleInformation.IsEnabledByUser) {
         VisualStyleRenderer renderer = new VisualStyleRenderer(_elementTop.VSElement);
         _markSizeTopBottom = renderer.GetPartSize(g, ThemeSizeType.True);
         renderer.SetParameters(_elementLeft.VSElement);
         _markSizeLeftRight = renderer.GetPartSize(g, ThemeSizeType.True);
     }
     else {
         _markSizeTopBottom = new Size(16, 16); //���̃T�C�Y�ł͐ݒ�ɂ���Ă̓_������
         _markSizeLeftRight = new Size(16, 16);
     }
 }
示例#16
0
		/// <summary>
		/// Initializes a new instance of the <see cref="StatusBarSizeGrip"/> class.
		/// </summary>
		/// <param name="bar">The status bar.</param>
		public StatusBarSizeGrip(StatusBar bar)
		{
			BorderStyle = StatusBarPanelBorderStyle.None;
			Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw;
			bar.DrawItem += new StatusBarDrawItemEventHandler(bar_DrawItem);
			int width = 16;
			if (Application.RenderWithVisualStyles)
			{
				using (Graphics g = bar.CreateGraphics())
				{
					VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal);
					Size sz = renderer.GetPartSize(g, ThemeSizeType.True);
					width = sz.Width;
				}
			}
			int widthT = width + SystemInformation.Border3DSize.Width * 2;
			// Can get widthT = 7 (< MinWidth = 10) on Mac Parallels, so we don't want to crash.
			Width = widthT >= MinWidth ? widthT : MinWidth;
		}
示例#17
0
        private void InitRects(Graphics g)
        {
            if (_rectsInitialized) {
                return;
            }

            int totalButtonWidth = _buttonSize.Width * 3;
            int startX = (((VisualStyleRenderer.IsSupported ? this.Width : this.ClientSize.Width) - totalButtonWidth) / 2);
            int iconX = (_buttonSize.Width - 16) / 2;
            int iconY = (_buttonSize.Height - 16) / 2;
            int buttonY = VisualStyleRenderer.IsSupported ? (this.Height - _buttonSize.Height) : (this.ClientSize.Height - _buttonSize.Height);

            if (VisualStyleRenderer.IsSupported) {
                _rectClient = new Rectangle(
                    _dwmMargins.cxLeftWidth,
                    _dwmMargins.cyTopHeight,
                    Width - _dwmMargins.cxRightWidth - _dwmMargins.cxLeftWidth,
                    Height - _dwmMargins.cyBottomHeight - _dwmMargins.cyTopHeight
                );
            }
            else {
                _rectClient = this.ClientRectangle;
            }

            _Panel.Top = _rectClient.Top;
            _Panel.Left = _rectClient.Left;

            _rectPrev = new Rectangle(startX, buttonY, _buttonSize.Width, _buttonSize.Height);

            startX += _buttonSize.Width;

            _rectInbox = new Rectangle(startX, buttonY, _buttonSize.Width, _buttonSize.Height);

            startX += _buttonSize.Width;

            _rectNext = new Rectangle(startX, buttonY, _buttonSize.Width, _buttonSize.Height);

            Size closeSize;

            if (VisualStyleRenderer.IsSupported) {
                VisualStyleRenderer renderer = new VisualStyleRenderer(_elementClose);

                closeSize = renderer.GetPartSize(g, ThemeSizeType.True);
            }
            else {
                closeSize = new Size(16, 14);
            }

            _rectClose = new Rectangle(Width - _dwmMargins.cxLeftWidth - closeSize.Width, 8, closeSize.Width, closeSize.Height);
        }
示例#18
0
		void bar_DrawItem(object sender, StatusBarDrawItemEventArgs sbdevent)
		{
			if (sbdevent.Panel == this)
			{
				if (Application.RenderWithVisualStyles)
				{
					VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Status.Gripper.Normal);
					Size partSz = renderer.GetPartSize(sbdevent.Graphics, ThemeSizeType.True);
					Rectangle rect = new Rectangle(sbdevent.Bounds.X + (sbdevent.Bounds.Width - partSz.Width),
						sbdevent.Bounds.Y + (sbdevent.Bounds.Height - partSz.Height), partSz.Width, partSz.Height);
					renderer.DrawBackground(sbdevent.Graphics, rect);
				}
				else
				{
					Rectangle rect = new Rectangle(sbdevent.Bounds.X + (sbdevent.Bounds.Width - 16),
						sbdevent.Bounds.Y + (sbdevent.Bounds.Height - 16), 16, 16);
					ControlPaint.DrawSizeGrip(sbdevent.Graphics, sbdevent.BackColor, rect);
				}
			}
		}
		protected override void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
		{
			if (!RenderClientAreas) {
				base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleElement element = VisualStyleElement.TrackBar.TrackVertical.Normal;
			if (!VisualStyleRenderer.IsElementDefined (element)) {
				base.TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clippingArea);
				return;
			}
			VisualStyleRenderer renderer = new VisualStyleRenderer (element);
			renderer.DrawBackground (dc, new Rectangle (channel_startpoint, new Size (renderer.GetPartSize (dc, ThemeSizeType.True).Width, thumb_area.Height)), clippingArea);
		}
示例#20
0
        public override void Layout(GraphicsSettings settings, Size maximumSize)
        {
            int width = 0;
            int height = 0;

            SyncSectionsToColumns(HeaderColumnSection.DisplayMode.Header);

            Point pt = new Point(Location.X, Location.Y);

            int reservedSpace = LayoutController == null ? 0 : LayoutController.ReservedNearSpace;

            bool first = true;

            foreach (Section hcs in Children)
            {
                hcs.Location = pt;
                hcs.Layout(settings, new Size(maximumSize.Width - pt.X, _isVisible ? maximumSize.Height - pt.Y : 0));
                if (first)
                {
                    hcs.Size = new Size(hcs.Size.Width + reservedSpace, hcs.Size.Height);
                    first = false;
                }
                pt = new Point(hcs.Rectangle.Right, pt.Y);
                width += hcs.Rectangle.Width;
                if (hcs.Size.Height > height)
                {
                    height = hcs.Size.Height;
                }
            }
            if (height == 0 && _isVisible)
            {
                if (VisualStyleRenderer.IsSupported)
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.Header.Item.Normal);

                    height = renderer.GetPartSize(settings.Graphics, ThemeSizeType.True).Height;
                }
                else
                {
                    height = SystemFonts.DialogFont.Height + 6;
                }
            }
            _idealWidth = width;
            if (height < MinimumHeight)
            {
                height = MinimumHeight;
            }
            Size = new Size(Math.Max(maximumSize.Width, _idealWidth), height);
            if (LayoutController != null)
            {
                LayoutController.HeaderLayedOut();
            }
        }
示例#21
0
		public static Size GetThumbGripSize (Graphics g, ScrollBarState state)
		{
			if (!IsSupported)
				throw new InvalidOperationException ();

			VisualStyleRenderer vsr = new VisualStyleRenderer (VisualStyleElement.ScrollBar.GripperVertical.Normal);

			return vsr.GetPartSize (g, ThemeSizeType.Draw);
		}
        /// <summary>
        /// Gets the background image of the current visual style element within the specified background color. If <paramref name="states"/> is set, the resulting image will contain each of the state images side by side.
        /// </summary>
        /// <param name="rnd">The <see cref="VisualStyleRenderer"/> instance.</param>
        /// <param name="clr">The background color. This color cannot have an alpha channel.</param>
        /// <param name="states">The optional list of states to render side by side.</param>
        /// <returns>The background image.</returns>
        public static Bitmap GetBackgroundBitmap(this VisualStyleRenderer rnd, Color clr, int[] states = null)
        {
            const int wh = 200;

            if (rnd == null)
            {
                throw new ArgumentNullException(nameof(rnd));
            }
            rnd.SetParameters(rnd.Class, rnd.Part, 0);
            if (states == null)
            {
                states = new[] { rnd.State }
            }
            ;
            var i = states.Length;

            // Get image size
            Size imgSz;

            using (var sg = Graphics.FromHwnd(IntPtr.Zero))
                imgSz = rnd.GetPartSize(sg, new Rectangle(0, 0, wh, wh), ThemeSizeType.Draw);
            if (imgSz.Width == 0 || imgSz.Height == 0)
            {
                imgSz = new Size(rnd.GetInteger(IntegerProperty.Width), rnd.GetInteger(IntegerProperty.Height));
            }

            var bounds = new Rectangle(0, 0, imgSz.Width * i, imgSz.Height);

            // Draw each background linearly down the bitmap
            using (var memoryHdc = SafeDCHandle.ScreenCompatibleDCHandle)
            {
                // Create a device-independent bitmap and select it into our DC
                var    info = new BITMAPINFO(bounds.Width, -bounds.Height);
                IntPtr ppv;
                using (new SafeDCObjectHandle(memoryHdc, CreateDIBSection(SafeDCHandle.Null, ref info, DIBColorMode.DIB_RGB_COLORS, out ppv, IntPtr.Zero, 0)))
                {
                    using (var memoryGraphics = Graphics.FromHdc(memoryHdc.DangerousGetHandle()))
                    {
                        // Setup graphics
                        memoryGraphics.CompositingMode    = CompositingMode.SourceOver;
                        memoryGraphics.CompositingQuality = CompositingQuality.HighQuality;
                        memoryGraphics.SmoothingMode      = SmoothingMode.HighQuality;
                        memoryGraphics.Clear(clr);

                        // Draw each background linearly down the bitmap
                        var rect = new Rectangle(0, 0, imgSz.Width, imgSz.Height);
                        foreach (var state in states)
                        {
                            rnd.SetParameters(rnd.Class, rnd.Part, state);
                            rnd.DrawBackground(memoryGraphics, rect);
                            rect.X += imgSz.Width;
                        }
                    }

                    // Copy DIB to Bitmap
                    var bmp = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
                    using (var primaryHdc = new SafeDCHandle(Graphics.FromImage(bmp)))
                        BitBlt(primaryHdc, bounds.Left, bounds.Top, bounds.Width, bounds.Height, memoryHdc, 0, 0, RasterOperationMode.SRCCOPY);
                    return(bmp);
                }
            }
        }
示例#23
0
        private Size GetGlyphSize( Graphics g, bool expanded )
        {
            if( VisualStyleRenderer.IsSupported )
            {
                VisualStyleElement vse = expanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                VisualStyleRenderer vsr = new VisualStyleRenderer( vse );
                Size ecSize = vsr.GetPartSize( g, ThemeSizeType.Draw );

                return ecSize;
            }
            else
            {
                return new Size( 9, 9 );
            }
        }
示例#24
0
            static void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
            {
                //Loosely based on Jason Williams solution (http://stackoverflow.com/questions/1003459/c-treeview-owner-drawing-with-ownerdrawtext-and-the-weird-black-highlighting-w)
                if (e.Bounds.Height < 1 || e.Bounds.Width < 1)
                    return;

                if (cIndentBy == -1)
                {
                    cIndentBy = e.Bounds.Height;
                    cMargin = e.Bounds.Height / 2;
                }

                var treeView = (TreeView)sender;

                Rectangle itemRect = e.Bounds;
                e.Graphics.FillRectangle(Brushes.White, itemRect);
                //e.Graphics.FillRectangle(Brushes.WhiteSmoke, itemRect);

                int cTwoMargins = cMargin * 2;

                int midY = (itemRect.Top + itemRect.Bottom) / 2;

                int iconWidth = itemRect.Height + 2;
                int checkboxWidth = itemRect.Height + 2;

                int indent = (e.Node.Level * cIndentBy) + cMargin;
                int iconLeft = indent;						                    // lines left position
                int checkboxLeft = iconLeft + iconWidth;                        // +/- icon left position


                int textLeft = checkboxLeft + checkboxWidth;	               // text left position
                if (!treeView.CheckBoxes)
                    textLeft = checkboxLeft;

                // Draw parentage lines
                if (treeView.ShowLines)
                {
                    int x = cMargin * 2;

                    if (e.Node.Level == 0 && e.Node.PrevNode == null)
                    {
                        // The very first node in the tree has a half-height line
                        e.Graphics.DrawLine(dotPen, x, midY, x, itemRect.Bottom);
                    }
                    else
                    {
                        TreeNode testNode = e.Node;			// Used to only draw lines to nodes with Next Siblings, as in normal TreeViews
                        for (int iLine = e.Node.Level; iLine >= 0; iLine--)
                        {
                            if (testNode.NextNode != null)
                            {
                                x = (iLine * cIndentBy) + (cMargin * 2);
                                e.Graphics.DrawLine(dotPen, x, itemRect.Top, x, itemRect.Bottom);
                            }

                            testNode = testNode.Parent;
                        }

                        x = (e.Node.Level * cIndentBy) + (cMargin * 2);
                        e.Graphics.DrawLine(dotPen, x, itemRect.Top, x, midY);
                    }

                    e.Graphics.DrawLine(dotPen, iconLeft + cMargin, midY, iconLeft + cMargin + 10, midY);
                }

                // Draw (plus/minus) icon if required
                if (e.Node.Nodes.Count > 0)
                {

                    var element = e.Node.IsExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;
                    var renderer = new VisualStyleRenderer(element);
                    var iconTrueSize = renderer.GetPartSize(e.Graphics, ThemeSizeType.True);

                    var bounds = new Rectangle(itemRect.Left + iconLeft, itemRect.Top, iconWidth, iconWidth);

                    //e.Graphics.FillRectangle(Brushes.Salmon, bounds);

                    //deflate (resize and center) icon within bounds 
                    var dif = (iconWidth - iconTrueSize.Height) / 2 - 1; //-1 is to compensate for rounding as icon is not getting rendered if the bounds is too small
                    bounds.Inflate(-dif, -dif);
                    renderer.DrawBackground(e.Graphics, bounds);
                }

                //Checkbox
                if (treeView.CheckBoxes)
                {
                    var element = e.Node.Checked ? VisualStyleElement.Button.CheckBox.CheckedNormal : VisualStyleElement.Button.CheckBox.UncheckedNormal;
                    if (IsReadOnly(e.Node))
                        element = e.Node.Checked ? VisualStyleElement.Button.CheckBox.CheckedDisabled : VisualStyleElement.Button.CheckBox.UncheckedDisabled;

                    var renderer = new VisualStyleRenderer(element);
                    var bounds = new Rectangle(itemRect.Left + checkboxLeft, itemRect.Top, checkboxWidth, itemRect.Height);
                    //e.Graphics.FillRectangle(Brushes.Bisque, bounds);
                    renderer.DrawBackground(e.Graphics, bounds);
                }

                //Text
                if (!string.IsNullOrEmpty(e.Node.Text))
                {
                    SizeF textSize = e.Graphics.MeasureString(e.Node.Text, treeView.Font);

                    var drawFormat = new StringFormat
                    {
                        Alignment = StringAlignment.Near,
                        LineAlignment = StringAlignment.Center,
                        FormatFlags = StringFormatFlags.NoWrap,
                    };

                    var bounds = new Rectangle(itemRect.Left + textLeft, itemRect.Top, (int)(textSize.Width + 2), itemRect.Height);

                    if (e.Node.IsSelected)
                    {
                        e.Graphics.FillRectangle(selectionModeBrush, bounds);
                        e.Graphics.DrawString(e.Node.Text, treeView.Font, Brushes.White, bounds, drawFormat);
                    }
                    else
                    {
                        //e.Graphics.FillRectangle(Brushes.Pink, bounds);
                        e.Graphics.DrawString(e.Node.Text, treeView.Font, Brushes.Black, bounds, drawFormat);
                    }

                }

                // Focus rectangle around the text
                if (e.State == TreeNodeStates.Focused)
                {
                    var r = itemRect;
                    r.Width -= 2;
                    r.Height -= 2;
                    r.Offset(indent, 0);
                    r.Width -= indent;
                    e.Graphics.DrawRectangle(dotPen, r);
                }
            }