//============================================================================* // OnMouseMove() //============================================================================* protected override void OnMouseMove(MouseEventArgs args) { int nX = args.X; int nY = args.Y; ListViewItem Item = GetItemAt(nX, nY); //----------------------------------------------------------------------------* // Find the Column that was clicked //----------------------------------------------------------------------------* int nColumn = 0; int nColumnX = 0; bool fColumnFound = false; if (Item != null) { foreach (ColumnHeader Column in Columns) { if (nX >= nColumnX && nX <= nColumnX + Column.Width) { fColumnFound = true; break; } nColumnX += Column.Width; nColumn++; } } this.Cursor = Cursors.Default; if (fColumnFound && nColumn < Item.SubItems.Count && nColumn < Columns.Count) { ColumnHeader Header = Columns[nColumn]; Graphics g = Graphics.FromHwnd(this.Handle); SizeF TextSize = g.MeasureString(Item.SubItems[nColumn].Text, this.Font); //----------------------------------------------------------------------------* // Website Column //----------------------------------------------------------------------------* if (Header.Text == "Website") { if (!String.IsNullOrEmpty(Item.SubItems[nColumn].Text)) { if (nX - nColumnX < (int)TextSize.Width) { this.Cursor = Cursors.Hand; } } } //----------------------------------------------------------------------------* // Part Number Column //----------------------------------------------------------------------------* if (Header.Text == "Part Number" && Item.Text == "Batch Editor") { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { this.Cursor = Cursors.Hand; } } //----------------------------------------------------------------------------* // Caliber Column //----------------------------------------------------------------------------* if (Header.Text == "Caliber" || Header.Text == "Primary Caliber") { cCaliber Caliber = GetCaliberFromTag(Item); if (Caliber != null && !String.IsNullOrEmpty(Caliber.SAAMIPDF)) { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { this.Cursor = Cursors.Hand; } } } } base.OnMouseMove(args); }
public ListViewModelItem() { CheckBoxes = true; Dock = DockStyle.Fill; BackColor = Color.White; BorderStyle = BorderStyle.None; View = View.Details; FullRowSelect = true; GridLines = true; Location = new Point(12, 12); MultiSelect = false; Size = new Size(288, 303); UseCompatibleStateImageBehavior = false; OwnerDraw = true; ColumnClick += (se, e) => { #region if (e.Column == 0) { bool value = false; try { value = Convert.ToBoolean(this.Columns[e.Column].Tag); } catch (Exception) { } this.Columns[e.Column].Tag = !value; foreach (ListViewItem item in this.Items) { item.Checked = !value; } this.Invalidate(); } #endregion }; DrawColumnHeader += (se, e) => { #region e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds); if (e.ColumnIndex == 0) { bool value = false; try { value = Convert.ToBoolean(e.Header.Tag); } catch (Exception) { } CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), value ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal); return; } using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center }) using (Font headerFont = new Font("Arial", 8, FontStyle.Regular)) e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, new Rectangle(e.Bounds.X, e.Bounds.Y + 3, e.Bounds.Width, e.Bounds.Height - 3), sf); #endregion }; DrawSubItem += (se, e) => { #region bool selected = (e.ItemState & ListViewItemStates.Selected) != 0; if (selected) { e.Graphics.FillRectangle(Brushes.Orange, e.Bounds); } else if (e.ItemIndex % 2 != 0) { e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), e.Bounds); } switch (e.ColumnIndex) { case 0: e.DrawDefault = true; break; case 1: using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center }) using (Font headerFont = new Font("Arial", 7, FontStyle.Regular)) e.Graphics.DrawString(e.SubItem.Text, headerFont, Brushes.Gray, new Point(e.Bounds.X + 10, e.Bounds.Y + 3), sf); break; default: //e.DrawDefault = true; e.DrawText(); //bool value = false; //try //{ // value = Convert.ToBoolean(e.Header.Tag); //} //catch (Exception) //{ //} //CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), // value ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal); //////using (StringFormat sf = new StringFormat() { Alignment = StringAlignment.Center }) //////using (Font headerFont = new Font("Arial", 8, FontStyle.Regular)) //Font size!!!! ////// e.Graphics.DrawString(e.SubItem.Text, headerFont, Brushes.Black, ////// new Rectangle(e.Bounds.X, e.Bounds.Y + 3, e.Bounds.Width, e.Bounds.Height + 3), sf); break; } #endregion }; DrawItem += (se, e) => { }; MouseClick += (se, ev) => { int index = -1; for (int i = 0; i < this.Items.Count; i++) { if (this.GetItemRect(i).Contains(ev.Location)) { index = i; break; } } if (index != -1) { ViewModelItem item = this.Items[index] as ViewModelItem; if (OnItemClick != null) { OnItemClick(index, item.Value); } } }; }
public void DrawIcon(IntPtr hdc, Int32 index, IListItemEx sho, User32.RECT iconBounds, Boolean isGhosted, Boolean isHot) { if (sho.OverlayIconIndex == -1) { this._OverlayQueue.Enqueue(index, true); } if (this._CurrentSize != 16) { var addornerType = this.GetAddornerType(sho); IntPtr hThumbnail = IntPtr.Zero; hThumbnail = sho.GetHBitmap(addornerType == 2 ? this._CurrentSize - 7 : this._CurrentSize, true); Int32 width = 0; Int32 height = 0; if (hThumbnail != IntPtr.Zero) { Gdi32.ConvertPixelByPixel(hThumbnail, out width, out height); if (addornerType > 0) { this.DrawWithAddorner(hdc, iconBounds, isGhosted, width, height, hThumbnail, addornerType); } else { Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isGhosted); } if (addornerType == 2) { width = width + 7; height = height + 7; } sho.IsNeedRefreshing = ((width > height && width != this._CurrentSize) || (width < height && height != this._CurrentSize) || (width == height && width != this._CurrentSize)) && !sho.IsOnlyLowQuality; sho.IsThumbnailLoaded = false; if (sho.IsNeedRefreshing) { Task.Run(() => { this._ThumbnailsForCacheLoad.Enqueue(index); }); } } else { if (sho.IsIconLoaded || ((sho.IconType & IExtractIconPWFlags.GIL_PERCLASS) == IExtractIconPWFlags.GIL_PERCLASS || (!this._ShellViewEx.IsSearchNavigating && this._ShellViewEx.RequestedCurrentLocation.ParsingName.Equals(KnownFolders.Libraries.ParsingName, StringComparison.InvariantCultureIgnoreCase)) || (!this._ShellViewEx.IsSearchNavigating && this._ShellViewEx.RequestedCurrentLocation.ParsingName.Equals(KnownFolders.Computer.ParsingName, StringComparison.InvariantCultureIgnoreCase)))) { hThumbnail = sho.GetHBitmap(this._CurrentSize, false); if (hThumbnail != IntPtr.Zero) { Gdi32.ConvertPixelByPixel(hThumbnail, out width, out height); Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isGhosted); sho.IsIconLoaded = true; } else { this.DrawDefaultIcons(hdc, sho, iconBounds); sho.IsThumbnailLoaded = true; sho.IsNeedRefreshing = false; sho.IsIconLoaded = false; //if (!this._IconsForRetreval.Contains(index)) Task.Run(() => { this._IconsForRetreval.Enqueue(index); }); } if (!sho.IsThumbnailLoaded || sho.IsNeedRefreshing) { //Task.Run(() => { this._ThumbnailsForCacheLoad.Enqueue(index); } //}); } else { var editControl = User32.SendMessage(this._ShellViewEx.LVHandle, 0x1018, 0, 0); if (editControl == IntPtr.Zero) { this.DrawDefaultIcons(hdc, sho, iconBounds); sho.IsIconLoaded = false; //if (!this._IconsForRetreval.Contains(index)) Task.Run(() => { this._IconsForRetreval.Enqueue(index); }); } else { hThumbnail = sho.GetHBitmap(this._CurrentSize, false); if (hThumbnail != IntPtr.Zero) { Gdi32.ConvertPixelByPixel(hThumbnail, out width, out height); Gdi32.NativeDraw(hdc, hThumbnail, iconBounds.Left + (iconBounds.Right - iconBounds.Left - width) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - height) / 2, width, height, isGhosted); } else { this.DrawDefaultIcons(hdc, sho, iconBounds); sho.IsIconLoaded = false; //if (!this._IconsForRetreval.Contains(index)) //Task.Run(() => { this._IconsForRetreval.Enqueue(index); //}); } if ((sho.GetShield() & IExtractIconPWFlags.GIL_SHIELD) != 0) { sho.ShieldedIconIndex = this._ShieldIconIndex; } } } } using (var g = Graphics.FromHdc(hdc)) { if (this._ShellViewEx.ShowCheckboxes && this._ShellViewEx.View != ShellViewStyle.Details && this._ShellViewEx.View != ShellViewStyle.List) { /* * var lvi = new LVITEMINDEX(); * lvi.iItem = index; * lvi.iGroup = this._ShellViewEx.GetGroupIndex(index); */ var iGroup = this._ShellViewEx.GetGroupIndex(index); var lvItem = new LVITEM() { iItem = index, iGroupId = iGroup, iGroup = iGroup, mask = LVIF.LVIF_STATE, stateMask = LVIS.LVIS_SELECTED }; var lvItemImageMask = new LVITEM() { iItem = index, iGroupId = iGroup, iGroup = iGroup, mask = LVIF.LVIF_STATE, stateMask = LVIS.LVIS_STATEIMAGEMASK }; var res = User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMW, 0, ref lvItemImageMask); if (isHot || (UInt32)lvItemImageMask.state == (2 << 12)) { res = User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMW, 0, ref lvItem); var checkboxOffsetH = 14; var checkboxOffsetV = 2; if (this._ShellViewEx.View == ShellViewStyle.Tile || this._ShellViewEx.View == ShellViewStyle.SmallIcon) { checkboxOffsetH = 2; } if (this._ShellViewEx.View == ShellViewStyle.Tile) { checkboxOffsetV = 5; } CheckBoxRenderer.DrawCheckBox(g, new Point(iconBounds.Left + checkboxOffsetH, iconBounds.Top + checkboxOffsetV), lvItem.state != 0 ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } } } if (sho.OverlayIconIndex > 0) { if (this._CurrentSize > 180) { this._Jumbo.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left, iconBounds.Bottom - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0) - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left + 10 - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0), iconBounds.Bottom - 50)); } else { this._Large.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left + 10 - (this._ShellViewEx.View == ShellViewStyle.Tile ? 5 : 0), iconBounds.Bottom - 32)); } } if (sho.ShieldedIconIndex > 0) { if (this._CurrentSize > 180) { this._Jumbo.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - this._CurrentSize / 3 - 3, iconBounds.Bottom - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 43, iconBounds.Bottom - 50)); } else { this._Large.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 33, iconBounds.Bottom - 32)); } } if (sho.IsShared) { if (this._CurrentSize > 180) { this._Jumbo.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - this._CurrentSize / 3, iconBounds.Bottom - this._CurrentSize / 3), this._CurrentSize / 3); } else if (this._CurrentSize > 64) { this._Extra.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 40, iconBounds.Bottom - 50)); } else { this._Large.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 30, iconBounds.Bottom - 32)); } } IListItemEx badge = this.GetBadgeForPath(sho.ParsingName); if (badge != null) { var badgeIco = badge.GetHBitmap(this._CurrentSize, false, false, true); Gdi32.ConvertPixelByPixel(badgeIco, out width, out height); Gdi32.NativeDraw(hdc, badgeIco, iconBounds.Left + (iconBounds.Right - iconBounds.Left - _CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - _CurrentSize) / 2, _CurrentSize, isGhosted); Gdi32.DeleteObject(badgeIco); } if (this._ShellViewEx.View == ShellViewStyle.Tile) { var lvi = new LVITEMINDEX(); lvi.iItem = index; lvi.iGroup = this._ShellViewEx.GetGroupIndex(index); var lableBounds = new User32.RECT() { Left = 2 }; User32.SendMessage(this._ShellViewEx.LVHandle, MSG.LVM_GETITEMINDEXRECT, ref lvi, ref lableBounds); using (var g = Graphics.FromHdc(hdc)) { var lblrectTiles = new RectangleF(lableBounds.Left, iconBounds.Top + 6, lableBounds.Right - lableBounds.Left, 15); if (this._ShellViewEx.RequestedCurrentLocation.ParsingName.Equals(KnownFolders.Computer.ParsingName) && (sho.IsDrive || sho.IsNetworkPath)) { var fmt = new StringFormat(); fmt.Trimming = StringTrimming.EllipsisCharacter; fmt.Alignment = StringAlignment.Center; fmt.Alignment = StringAlignment.Near; fmt.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox; fmt.LineAlignment = StringAlignment.Center; this.DrawComputerTiledModeView(sho, g, lblrectTiles, fmt); } } } } else { sho.IsThumbnailLoaded = true; Int32 width = 0, height = 0; if ((sho.IconType & IExtractIconPWFlags.GIL_PERCLASS) == IExtractIconPWFlags.GIL_PERCLASS) { var hIconExe = sho.GetHBitmap(this._CurrentSize, false); if (hIconExe != IntPtr.Zero) { sho.IsIconLoaded = true; Gdi32.ConvertPixelByPixel(hIconExe, out width, out height); Gdi32.NativeDraw(hdc, hIconExe, iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2, this._CurrentSize, isGhosted); } } else if ((sho.IconType & IExtractIconPWFlags.GIL_PERINSTANCE) == IExtractIconPWFlags.GIL_PERINSTANCE) { if (!sho.IsIconLoaded) { /* * if (sho.IsNetworkPath || this._ShellViewEx.IsSearchNavigating) { * Task.Run(() => { * this._IconsForRetreval.Enqueue(index); * }); * } else { * Task.Run(() => { * this._IconsForRetreval.Enqueue(index); * }); * } */ //Task.Run(() => { this._IconsForRetreval.Enqueue(index); //}); this._Small.DrawIcon(hdc, this._ExeFallBackIndex, new Point(iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2)); } else { var hIconExe = sho.GetHBitmap(this._CurrentSize, false); if (hIconExe != IntPtr.Zero) { sho.IsIconLoaded = true; Gdi32.ConvertPixelByPixel(hIconExe, out width, out height); Gdi32.NativeDraw(hdc, hIconExe, iconBounds.Left + (iconBounds.Right - iconBounds.Left - this._CurrentSize) / 2, iconBounds.Top + (iconBounds.Bottom - iconBounds.Top - this._CurrentSize) / 2, this._CurrentSize, isGhosted); } } } if (sho.OverlayIconIndex > 0) { this._Small.DrawOverlay(hdc, sho.OverlayIconIndex, new Point(iconBounds.Left, iconBounds.Bottom - 16)); } if (sho.ShieldedIconIndex > 0) { this._Small.DrawIcon(hdc, sho.ShieldedIconIndex, new Point(iconBounds.Right - 9, iconBounds.Bottom - 10), 10); } if (sho.IsShared) { this._Small.DrawIcon(hdc, this._SharedIconIndex, new Point(iconBounds.Right - 9, iconBounds.Bottom - 16)); } IListItemEx badge = this.GetBadgeForPath(sho.ParsingName); if (badge != null) { var badgeIco = badge.GetHBitmap(16, false, false, true); Gdi32.ConvertPixelByPixel(badgeIco, out width, out height); Gdi32.NativeDraw(hdc, badgeIco, iconBounds.Left, iconBounds.Top, 16, isGhosted); Gdi32.DeleteObject(badgeIco); } } }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { if (e.Item == null) { return; } // Draw the background var item = (e.Item.Tag as CloudTaskItem); var textColor = item.GetTextColor(e.Item.Selected, m_TaskColorIsBkgnd); var backColor = item.GetBackColor(m_TaskColorIsBkgnd); Brush textBrush = new SolidBrush(textColor); if (m_TaskColorIsBkgnd && !backColor.IsEmpty) { using (Brush backBrush = new SolidBrush(backColor)) e.Graphics.FillRectangle(backBrush, e.Bounds); } else if (!e.Item.Selected) { e.DrawBackground(); } if (e.Item.Selected) { // Selection rect just around text label Rectangle labelRect = LabelTextRect(e.Bounds, true); UIExtension.SelectionRect.Draw(Handle, e.Graphics, labelRect.X, labelRect.Y, labelRect.Width, labelRect.Height, false); // opaque } // Draw subitems StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Near; stringFormat.LineAlignment = StringAlignment.Center; stringFormat.FormatFlags = StringFormatFlags.NoWrap; Rectangle itemRect = e.Bounds; for (int colIndex = 0; colIndex < e.Item.SubItems.Count; colIndex++) { itemRect.X += 2; itemRect.Width = (Columns[colIndex].Width - 2); if (colIndex == 0) { if (m_ShowCompletionCheckboxes) { if (m_CheckBoxSize.IsEmpty) { m_CheckBoxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.UncheckedNormal); } var checkRect = CheckboxRect(itemRect); CheckBoxRenderer.DrawCheckBox(e.Graphics, checkRect.Location, GetItemCheckboxState(item)); itemRect.X += CheckboxOffset; itemRect.Width -= CheckboxOffset; } if (m_TaskMatchesHaveIcons) { if ((e.Item.ImageIndex != -1) && m_TaskIcons.Get(item.Id)) { int imageSize = ImageSize; Rectangle iconRect = new Rectangle(itemRect.Location, new Size(imageSize, imageSize)); iconRect.Y += ((itemRect.Height - imageSize) / 2); m_TaskIcons.Draw(e.Graphics, iconRect.Left, iconRect.Top); } itemRect.X += TextIconOffset; itemRect.Width -= TextIconOffset; } } itemRect.Y++; itemRect.Height--; DrawText(e.Graphics, e.Item.SubItems[colIndex].Text, itemRect, textBrush, StringAlignment.Near, (colIndex == 0)); // next subitem itemRect.X += itemRect.Width; } }
/// <summary> /// Renders the supplied CheckBox_t as XAML. /// </summary> /// <param name="control">CheckBox_t to render.</param> public void Visit(CheckBox_t control) { CheckBoxRenderer.Render(_writer, control); }
protected override void OnPaint(PaintEventArgs e) { try { if (GetStyle(ControlStyles.AllPaintingInWmPaint)) { OnPaintBackground(e); } MinimumSize = new Size(0, GetPreferredSize(Size.Empty).Height); Rectangle _clientRectangle = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); GraphicsPath controlGraphicsPath = VisualBorderRenderer.CreateBorderTypePath(_clientRectangle, _border); Color backColorState = ColorState.BackColorState(_backColor, Enabled, MouseState); e.Graphics.SetClip(controlGraphicsPath); VisualBackgroundRenderer.DrawBackground(e.Graphics, backColorState, BackgroundImage, MouseState, _clientRectangle, _border); VisualBorderRenderer.DrawBorderStyle(e.Graphics, _border, controlGraphicsPath, _mouseState); Rectangle arrowRectangle = new Rectangle(Width - _arrowSize.Width - 5, (Height / 2) - (_arrowSize.Height / 2), _arrowSize.Width, _arrowSize.Height); if (_image != null) { e.Graphics.DrawImage(_image, new Rectangle(arrowRectangle.Left - _image.Width - 2, (Height / 2) - (_image.Height / 2), _imageSize.Width, _imageSize.Height)); } VisualElementRenderer.RenderTriangle(e.Graphics, _arrowColor, _arrowDisabledColor, Enabled, _dropDownImage, arrowRectangle, Alignment.Vertical.Down); var _check = 0; Rectangle checkBoxRectangle = new Rectangle(3, (Height / 2) - 6, 12, 12); if (ShowCheckBox) { _check = 15; if (Checked) { CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.CheckedNormal); } else { CheckBoxRenderer.DrawCheckBox(e.Graphics, checkBoxRectangle.Location, CheckBoxState.UncheckedNormal); } } Size textSize = TextManager.MeasureText(Text, Font); Rectangle textBoxRectangle = new Rectangle(2 + _check, (Height / 2) - (textSize.Height / 2), textSize.Width, textSize.Height); TextRenderer.DrawText(e.Graphics, Text, Font, textBoxRectangle, ForeColor, TextFormatFlags.Left | TextFormatFlags.VerticalCenter); if (_showFocus && _focused) { ControlPaint.DrawFocusRectangle(e.Graphics, ClientRectangle); } e.Graphics.ResetClip(); } catch { Invalidate(); } }
/// <summary> /// Raises the <see cref="ListView.DrawSubItem"/> event. /// </summary> /// <remarks> /// This is where the owner draws the specific sub item. We handle this. /// </remarks> /// <param name="e">A <see cref="DrawListViewSubItemEventArgs"/> describing the event arguments.</param> protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e) { //if the item is not in a list view, then don't bother trying to draw it, // as it isn't visible anyway if (e.Item.ListView == null) { return; } base.OnDrawSubItem(e); e.DrawBackground(); Int32 intBoundsX = e.Bounds.X; Int32 intBoundsY = e.Bounds.Y; Int32 intBoundsWidth = e.Bounds.Width; Int32 intFontX = e.Bounds.X + 3; Int32 intFontWidth = e.Bounds.Width - 3; if (e.Item.SubItems[0] == e.SubItem) { intBoundsX += 4; intBoundsWidth -= 4; if (CheckBoxes) { CheckBoxState cbsState = e.Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; Size szeCheckboxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, cbsState); int intBoxY = intBoundsY + (e.Bounds.Height - szeCheckboxSize.Height) / 2; int intBoxX = intBoundsX; intBoundsX += 3 + szeCheckboxSize.Width; intBoundsWidth -= 3 + szeCheckboxSize.Width; intFontX += 3 + szeCheckboxSize.Width; intFontWidth -= 3 + szeCheckboxSize.Width; CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(intBoxX, intBoxY), cbsState); } m_intFocusBoundsX = intBoundsX; } Color clrForeColor = e.SubItem.ForeColor; if (e.Item.Selected) { clrForeColor = e.Item.ListView.Focused ? SystemColors.HighlightText : clrForeColor; Color clrBackColor = e.Item.ListView.Focused ? SystemColors.Highlight : SystemColors.Control; e.Graphics.FillRectangle(new SolidBrush(clrBackColor), new Rectangle(intBoundsX, intBoundsY, intBoundsWidth, e.Bounds.Height)); } if (Messages.ContainsKey(e.SubItem)) { Image imgIcon = Messages[e.SubItem].Value; Rectangle rctIconBounds = GetMessageIconBounds(e.Bounds, imgIcon, String.IsNullOrEmpty(e.SubItem.Text) ? true : false); Rectangle rctPaint = new Rectangle(new Point(rctIconBounds.X, intBoundsY + rctIconBounds.Y), rctIconBounds.Size); e.Graphics.DrawImage(imgIcon, rctPaint); intFontWidth -= rctIconBounds.Width; } Rectangle rctTextBounds = new Rectangle(intFontX, intBoundsY + 2, intFontWidth, e.Bounds.Height - 4); TextRenderer.DrawText(e.Graphics, e.SubItem.Text, e.SubItem.Font, rctTextBounds, clrForeColor, TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter); if (e.Item.Focused) { Pen penFocusRectangle = new Pen(Brushes.Black); penFocusRectangle.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; e.Graphics.DrawRectangle(penFocusRectangle, new Rectangle(m_intFocusBoundsX, intBoundsY, e.Item.Bounds.Width - m_intFocusBoundsX - 1, e.Item.Bounds.Height - 1)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Draw normal checked/unchecked check box. /// </summary> /// ------------------------------------------------------------------------------------ protected override void DrawFeatureState(Graphics g, FeatureItemInfo itemInfo, Rectangle rc) { CheckBoxRenderer.DrawCheckBox(g, rc.Location, (itemInfo != null && itemInfo.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); }
private void panCols_Paint(object sender, PaintEventArgs e) { m_fkButs = new List <Interval>(); m_textLefts = new List <int>(); for (int i = 0; i < m_table.Columns.Count; i++) { System.Windows.Forms.VisualStyles.CheckBoxState state; string colname = m_table.Columns[i].ColumnName; int y = i * m_lineHeight; //e.Graphics.FillRectangle(SystemBrushes.ButtonFace, new Rectangle(0, y, m_checkWidth, m_lineHeight)); if (m_checkedColumns.Contains(colname)) { if (i == m_highlightedCheckbox) { state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot; } else { state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } } else { if (i == m_highlightedCheckbox) { state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot; } else { state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; } } CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(0, y), state); int x = m_checkWidth + 2; if (m_pkCols.Contains(colname)) { e.Graphics.DrawImage(CoreIcons.primary_key, new Point(x, y)); x += 18; } if (m_fkCols.Contains(colname)) { m_fkButs.Add(new Interval(x, x + 16)); var r = new Rectangle(x, y, 16, 15); if (i == m_hightlightedFk) { e.Graphics.FillRectangle(Brushes.Aqua, r); } else { e.Graphics.FillRectangle(Brushes.White, r); } e.Graphics.DrawRectangle(Pens.Black, r); e.Graphics.DrawImage(CoreIcons.foreign_key, new Point(x, y)); x += 18; } else { m_fkButs.Add(new Interval()); } m_textLefts.Add(x); var r2 = new Rectangle(x, y, panCols.Width - x, m_lineHeight); if (m_hightlightedColName == i) { e.Graphics.FillRectangle(Brushes.Yellow, r2); } e.Graphics.DrawString(colname, Font, Brushes.Black, x, y); } }
protected override void DrawNodeLabel(Graphics graphics, String label, Rectangle rect, NodeDrawState nodeState, NodeDrawPos nodePos, Font nodeFont, Object itemData) { var taskItem = (itemData as MindMapTaskItem); bool isSelected = (nodeState != NodeDrawState.None); if (taskItem.IsTask) // real task { // Checkbox Rectangle checkRect = CalcCheckboxRect(rect); if (m_ShowCompletionCheckboxes) { CheckBoxRenderer.DrawCheckBox(graphics, checkRect.Location, GetItemCheckboxState(taskItem)); } // Task icon if (TaskHasIcon(taskItem)) { Rectangle iconRect = CalcIconRect(rect); if (m_TaskIcons.Get(taskItem.ID)) { m_TaskIcons.Draw(graphics, iconRect.X, iconRect.Y); } rect.Width = (rect.Right - iconRect.Right - 2); rect.X = iconRect.Right + 2; } else if (m_ShowCompletionCheckboxes) { rect.Width = (rect.Right - checkRect.Right - 2); rect.X = checkRect.Right + 2; } } // Text background Brush textColor = SystemBrushes.WindowText; Brush backColor = null; Color taskColor = taskItem.TextColor; if (!taskColor.IsEmpty) { if (m_TaskColorIsBkgnd && !isSelected && !taskItem.IsDone(true)) { backColor = new SolidBrush(taskColor); textColor = new SolidBrush(DrawingColor.GetBestTextColor(taskColor)); } else { if (nodeState != MindMapControl.NodeDrawState.None) { taskColor = DrawingColor.SetLuminance(taskColor, 0.3f); } textColor = new SolidBrush(taskColor); } } switch (nodeState) { case NodeDrawState.Selected: m_SelectionRect.Draw(graphics, rect.X, rect.Y, rect.Width, rect.Height, this.Focused); break; case NodeDrawState.DropTarget: m_SelectionRect.Draw(graphics, rect.X, rect.Y, rect.Width, rect.Height, false); break; case NodeDrawState.None: { if (backColor != null) { var prevSmoothing = graphics.SmoothingMode; graphics.SmoothingMode = SmoothingMode.None; graphics.FillRectangle(backColor, rect); graphics.SmoothingMode = prevSmoothing; } if (DebugMode()) { graphics.DrawRectangle(new Pen(Color.Green), rect); } } break; } // Text var format = DefaultLabelFormat(nodePos, isSelected); graphics.DrawString(label, nodeFont, textColor, rect, format); }
/// <summary>Gets the size of the image used to display the button.</summary> /// <param name="g">Current <see cref="Graphics"/> context.</param> /// <returns>The size of the image.</returns> protected override Size GetButtonSize(Graphics g) => CheckBoxRenderer.GetGlyphSize(g, CheckBoxState.CheckedNormal);
private void PaintNode(SmartTreeNode theNode, Graphics g, int locationX, int locationY) { // Icon dimensions int imageMidpointX = locationX + _expanderWidth / 2; int imageMidpointY = locationY + (int)(Font.SizeInPoints * 2) / 2; // Node dimensions Rectangle contentArea = CalculateContentArea(locationX, locationY, theNode.GetContentSize()); int nodeHeight = contentArea.Height; int nodeBottom = locationY + nodeHeight; // Update node bounds theNode.Bounds = new Rectangle(locationX, locationY, _expanderWidth + HorizontalSpace + contentArea.Width, contentArea.Height); // Draw lines using (Pen pen = new Pen(LineColor)) { pen.DashStyle = DashStyle; // Horizontal Line g.DrawLine(pen, imageMidpointX, imageMidpointY, contentArea.Left, imageMidpointY); Point verticalLineTop = new Point(imageMidpointX, imageMidpointY); Point verticalLineBottom = verticalLineTop; // Vertical line upwards if (theNode.Parent != null || theNode.PreviousNode != null) { verticalLineTop = new Point(imageMidpointX, locationY - VerticalSpace); } // Vertical line downwards if (theNode.NextNode != null) { verticalLineBottom = new Point(imageMidpointX, nodeBottom); } if (verticalLineTop != verticalLineBottom) { g.DrawLine(pen, verticalLineTop, verticalLineBottom); } } // Draw plus and minus if (theNode.Nodes.Count > 0) { int imageLocationY = locationY + ((int)(Font.SizeInPoints * 2) - _expanderHeight) / 2; if (theNode.IsExpanded) { g.DrawImage(_expanderExpandedImage, locationX, imageLocationY); } else { g.DrawImage(_expanderCollapsedImage, locationX, imageLocationY); } } // draw the vertical dot line for the parent nodes if necessary using (Pen pen = new Pen(LineColor)) { pen.DashStyle = DashStyle; SmartTreeNode parentNode = theNode.Parent; while (parentNode != null) { if (parentNode.NextNode != null) { int parentImageLocationX = parentNode.Bounds.X + _expanderWidth / 2; g.DrawLine(pen, parentImageLocationX, locationY - VerticalSpace, parentImageLocationX, locationY + nodeHeight); } parentNode = parentNode.Parent; } } // Draw checkbox: if (theNode.HasCheckBox) { int checkBoxLocationY = locationY + ((int)(Font.SizeInPoints * 2) - CheckBoxHeight) / 2; if (theNode.Checked) { CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.CheckedNormal); } else { CheckBoxRenderer.DrawCheckBox(g, new Point(contentArea.Left, checkBoxLocationY), CheckBoxState.UncheckedNormal); } // Update text area to account for the space needed by the checkbox: contentArea = new Rectangle(contentArea.Left + CheckBoxWidth, contentArea.Top, contentArea.Width, contentArea.Height); } theNode.DrawContent(g, contentArea); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { // The checkBox cell is disabled, so paint the border, // background, and disabled checkBox for the cell. if (!this.enabledValue) { // Draw the cell background, if specified. if ((paintParts & DataGridViewPaintParts.Background) == DataGridViewPaintParts.Background) { Brush cellBackground = new SolidBrush(this.Selected ? cellStyle.SelectionBackColor : cellStyle.BackColor); graphics.FillRectangle(cellBackground, cellBounds); cellBackground.Dispose(); } // Draw the cell borders, if specified. if ((paintParts & DataGridViewPaintParts.Border) == DataGridViewPaintParts.Border) { PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle); } CheckState checkState = CheckState.Unchecked; if (formattedValue != null) { if (formattedValue is CheckState) { checkState = (CheckState)formattedValue; } else if (formattedValue is bool) { if ((bool)formattedValue) { checkState = CheckState.Checked; } } } CheckBoxState state = checkState == CheckState.Checked ? CheckBoxState.CheckedDisabled : CheckBoxState.UncheckedDisabled; // Calculate the area in which to draw the checkBox. // force to unchecked!! Size size = CheckBoxRenderer.GetGlyphSize(graphics, state); Point center = new Point(cellBounds.X, cellBounds.Y); center.X += (cellBounds.Width - size.Width) / 2; center.Y += (cellBounds.Height - size.Height) / 2; // Draw the disabled checkBox. // We prevent painting of the checkbox if the Width, // plus a little padding, is too small. if (size.Width + 4 < cellBounds.Width) { CheckBoxRenderer.DrawCheckBox(graphics, center, state); } } else { // The checkBox cell is enabled, so let the base class // handle the painting. base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } }
public void OnDrawNode(object sender, DrawTreeNodeEventArgs e) { TreeView treeview = e.Node.TreeView; Font font = e.Node.NodeFont; if (font == null) { font = treeview.Font; } int top = e.Bounds.Y; int height = e.Bounds.Height; int nodeleft = e.Node.Bounds.X; int nodetop = e.Node.Bounds.Y; int nodeheight = e.Node.Bounds.Height; int nodewidth = e.Node.Bounds.Width; int linelength = 10; int checkboxwidth = 13; int checknodespace = 2; if (!treeview.CheckBoxes) { checkboxwidth = checknodespace = 0; } using (SolidBrush brush = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(brush, e.Node.Bounds); } using (Pen p = new Pen(Color.Gray)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; int lineleft = nodeleft - checknodespace - checkboxwidth - linelength; //draw horizontal dot line e.Graphics.DrawLine(p, lineleft, top + height / 2, lineleft + linelength, top + height / 2); // draw the up half vertical dot line if (e.Node.PrevNode != null || e.Node.Parent != null) { e.Graphics.DrawLine(p, lineleft, top, lineleft, top + height / 2); } // draw the down half vertical dot line if (e.Node.NextNode != null) { e.Graphics.DrawLine(p, lineleft, top + height / 2, lineleft, e.Node.NextNode.Bounds.Top); } // draw plus/minus image if (e.Node.Nodes.Count > 0) { if (!e.Node.IsExpanded) { e.Graphics.DrawImage(Properties.Resources.Plus, lineleft - Properties.Resources.Plus.Width / 2, top + (height - Properties.Resources.Plus.Height) / 2); } else { e.Graphics.DrawImage(Properties.Resources.Minus, lineleft - Properties.Resources.Minus.Width / 2, top + (height - Properties.Resources.Minus.Height) / 2); } } // draw the vertical dot line for the parent nodes if necessary TreeNode parentNode = e.Node.Parent; int parentNodeLeftDistance = checknodespace + checkboxwidth + linelength; while (parentNode != null) { if (parentNode.NextNode != null) { e.Graphics.DrawLine(p, parentNode.Bounds.X - parentNodeLeftDistance, top, parentNode.Bounds.X - parentNodeLeftDistance, top + height); } parentNode = parentNode.Parent; } } if (treeview.CheckBoxes) { // draw checkbox if (e.Node.Checked) { CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(nodeleft - checkboxwidth - checknodespace, top + (height - checkboxwidth) / 2), CheckBoxState.CheckedNormal); } else { CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(nodeleft - checkboxwidth - checknodespace, top + (height - checkboxwidth) / 2), CheckBoxState.UncheckedNormal); } } // erase the previous node text using (Brush b = new SolidBrush(treeview.BackColor)) { e.Graphics.DrawString(e.Node.Text, font, b, nodeleft, nodetop); } // draw node text and highlight rectangle if (e.Node.IsSelected) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds); e.Graphics.FillRectangle(Brushes.LightSkyBlue, new Rectangle(nodeleft + 1, nodetop + 1, nodewidth - 2, nodeheight - 2)); using (Brush b = new SolidBrush(Color.White)) { e.Graphics.DrawString(e.Node.Text, font, b, nodeleft, nodetop); } } else { using (Brush b = new SolidBrush(treeview.ForeColor)) { e.Graphics.DrawString(e.Node.Text, font, b, nodeleft, nodetop); } } }
void OPMCheckBox_Paint(object sender, PaintEventArgs e) { ThemeManager.PrepareGraphics(e.Graphics); int pw = 1; Color c1 = Color.Empty, c2 = Color.Empty, cb = Color.Empty, cText = Color.Empty; c1 = Enabled ? ThemeManager.GradientNormalColor1 : ThemeManager.BackColor; cb = Enabled ? ThemeManager.BorderColor : ThemeManager.GradientNormalColor2; cText = Enabled ? ThemeManager.ForeColor : Color.FromKnownColor(KnownColor.ControlDark); if (Enabled && (_isHovered || Focused)) { if (_isHovered && Focused) { c1 = ThemeManager.GradientFocusHoverColor1; cb = ThemeManager.FocusBorderColor; //pw = 2; } else if (Focused) { c1 = ThemeManager.GradientFocusColor1; cb = ThemeManager.FocusBorderColor; //pw = 2; } else { c1 = ThemeManager.GradientHoverColor1; } } Rectangle rcFill = new Rectangle(-1, 0, Width + 1, Height); using (Brush b = new SolidBrush(ThemeManager.BackColor)) { e.Graphics.FillRectangle(b, rcFill); } ButtonState bs = Checked ? ButtonState.Checked : ButtonState.Normal; bs |= ButtonState.Flat; // Get the size of the checkbox glyph (depending on OS settings this may vary) Size sz = CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.UncheckedNormal); sz = new System.Drawing.Size(sz.Width, sz.Height); int glyphTop = (CheckAlign == System.Drawing.ContentAlignment.TopLeft) ? 2 : (Height - sz.Height) / 2; Rectangle rcGlyph = new Rectangle(1, glyphTop, sz.Width - 2, sz.Height - 2); Rectangle rcCheck = new Rectangle(rcGlyph.Left + 2, rcGlyph.Top + 2, rcGlyph.Width - 4, rcGlyph.Width - 4); Rectangle rcText = new Rectangle(rcGlyph.Right + 5, 0, Width - rcGlyph.Width - 5, Height); int d = 2 * rcCheck.Width / 3; using (Brush b = new SolidBrush(c1)) using (Pen p = new Pen(cb, pw)) { e.Graphics.FillRectangle(b, rcGlyph); e.Graphics.DrawRectangle(p, rcGlyph); } using (Brush b = new SolidBrush(cText)) using (Pen p = new Pen(b, 2)) { switch (CheckState) { case CheckState.Checked: e.Graphics.DrawLine(p, rcCheck.Left, rcCheck.Top + d, rcCheck.Right - d, rcCheck.Bottom); e.Graphics.DrawLine(p, rcCheck.Right - d, rcCheck.Bottom, rcCheck.Right, rcCheck.Top); break; case CheckState.Indeterminate: e.Graphics.FillRectangle(b, rcCheck); break; } } using (Brush b = new SolidBrush(cText)) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignments.FromContentAlignment(TextAlign).Alignment; sf.LineAlignment = StringAlignments.FromContentAlignment(TextAlign).LineAlignment; sf.Trimming = StringTrimming.EllipsisWord; //sf.FormatFlags = StringFormatFlags.NoWrap; sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; e.Graphics.DrawString(this.Text, this.Font, b, rcText, sf); } }
void ForwardListView_DrawItem(object sender, DrawListViewItemEventArgs e) { if (this.View == View.Tile) { int checkBoxAreaWidth = CHECKBOX_PADDING + CHECKBOX_SIZE + CHECKBOX_PADDING; System.Drawing.Rectangle bounds = new System.Drawing.Rectangle(e.Bounds.X + checkBoxAreaWidth, e.Bounds.Top, e.Bounds.Width - checkBoxAreaWidth, e.Bounds.Height); // update information DestinationBase fc = (DestinationBase)e.Item.Tag; string display = Escape(fc.Display); string address = Escape(fc.AddressDisplay); string additional = Escape(fc.AdditionalDisplayInfo); string tooltip = String.Format("{0}\r\n{1}{2}", fc.Display, fc.AddressDisplay, (!String.IsNullOrEmpty(fc.AdditionalDisplayInfo) ? String.Format("\r\n{0}", fc.AdditionalDisplayInfo) : null)); e.Item.ToolTipText = tooltip; // NOTE: dont set the .Text or .SubItem properties here - it causes an erratic exception bool drawEnabled = ShouldDrawEnabled(fc); bool selected = this.SelectedIndices.Contains(e.ItemIndex); // draw the background for selected states if (drawEnabled && selected) { e.Graphics.FillRectangle(System.Drawing.Brushes.LightGray, e.Bounds); } else { e.DrawBackground(); } // draw the focus rectangle if (selected) { ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds); } // draw icon int newX = bounds.X; DestinationBase db = e.Item.Tag as DestinationBase; if (db != null) { System.Drawing.Image img = db.GetIcon(); // size if (img.Width > IMAGE_SIZE) { System.Drawing.Image resized = new System.Drawing.Bitmap(IMAGE_SIZE, IMAGE_SIZE); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(resized); using (g) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(img, 0, 0, IMAGE_SIZE, IMAGE_SIZE); } img = resized; } if (img != null) { int x = bounds.X; int y = bounds.Top; if (drawEnabled) { e.Graphics.DrawImage(img, new System.Drawing.Rectangle(x, y, img.Width, img.Height)); } else { ControlPaint.DrawImageDisabled(e.Graphics, img, x, y, System.Drawing.Color.Transparent); } newX += IMAGE_SIZE + this.Margin.Right; } } // offset the text vertically a bit so it lines up with the icon better System.Drawing.RectangleF rect = new System.Drawing.RectangleF(newX, bounds.Top, bounds.Right - newX, e.Item.Font.Height); rect.Offset(0, 4); // draw main text System.Drawing.Color textColor = (drawEnabled ? e.Item.ForeColor : System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb())); System.Drawing.StringFormat sf = new System.Drawing.StringFormat(); sf.Trimming = System.Drawing.StringTrimming.EllipsisCharacter; sf.FormatFlags = System.Drawing.StringFormatFlags.NoClip; System.Drawing.SolidBrush textBrush = new System.Drawing.SolidBrush(textColor); using (textBrush) { e.Graphics.DrawString(display, e.Item.Font, textBrush, rect, sf); } // draw additional information text System.Drawing.Color subColor = System.Drawing.Color.FromArgb(System.Drawing.SystemColors.GrayText.ToArgb()); System.Drawing.SolidBrush subBrush = new System.Drawing.SolidBrush(subColor); using (subBrush) { // draw address display (line 2) rect.Offset(0, e.Item.Font.Height); e.Graphics.DrawString(address, e.Item.Font, subBrush, rect, sf); // draw additional display (line 3) rect.Offset(0, e.Item.Font.Height); e.Graphics.DrawString(additional, e.Item.Font, subBrush, rect, sf); } // draw checkbox System.Windows.Forms.VisualStyles.CheckBoxState state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; if (fc.Enabled) { state = System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal; } else { state = System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal; } CheckBoxRenderer.DrawCheckBox(e.Graphics, new System.Drawing.Point(e.Bounds.Left + CHECKBOX_PADDING, e.Bounds.Top + CHECKBOX_PADDING), state); } else { e.DrawDefault = true; } }
/// <summary> /// Sets the dropDownListBox.FilterListBox size and position based on the formatted /// values in the filters dictionary and the position of the drop-down /// button. Called only by ShowDropDownListBox. /// </summary> private void SetDropDownListBoxBounds() { Debug.Assert(filters.Count > 0, "filters.Count <= 0"); // Declare variables that will be used in the calculation, // initializing dropDownListBoxHeight to account for the // ListBox borders. Int32 dropDownListBoxHeight = 2; Int32 currentWidth = 0; Int32 dropDownListBoxWidth = 0; Int32 dropDownListBoxLeft = 0; // For each formatted value in the filters dictionary Keys collection, // add its height to dropDownListBoxHeight and, if it is wider than // all previous values, set dropDownListBoxWidth to its width. using (Graphics graphics = filterWindow.FilterListBox.CreateGraphics()) { foreach (String filter in filters.Keys) { SizeF stringSizeF = graphics.MeasureString( filter, filterWindow.FilterListBox.Font); dropDownListBoxHeight += (Int32)stringSizeF.Height; currentWidth = (Int32)stringSizeF.Width; if (dropDownListBoxWidth < currentWidth) { dropDownListBoxWidth = currentWidth; } } dropDownListBoxWidth += (Int32)(CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.CheckedNormal).Width * 2.0); } // Increase the width to allow for horizontal margins and borders. dropDownListBoxWidth += 6; // Increase the width and height to take care of the width/height difference between CheckedListBox and UserControl dropDownListBoxWidth += 6; dropDownListBoxHeight += 56; // Constrain the dropDownListBox.FilterListBox height to the // DropDownListBoxMaxHeightInternal value, which is based on // the DropDownListBoxMaxLines property value but constrained by // the maximum height available in the DataGridView control. if (dropDownListBoxHeight > DropDownListBoxMaxHeightInternal) { dropDownListBoxHeight = DropDownListBoxMaxHeightInternal; // If the preferred height is greater than the available height, // adjust the width to accommodate the vertical scroll bar. dropDownListBoxWidth += SystemInformation.VerticalScrollBarWidth; } // Calculate the ideal location of the left edge of dropDownListBox.FilterListBox // based on the location of the drop-down button and taking the // RightToLeft property value into consideration. if (this.DataGridView.RightToLeft == RightToLeft.No) { dropDownListBoxLeft = DropDownButtonBounds.Right - dropDownListBoxWidth + 1; } else { dropDownListBoxLeft = DropDownButtonBounds.Left - 1; } // Determine the left and right edges of the available horizontal // width of the DataGridView control. Int32 clientLeft = 1; Int32 clientRight = this.DataGridView.ClientRectangle.Right; if (this.DataGridView.DisplayedRowCount(false) < this.DataGridView.RowCount) { if (this.DataGridView.RightToLeft == RightToLeft.Yes) { clientLeft += SystemInformation.VerticalScrollBarWidth; } else { clientRight -= SystemInformation.VerticalScrollBarWidth; } } // Adjust the dropDownListBox.FilterListBox location and/or width if it would // otherwise overlap the left or right edge of the DataGridView. if (dropDownListBoxLeft < clientLeft) { dropDownListBoxLeft = clientLeft; } Int32 dropDownListBoxRight = dropDownListBoxLeft + dropDownListBoxWidth + 1; if (dropDownListBoxRight > clientRight) { if (dropDownListBoxLeft == clientLeft) { dropDownListBoxWidth -= dropDownListBoxRight - clientRight; } else { dropDownListBoxLeft -= dropDownListBoxRight - clientRight; if (dropDownListBoxLeft < clientLeft) { dropDownListBoxWidth -= clientLeft - dropDownListBoxLeft; dropDownListBoxLeft = clientLeft; } } } // Set the ListBox.Bounds property using the calculated values. filterWindow.Bounds = this.DataGridView.RectangleToScreen( new Rectangle(dropDownListBoxLeft, DropDownButtonBounds.Bottom, dropDownListBoxWidth, dropDownListBoxHeight)); }
protected override void OnDrawItem(DrawItemEventArgs e) { Brush backColorBrush = Brushes.White; Brush foreColorBrush = Brushes.Black; switch ((Elements)e.Index) { case Elements.Fire: backColorBrush = Brushes.Red; foreColorBrush = Brushes.White; break; case Elements.Lightning: backColorBrush = Brushes.Purple; // TODO: find a better color foreColorBrush = Brushes.White; break; case Elements.Ice: backColorBrush = Brushes.LightCyan; foreColorBrush = Brushes.Black; break; case Elements.Wind: backColorBrush = Brushes.Yellow; foreColorBrush = Brushes.Black; break; case Elements.Earth: backColorBrush = Brushes.Green; foreColorBrush = Brushes.White; break; case Elements.Water: backColorBrush = Brushes.LightBlue; foreColorBrush = Brushes.Black; break; case Elements.Holy: backColorBrush = Brushes.White; foreColorBrush = Brushes.Black; break; case Elements.Dark: backColorBrush = Brushes.Black; foreColorBrush = Brushes.White; break; default: // empty break; } e.Graphics.FillRectangle(backColorBrush, e.Bounds); CheckBoxState state = this.GetItemChecked(e.Index) ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; Size checkBoxSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, state); Point loc = new Point(1, (e.Bounds.Height - (checkBoxSize.Height + 1)) / 2 + 1); CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(loc.X + e.Bounds.X, loc.Y + e.Bounds.Y), state); e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, foreColorBrush, new PointF(loc.X + checkBoxSize.Width + 1 + e.Bounds.X, loc.Y + e.Bounds.Y)); if ((Defaults != null) && (Defaults.Length > e.Index) && (Defaults[e.Index] != GetItemChecked(e.Index))) { using (Pen p = new Pen(Settings.ModifiedColor.BackgroundColor, 1)) { e.Graphics.DrawRectangle(p, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 1, e.Bounds.Height - 1)); } } if (!Enabled) { using (SolidBrush disabledRect = new SolidBrush(Color.FromArgb(100, Color.Gray))) { e.Graphics.FillRectangle(disabledRect, e.Bounds); } } }
protected override void OnPaint(PaintEventArgs e) { e.Graphics.PixelOffsetMode = PixelOffsetMode.None; e.Graphics.SmoothingMode = SmoothingMode.None; e.Graphics.Clear(Enabled ? SystemColors.Window : SystemColors.Control); ControlPaint.DrawBorder(e.Graphics, ClientRectangle, SystemColors.ControlDark, ButtonBorderStyle.Solid); Region oldClip = e.Graphics.Clip; e.Graphics.SetClip(ClientRectangleInner, CombineMode.Intersect); if (items.Count > 0) { Size sizeCheckBox = CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.CheckedNormal); using (Brush brush = new SolidBrush(Color.FromArgb(0x05000000))) { e.Graphics.FillRectangle(brush, new Rectangle(ClientRectangleInner.Left, ClientRectangleInner.Top, 6 + sizeCheckBox.Width + 6 - ClientRectangleInner.Left - 1, ClientRectangleInner.Height)); } PaintColumnLine(e.Graphics, 6 + sizeCheckBox.Width + 6, ClientRectangleInner.Top, ClientRectangleInner.Height); PaintColumnLine(e.Graphics, ClientRectangleInner.Width - (descriptionWidth + 6 - 2), ClientRectangleInner.Top, ClientRectangleInner.Height); int y = -vScrollBar.Value + ClientRectangleInner.Top + 1; // TODO: Optimization - adjust lower and upper bounds of 'i' for (int _i = 0; _i < items.Count; _i++) { if (y >= -rowHeight && y <= ClientRectangleInner.Height) { Item i = items[_i]; int itemX = 6; Rectangle boundsCheckBox = new Rectangle(itemX, y + ((rowHeight - sizeCheckBox.Height) >> 1), sizeCheckBox.Width, sizeCheckBox.Height); itemX += boundsCheckBox.Width + 8; Rectangle boundsIcon = new Rectangle(itemX + ((imageMarginSize - imageSize) >> 1), y + imageSpacing + ((imageMarginSize - imageSize) >> 1), imageSize, imageSize); itemX += imageSize + 10; Rectangle boundsText = new Rectangle(itemX, y + 1, ClientRectangleInner.Width - itemX - 1 - (descriptionWidth + 6), rowHeight - 2); Rectangle boundsDescription = new Rectangle(boundsText.Right + 6, y + 1, descriptionWidth, rowHeight - 2); i.BoundsCheckBox = boundsCheckBox; i.BoundsSelection = new Rectangle(ClientRectangleInner.Left + 1, y, ClientRectangleInner.Width - 2, rowHeight); i.BoundsIcon = boundsIcon; i.BoundsText = boundsText; // Selection Color foreColor = ForeColor; VisualStyleRenderer r = null; if (stateFocusedItem == i) { if (stateSelectedItem) { if (!Enabled || (!Focused && stateHotItem != i && stateEditItem != i)) { r = itemDisabledRenderer; } else if (stateHotItem == i || stateEditItem == i) { r = itemHotSelectedRenderer; } else { r = itemSelectedRenderer; } if (r == null) { e.Graphics.FillRectangle(SystemBrushes.Highlight, i.BoundsSelection); foreColor = SystemColors.HighlightText; } } else if (Enabled) { if (stateHotItem == i) { r = itemHotFocusedRenderer; if (r == null) { ControlPaint.DrawFocusRectangle(e.Graphics, i.BoundsSelection); } } else if (Focused) { r = itemFocusedRenderer; if (r == null) { ControlPaint.DrawFocusRectangle(e.Graphics, i.BoundsSelection); } } } } else if (stateHotItem == i && Enabled) { r = itemHotRenderer; } if (r != null) { r.DrawBackground(e.Graphics, i.BoundsSelection); } // CheckBox if (e.ClipRectangle.IntersectsWith(boundsCheckBox)) { int state = 1; // UncheckedNormal if (!Enabled || !i.CheckEnabled) { state = 4; // UncheckedDisabled } else if (i.StateCheckBox == ItemCheckBoxState.Hot) { state = 2; // UncheckedHot } else if (i.StateCheckBox == ItemCheckBoxState.Pressed) { state = 3; // UncheckedPressed } if (i.CheckState == CheckState.Indeterminate) { state += 9 - 1; } else if (i.CheckState == CheckState.Checked) { state += 5 - 1; } Point pointCheckBox = new Point(boundsCheckBox.X, boundsCheckBox.Y); CheckBoxRenderer.DrawCheckBox(e.Graphics, pointCheckBox, (CheckBoxState)state); } // Icon (Color) if (e.ClipRectangle.IntersectsWith(boundsIcon)) { using (Brush brush = new SolidBrush(i.Color)) { e.Graphics.FillRectangle(brush, boundsIcon); using (Pen pen = new Pen(Color.FromArgb(0x66000000))) { e.Graphics.DrawRectangle(pen, new Rectangle(boundsIcon.X - 1, boundsIcon.Y - 1, boundsIcon.Width + 1, boundsIcon.Height + 1)); } using (Pen pen = new Pen(Color.FromArgb(0x16000000))) { e.Graphics.DrawRectangle(pen, new Rectangle(boundsIcon.X - 2, boundsIcon.Y - 2, boundsIcon.Width + 3, boundsIcon.Height + 3)); } using (Pen pen = new Pen(Color.FromArgb(0x26ffffff))) { e.Graphics.DrawRectangle(pen, new Rectangle(boundsIcon.X, boundsIcon.Y, boundsIcon.Width - 1, boundsIcon.Height - 1)); } } } // Content if (!string.IsNullOrEmpty(i.TextDisplay) && e.ClipRectangle.IntersectsWith(boundsText)) { using (GdiGraphics g = GdiGraphics.FromGraphics(e.Graphics)) { i.textDisplay.DefaultColor = foreColor; i.textDisplay.Font = itemFont; int height2 = i.textDisplay.MeasureHeight(g); i.textDisplay.Draw(g, new Rectangle(boundsText.X + 3, boundsText.Y + ((boundsText.Height - height2) / 2), boundsText.Width - 6, height2)); } } if (!string.IsNullOrEmpty(i.Description) && e.ClipRectangle.IntersectsWith(boundsDescription)) { const TextFormatFlags flags = TextFormatFlags.Default | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.EndEllipsis; TextRenderer.DrawText(e.Graphics, i.Description, itemFont, boundsDescription, foreColor, flags); } } y += rowHeight - 1; } // Column resize line if (columnSizingState != ColumnSizingState.Normal) { int x = ClientRectangleInner.Width - (descriptionWidth + 6 - 2); using (Pen pen = new Pen(Color.FromArgb(columnSizingState == ColumnSizingState.Active ? 80 : 40, 0, 0, 0))) { e.Graphics.DrawLine(pen, x - 1, ClientRectangleInner.Top, x - 1, ClientRectangleInner.Bottom); } using (Pen pen = new Pen(Color.FromArgb(0x78ffffff))) { e.Graphics.DrawLine(pen, x - 2, ClientRectangleInner.Top, x - 2, ClientRectangleInner.Bottom); e.Graphics.DrawLine(pen, x, ClientRectangleInner.Top, x, ClientRectangleInner.Bottom); } } } else if (!string.IsNullOrEmpty(emptyText)) { TextRenderer.DrawText(e.Graphics, emptyText, Font, ClientRectangle, SystemColors.GrayText, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter); } e.Graphics.Clip = oldClip; oldClip.Dispose(); base.OnPaint(e); }
protected virtual Size GetButtonSize(Graphics g) { return(cachedGlyphSize.IsEmpty ? cachedGlyphSize = CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal) : cachedGlyphSize); }
protected override void OnDrawItem(DrawItemEventArgs e) { base.OnDrawItem(e); if (Enabled) { using (SolidBrush backBrush = new SolidBrush(BackColor)) { e.Graphics.FillRectangle(backBrush, e.Bounds); } } else { e.Graphics.FillRectangle(SystemBrushes.Control, e.Bounds); } if (e.Index == -1 || Items.Count <= e.Index) { return; } CustomTreeNode node = this.Items[e.Index] as CustomTreeNode; if (node == null) { return; } //int indent = (node.Level + 1) * NodeIndent; int indent = node.Level * NodeIndent + (ShowRootLines ? NodeIndent : 2); int TextLength = Drawing.MeasureText(node.ToString(), e.Font).Width + 2; int TextLeft = indent + (ShowCheckboxes && !node.HideCheckbox ? ItemHeight : 0) + (ShowImages ? ItemHeight : 0); //CA-59618: add top margin to the items except the first one when rendering with //visual styles because in this case there is already one pixel of margin. int topMargin = Application.RenderWithVisualStyles && e.Index == 0 ? 0 : 1; if (Enabled && node.Selectable) { Color nodeBackColor = node.Enabled ? e.BackColor : (e.BackColor == BackColor ? BackColor : SystemColors.ControlLight); using (SolidBrush backBrush = new SolidBrush(nodeBackColor)) { e.Graphics.FillRectangle(backBrush, new Rectangle(e.Bounds.Left + TextLeft + 1, e.Bounds.Top + topMargin, TextLength - 4, e.Bounds.Height)); } } //draw expander if (node.ChildNodes.Count > 0 && (ShowRootLines || node.Level > 0)) { if (!node.Expanded) { if (Application.RenderWithVisualStyles) { plusRenderer.DrawBackground(e.Graphics, new Rectangle(e.Bounds.Left + indent - ItemHeight, e.Bounds.Top + 3 + topMargin, 9, 9)); } else { e.Graphics.DrawImage(Properties.Resources.tree_plus, new Rectangle(e.Bounds.Left + indent - ItemHeight, e.Bounds.Top + 3 + topMargin, 9, 9)); } } else { if (Application.RenderWithVisualStyles) { minusRenderer.DrawBackground(e.Graphics, new Rectangle(e.Bounds.Left + indent - ItemHeight, e.Bounds.Top + 3 + topMargin, 9, 9)); } else { e.Graphics.DrawImage(Properties.Resources.tree_minus, new Rectangle(e.Bounds.Left + indent - ItemHeight, e.Bounds.Top + 3 + topMargin, 9, 9)); } } } //draw checkboxes if (ShowCheckboxes && !node.HideCheckbox) { var checkedState = CheckBoxState.UncheckedDisabled; if (node.State == CheckState.Checked) { if (node.Enabled && Enabled) { checkedState = CheckBoxState.CheckedNormal; } else if (node.CheckedIfdisabled) { checkedState = CheckBoxState.CheckedDisabled; } } else if (node.State == CheckState.Indeterminate) { checkedState = node.Enabled && Enabled ? CheckBoxState.MixedNormal : CheckBoxState.MixedDisabled; } else if (node.State == CheckState.Unchecked) { checkedState = node.Enabled && Enabled ? CheckBoxState.UncheckedNormal : CheckBoxState.UncheckedDisabled; } CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + indent, e.Bounds.Top + 1 + topMargin), checkedState); indent += ItemHeight; } //draw images if (ShowImages && node.Image != null) { var rectangle = new Rectangle(e.Bounds.Left + indent, e.Bounds.Top + topMargin, node.Image.Width, node.Image.Height); if (node.Enabled && Enabled) { e.Graphics.DrawImage(node.Image, rectangle); } else { e.Graphics.DrawImage(node.Image, rectangle, 0, 0, node.Image.Width, node.Image.Height, GraphicsUnit.Pixel, Drawing.GreyScaleAttributes); } indent += ItemHeight; } //draw item's main text Color textColor = node.Enabled && Enabled ? (node.Selectable ? e.ForeColor : ForeColor) : SystemColors.GrayText; Drawing.DrawText(e.Graphics, node.ToString(), e.Font, new Point(e.Bounds.Left + indent, e.Bounds.Top + topMargin), textColor); indent += TextLength; //draw item's description if (ShowDescription) { Drawing.DrawText(e.Graphics, node.Description, _descriptionFont, new Point(e.Bounds.Left + indent, e.Bounds.Top + 1 + topMargin), SystemColors.GrayText); } }
protected void DrawCheckBox(PaintEventArgs e, LayoutData layout) { Graphics g = e.Graphics; ButtonState style = GetState(); if (Control.CheckState == CheckState.Indeterminate) { if (Application.RenderWithVisualStyles) { CheckBoxRenderer.DrawCheckBox(g, new Point(layout.checkBounds.Left, layout.checkBounds.Top), CheckBoxRenderer.ConvertFromButtonState(style, true, Control.MouseIsOver)); } else { ControlPaint.DrawMixedCheckBox(g, layout.checkBounds, style); } } else { if (Application.RenderWithVisualStyles) { CheckBoxRenderer.DrawCheckBox(g, new Point(layout.checkBounds.Left, layout.checkBounds.Top), CheckBoxRenderer.ConvertFromButtonState(style, false, Control.MouseIsOver)); } else { ControlPaint.DrawCheckBox(g, layout.checkBounds, style); } } }
public static void Init() { CheckBoxRenderer.InitRenderer(); LabelRenderer.InitRenderer(); CheckBoxCellRenderer.Init(); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (comboBox1.SelectedItem == null) { return; } Graphics g = e.Graphics; Image i = Image.FromFile(@"accessories-character-map.png"); Font f = new Font("Microsoft Sans Serif", 8); switch (comboBox1.SelectedItem.ToString()) { case "ButtonRenderer": ButtonRenderer.DrawButton(g, new Rectangle(0, 125, 75, 23), System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(0, 25, 75, 23), System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(0, 50, 75, 23), System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(0, 75, 75, 23), System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(0, 100, 75, 23), System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(100, 125, 75, 23), true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(100, 25, 75, 23), true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(100, 50, 75, 23), true, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(100, 75, 75, 23), true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(100, 100, 75, 23), true, System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(200, 125, 75, 23), i, new Rectangle(200, 128, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(200, 25, 75, 23), i, new Rectangle(203, 28, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(200, 50, 75, 23), i, new Rectangle(203, 53, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(200, 75, 75, 23), i, new Rectangle(203, 78, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(200, 100, 75, 23), i, new Rectangle(203, 103, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(300, 125, 75, 23), "Hi there button!", f, true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(300, 25, 75, 23), "Hi there button!", f, true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(300, 50, 75, 23), "Hi there button!", f, false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(300, 75, 75, 23), "Hi there button!", f, true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(300, 100, 75, 23), "Hi there button!", f, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(400, 125, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(400, 25, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(400, 50, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(400, 75, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(400, 100, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(500, 125, 75, 23), "Hi there button!", f, i, new Rectangle(500, 128, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(500, 25, 75, 23), "Hi there button!", f, i, new Rectangle(500, 28, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(500, 50, 75, 23), "Hi there button!", f, i, new Rectangle(500, 53, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(500, 75, 75, 23), "Hi there button!", f, i, new Rectangle(500, 78, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(500, 100, 75, 23), "Hi there button!", f, i, new Rectangle(500, 103, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); ButtonRenderer.DrawButton(g, new Rectangle(600, 125, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, i, new Rectangle(600, 128, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Pressed); ButtonRenderer.DrawButton(g, new Rectangle(600, 25, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, i, new Rectangle(600, 28, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Default); ButtonRenderer.DrawButton(g, new Rectangle(600, 50, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, i, new Rectangle(600, 53, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Disabled); ButtonRenderer.DrawButton(g, new Rectangle(600, 75, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, i, new Rectangle(600, 78, 16, 16), true, System.Windows.Forms.VisualStyles.PushButtonState.Hot); ButtonRenderer.DrawButton(g, new Rectangle(600, 100, 75, 23), "Hi there button!", f, TextFormatFlags.Left & TextFormatFlags.WordEllipsis, i, new Rectangle(600, 103, 16, 16), false, System.Windows.Forms.VisualStyles.PushButtonState.Normal); break; case "CheckBoxRenderer": CheckBoxRenderer.DrawCheckBox(g, new Point(5, 5), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 5, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 4, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedDisabled); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 25), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 25, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 24, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedHot); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 45), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 45, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 44, 16, 16), true, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 65), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 65, 75, 14), "checkBox1", f, TextFormatFlags.Default, false, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedPressed); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 85), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 85, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 84, 16, 16), true, System.Windows.Forms.VisualStyles.CheckBoxState.MixedDisabled); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 105), System.Windows.Forms.VisualStyles.CheckBoxState.MixedHot); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 125), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 125, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 124, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.MixedNormal); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 145), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 145, 75, 14), "checkBox1", f, i, new Rectangle(90, 144, 16, 16), true, System.Windows.Forms.VisualStyles.CheckBoxState.MixedPressed); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 165), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 165, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 164, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedDisabled); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 185), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 185, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 184, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedHot); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 205), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 205, 75, 14), "checkBox1", f, true, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); CheckBoxRenderer.DrawCheckBox(g, new Point(5, 225), new Rectangle(8 + CheckBoxRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal).Width, 225, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 224, 16, 16), false, System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedPressed); break; case "ComboBoxRenderer": if (!ComboBoxRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } ComboBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(5, 5, 121, 21), System.Windows.Forms.VisualStyles.ComboBoxState.Normal); ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(109, 6, 16, 19), System.Windows.Forms.VisualStyles.ComboBoxState.Normal); ComboBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(5, 35, 121, 21), this.Text, this.Font, System.Windows.Forms.VisualStyles.ComboBoxState.Hot); ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(109, 36, 16, 19), System.Windows.Forms.VisualStyles.ComboBoxState.Hot); ComboBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(5, 65, 121, 21), this.Text, this.Font, new Rectangle(8, 65, 57, 21), System.Windows.Forms.VisualStyles.ComboBoxState.Disabled); ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(109, 66, 16, 19), System.Windows.Forms.VisualStyles.ComboBoxState.Disabled); ComboBoxRenderer.DrawTextBox(e.Graphics, new Rectangle(5, 95, 121, 21), this.Text, this.Font, TextFormatFlags.WordEllipsis, System.Windows.Forms.VisualStyles.ComboBoxState.Pressed); ComboBoxRenderer.DrawDropDownButton(e.Graphics, new Rectangle(109, 96, 16, 19), System.Windows.Forms.VisualStyles.ComboBoxState.Pressed); break; case "GroupBoxRenderer": Font f2 = new Font("Microsoft Sans Serif", 12); Font f3 = new Font("Microsoft Sans Serif", 14); Font f4 = new Font("Microsoft Sans Serif", 8); GroupBoxRenderer.DrawGroupBox(g, new Rectangle(5, 5, 150, 75), "My Group!", f, Color.Black, TextFormatFlags.Default, System.Windows.Forms.VisualStyles.GroupBoxState.Normal); GroupBoxRenderer.DrawGroupBox(g, new Rectangle(5, 105, 150, 75), "My Group!", f2, Color.Red, System.Windows.Forms.VisualStyles.GroupBoxState.Disabled); GroupBoxRenderer.DrawGroupBox(g, new Rectangle(5, 205, 150, 75), "My Group!", f3, TextFormatFlags.Default, System.Windows.Forms.VisualStyles.GroupBoxState.Normal); GroupBoxRenderer.DrawGroupBox(g, new Rectangle(5, 305, 150, 75), "My Group!", f4, System.Windows.Forms.VisualStyles.GroupBoxState.Disabled); GroupBoxRenderer.DrawGroupBox(g, new Rectangle(5, 405, 150, 75), System.Windows.Forms.VisualStyles.GroupBoxState.Normal); break; case "ProgressBarRenderer": if (!ProgressBarRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } g.DrawString("ChunkSpaceThickness: " + ProgressBarRenderer.ChunkSpaceThickness.ToString(), this.Font, Brushes.Black, 0, 0); g.DrawString("ChunkThickness: " + ProgressBarRenderer.ChunkThickness.ToString(), this.Font, Brushes.Black, 0, 20); ProgressBarRenderer.DrawHorizontalBar(g, new Rectangle(5, 40, 100, 20)); ProgressBarRenderer.DrawHorizontalChunks(g, new Rectangle(7, 42, 47, 16)); ProgressBarRenderer.DrawVerticalBar(g, new Rectangle(110, 40, 20, 100)); ProgressBarRenderer.DrawVerticalChunks(g, new Rectangle(112, 42, 16, 47)); break; case "RadioButtonRenderer": RadioButtonRenderer.DrawRadioButton(g, new Point(5, 5), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 5, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 4, 16, 16), false, System.Windows.Forms.VisualStyles.RadioButtonState.CheckedDisabled); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 25), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 25, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 24, 16, 16), false, System.Windows.Forms.VisualStyles.RadioButtonState.CheckedHot); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 45), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 45, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 44, 16, 16), true, System.Windows.Forms.VisualStyles.RadioButtonState.CheckedNormal); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 65), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 65, 75, 14), "checkBox1", f, TextFormatFlags.Default, false, System.Windows.Forms.VisualStyles.RadioButtonState.CheckedPressed); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 85), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 85, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 84, 16, 16), true, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedDisabled); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 105), System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedHot); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 125), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 125, 75, 14), "checkBox1", f, TextFormatFlags.Default, i, new Rectangle(90, 124, 16, 16), false, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal); RadioButtonRenderer.DrawRadioButton(g, new Point(5, 145), new Rectangle(8 + RadioButtonRenderer.GetGlyphSize(g, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedNormal).Width, 145, 75, 14), "checkBox1", f, i, new Rectangle(90, 144, 16, 16), true, System.Windows.Forms.VisualStyles.RadioButtonState.UncheckedPressed); break; case "ScrollBarRenderer": if (!ScrollBarRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } ScrollBarRenderer.DrawArrowButton(g, new Rectangle(5, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.DownDisabled); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(25, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.DownHot); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(45, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.DownNormal); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(65, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.DownPressed); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(85, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.LeftDisabled); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(105, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.LeftHot); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(125, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.LeftNormal); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(145, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.LeftPressed); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(165, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.RightDisabled); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(185, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.RightHot); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(205, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.RightNormal); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(225, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.RightPressed); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(245, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.UpDisabled); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(265, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.UpHot); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(285, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.UpNormal); ScrollBarRenderer.DrawArrowButton(g, new Rectangle(305, 5, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarArrowButtonState.UpPressed); ScrollBarRenderer.DrawHorizontalThumb(g, new Rectangle(5, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawHorizontalThumb(g, new Rectangle(45, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawHorizontalThumb(g, new Rectangle(85, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawHorizontalThumb(g, new Rectangle(125, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawHorizontalThumbGrip(g, new Rectangle(5, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawHorizontalThumbGrip(g, new Rectangle(45, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawHorizontalThumbGrip(g, new Rectangle(85, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawHorizontalThumbGrip(g, new Rectangle(125, 25, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawLeftHorizontalTrack(g, new Rectangle(5, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawLeftHorizontalTrack(g, new Rectangle(45, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawLeftHorizontalTrack(g, new Rectangle(85, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawLeftHorizontalTrack(g, new Rectangle(125, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawLowerVerticalTrack(g, new Rectangle(5, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawLowerVerticalTrack(g, new Rectangle(25, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawLowerVerticalTrack(g, new Rectangle(45, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawLowerVerticalTrack(g, new Rectangle(65, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawRightHorizontalTrack(g, new Rectangle(165, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawRightHorizontalTrack(g, new Rectangle(205, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawRightHorizontalTrack(g, new Rectangle(245, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawRightHorizontalTrack(g, new Rectangle(285, 45, 38, 18), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawSizeBox(g, new Rectangle(5, 105, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarSizeBoxState.LeftAlign); ScrollBarRenderer.DrawSizeBox(g, new Rectangle(25, 105, 18, 18), System.Windows.Forms.VisualStyles.ScrollBarSizeBoxState.RightAlign); ScrollBarRenderer.DrawUpperVerticalTrack(g, new Rectangle(85, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawUpperVerticalTrack(g, new Rectangle(105, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawUpperVerticalTrack(g, new Rectangle(125, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawUpperVerticalTrack(g, new Rectangle(145, 65, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawVerticalThumb(g, new Rectangle(5, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawVerticalThumb(g, new Rectangle(25, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawVerticalThumb(g, new Rectangle(45, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawVerticalThumb(g, new Rectangle(65, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); ScrollBarRenderer.DrawVerticalThumbGrip(g, new Rectangle(5, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Disabled); ScrollBarRenderer.DrawVerticalThumbGrip(g, new Rectangle(25, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Hot); ScrollBarRenderer.DrawVerticalThumbGrip(g, new Rectangle(45, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Normal); ScrollBarRenderer.DrawVerticalThumbGrip(g, new Rectangle(65, 105, 18, 38), System.Windows.Forms.VisualStyles.ScrollBarState.Pressed); g.DrawString(ScrollBarRenderer.GetSizeBoxSize(g, System.Windows.Forms.VisualStyles.ScrollBarState.Normal).ToString(), f, Brushes.Black, new PointF(5, 145)); g.DrawString(ScrollBarRenderer.GetThumbGripSize(g, System.Windows.Forms.VisualStyles.ScrollBarState.Normal).ToString(), f, Brushes.Black, new PointF(5, 165)); break; case "TabRenderer": if (!TabRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } TabRenderer.DrawTabPage(g, new Rectangle(5, 95, 700, 50)); TabRenderer.DrawTabItem(g, new Rectangle(5, 55, 70, 25), System.Windows.Forms.VisualStyles.TabItemState.Normal); TabRenderer.DrawTabItem(g, new Rectangle(95, 55, 70, 25), true, System.Windows.Forms.VisualStyles.TabItemState.Selected); TabRenderer.DrawTabItem(g, new Rectangle(185, 55, 70, 25), "Tab 1", f, System.Windows.Forms.VisualStyles.TabItemState.Normal); TabRenderer.DrawTabItem(g, new Rectangle(275, 55, 70, 25), i, new Rectangle(278, 58, 16, 16), false, System.Windows.Forms.VisualStyles.TabItemState.Hot); TabRenderer.DrawTabItem(g, new Rectangle(365, 55, 70, 25), "Tab 6 is too long", f, true, System.Windows.Forms.VisualStyles.TabItemState.Normal); TabRenderer.DrawTabItem(g, new Rectangle(455, 55, 70, 25), "My Tab Octopus", f, TextFormatFlags.WordEllipsis, false, System.Windows.Forms.VisualStyles.TabItemState.Disabled); TabRenderer.DrawTabItem(g, new Rectangle(545, 55, 70, 25), "Tab 7", f, i, new Rectangle(546, 56, 16, 16), true, System.Windows.Forms.VisualStyles.TabItemState.Normal); TabRenderer.DrawTabItem(g, new Rectangle(635, 55, 70, 25), "Tab 8", f, TextFormatFlags.WordEllipsis, i, new Rectangle(638, 58, 16, 16), false, System.Windows.Forms.VisualStyles.TabItemState.Disabled); break; case "TextBoxRenderer": if (!TextBoxRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } TextBoxRenderer.DrawTextBox(g, new Rectangle(5, 55, 95, 40), System.Windows.Forms.VisualStyles.TextBoxState.Assist); TextBoxRenderer.DrawTextBox(g, new Rectangle(105, 55, 95, 40), "This is my text box text!!!", f, System.Windows.Forms.VisualStyles.TextBoxState.Disabled); TextBoxRenderer.DrawTextBox(g, new Rectangle(205, 55, 95, 40), "This is my text box text!!!", f, new Rectangle(205, 55, 95, 40), System.Windows.Forms.VisualStyles.TextBoxState.Hot); TextBoxRenderer.DrawTextBox(g, new Rectangle(305, 55, 95, 40), "This is my text box text!!!", f, TextFormatFlags.WordEllipsis, System.Windows.Forms.VisualStyles.TextBoxState.Normal); TextBoxRenderer.DrawTextBox(g, new Rectangle(405, 55, 95, 40), "This is my text box text!!!", f, new Rectangle(405, 55, 95, 40), TextFormatFlags.WordEllipsis, System.Windows.Forms.VisualStyles.TextBoxState.Readonly); TextBoxRenderer.DrawTextBox(g, new Rectangle(505, 55, 95, 40), System.Windows.Forms.VisualStyles.TextBoxState.Selected); break; case "TrackBarRenderer": if (!TrackBarRenderer.IsSupported) { g.DrawString("Visual Styles not enabled", f, Brushes.Black, 0, 0); break; } TrackBarRenderer.DrawBottomPointingThumb(g, new Rectangle(5, 5, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawBottomPointingThumb(g, new Rectangle(20, 5, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawBottomPointingThumb(g, new Rectangle(35, 5, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawBottomPointingThumb(g, new Rectangle(50, 5, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawHorizontalThumb(g, new Rectangle(5, 45, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawHorizontalThumb(g, new Rectangle(20, 45, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawHorizontalThumb(g, new Rectangle(35, 45, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawHorizontalThumb(g, new Rectangle(50, 45, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawHorizontalTicks(g, new Rectangle(5, 75, 100, 20), 15, System.Windows.Forms.VisualStyles.EdgeStyle.Bump); TrackBarRenderer.DrawHorizontalTicks(g, new Rectangle(115, 75, 100, 20), 10, System.Windows.Forms.VisualStyles.EdgeStyle.Etched); TrackBarRenderer.DrawHorizontalTicks(g, new Rectangle(225, 75, 100, 20), 5, System.Windows.Forms.VisualStyles.EdgeStyle.Raised); TrackBarRenderer.DrawHorizontalTicks(g, new Rectangle(335, 75, 100, 20), 25, System.Windows.Forms.VisualStyles.EdgeStyle.Sunken); TrackBarRenderer.DrawHorizontalTrack(g, new Rectangle(5, 120, 100, 20)); TrackBarRenderer.DrawLeftPointingThumb(g, new Rectangle(5, 145, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawLeftPointingThumb(g, new Rectangle(25, 145, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawLeftPointingThumb(g, new Rectangle(45, 145, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawLeftPointingThumb(g, new Rectangle(65, 145, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawRightPointingThumb(g, new Rectangle(5, 165, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawRightPointingThumb(g, new Rectangle(25, 165, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawRightPointingThumb(g, new Rectangle(45, 165, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawRightPointingThumb(g, new Rectangle(65, 165, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawTopPointingThumb(g, new Rectangle(5, 185, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawTopPointingThumb(g, new Rectangle(20, 185, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawTopPointingThumb(g, new Rectangle(35, 185, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawTopPointingThumb(g, new Rectangle(50, 185, 12, 20), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawVerticalThumb(g, new Rectangle(5, 215, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled); TrackBarRenderer.DrawVerticalThumb(g, new Rectangle(25, 215, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot); TrackBarRenderer.DrawVerticalThumb(g, new Rectangle(45, 215, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal); TrackBarRenderer.DrawVerticalThumb(g, new Rectangle(65, 215, 20, 12), System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed); TrackBarRenderer.DrawVerticalTicks(g, new Rectangle(5, 230, 20, 100), 15, System.Windows.Forms.VisualStyles.EdgeStyle.Bump); TrackBarRenderer.DrawVerticalTicks(g, new Rectangle(50, 230, 20, 100), 10, System.Windows.Forms.VisualStyles.EdgeStyle.Etched); TrackBarRenderer.DrawVerticalTicks(g, new Rectangle(95, 230, 20, 100), 5, System.Windows.Forms.VisualStyles.EdgeStyle.Raised); TrackBarRenderer.DrawVerticalTicks(g, new Rectangle(140, 230, 20, 100), 25, System.Windows.Forms.VisualStyles.EdgeStyle.Sunken); TrackBarRenderer.DrawVerticalTrack(g, new Rectangle(185, 230, 20, 100)); g.DrawString(TrackBarRenderer.GetBottomPointingThumbSize(g, System.Windows.Forms.VisualStyles.TrackBarThumbState.Normal).ToString(), f, Brushes.Black, new Point(5, 340)); g.DrawString(TrackBarRenderer.GetLeftPointingThumbSize(g, System.Windows.Forms.VisualStyles.TrackBarThumbState.Hot).ToString(), f, Brushes.Black, new Point(5, 370)); g.DrawString(TrackBarRenderer.GetRightPointingThumbSize(g, System.Windows.Forms.VisualStyles.TrackBarThumbState.Disabled).ToString(), f, Brushes.Black, new Point(5, 400)); g.DrawString(TrackBarRenderer.GetTopPointingThumbSize(g, System.Windows.Forms.VisualStyles.TrackBarThumbState.Pressed).ToString(), f, Brushes.Black, new Point(5, 430)); break; default: break; } }
protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, @"", @"", errorText, cellStyle, advancedBorderStyle, paintParts); this.m_chkboxRegion = RectangleCommon.GetSmallRectOfRectangle(cellBounds, CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal), out m_absChkboxRegion); this.RenderCheckBox(graphics); }
public MailOptionsControl(MailAccount account) { account = account ?? new MailAccount(); InitializeComponent(); this.account = account; account.Configuration.PropertyChanged += Configuration_PropertyChanged; this.text_IdentityName.Text = account.MailConfiguration.AccountName; this.text_Email.Text = account.MailConfiguration.EmailAddress.Address; this.text_Name.Text = account.MailConfiguration.EmailAddress.Name; LoadAuthenticationSettings(account.MailConfiguration); this.check_IncludeInGlobalOperations.Checked = account.MailConfiguration.IncludeInGlobalOperations; this.checkEncryptMessages.Checked = account.MailConfiguration.EncryptMessages; this.checkIncludeCertificates.Checked = account.MailConfiguration.IncludeCertificates; this.checkSignMessages.Checked = account.MailConfiguration.SignMessages; aliases = account.MailConfiguration.Aliases; useAliasesFromSubaccounts = account.MailConfiguration.UseAliasesFromSubaccounts; //this.text_AutoBCC.AddMailAddresses(account.MailConfiguration.AutoBcc, false); //OAuthHelper.TryCreate(account.MailConfiguration.ProviderName, out oauthHelper); if (oauthHelper != null) { group_Server_Authentication.Visible = false; } //Accounts_CollectionChanged(null, new NotifyCollectionChangedEventArgs<IAccount>(NotifyCollectionChangedAction.Add, account.Accounts.ToList())); //account.Accounts.CollectionChanged += Accounts_CollectionChanged; // Account Tester testerPage = new Common.UI.Controls.ControlPanelSwitcher.SwitchPanel(); testerPage.Text = "Account Tester"; // Resources.Accounts.Mail_base.Diagnostics; testerPage.Padding = this.panel_General.Padding; // FlowLayoutPanel inside tableLayout - it doesn't work if we only dock FlowLayout to bottom, so we have to 'wrap' it this way TableLayoutPanel tablePanelOuter = new TableLayoutPanel(); tablePanelOuter.ColumnCount = tablePanelOuter.RowCount = 1; tablePanelOuter.AutoSize = true; tablePanelOuter.Dock = DockStyle.Bottom; testerPage.Controls.Add(tablePanelOuter); FlowLayoutPanel flowPanel = new FlowLayoutPanel(); flowPanel.FlowDirection = FlowDirection.TopDown; flowPanel.AutoSize = true; flowPanel.Dock = DockStyle.Fill; flowPanel.Margin = new System.Windows.Forms.Padding(0, 0, 0, 10); tablePanelOuter.Controls.Add(flowPanel); Label loggingLabel = new Label(); loggingLabel.Text = "Enable logs"; //Resources.Accounts.Mail_base.EnableLogs; loggingLabel.AutoSize = true; loggingLabel.Padding = new System.Windows.Forms.Padding(0); loggingLabel.Margin = new System.Windows.Forms.Padding(3, loggingLabel.Margin.Top, 0, 3); flowPanel.Controls.Add(loggingLabel); logCheckBoxes = new List <CheckBox>(); //foreach (IAccount subaccount in account.Accounts) //{ // if (subaccount is Licensing.LicensingAccount) // continue; // IAccount currentAccount = subaccount; // CheckBox cb = new CheckBox(); // cb.Text = currentAccount.Configuration.ProtocolName; // cb.Checked = currentAccount.Configuration.EnableLog; // cb.Tag = subaccount; // cb.Margin = new System.Windows.Forms.Padding(18, 5, 3, 0); // cb.AutoSize = true; // flowPanel.Controls.Add(cb); // logCheckBoxes.Add(cb); //} tester = new ControlAccountDiagnostics(); //this); tester.Dock = DockStyle.Fill; tester.BackColor = Color.Transparent; tester.AutoSize = true; tester.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; //testerPage.Controls.Add(tester); controlPanelTabSwitcher1.Controls.Add(testerPage); using (Graphics sg = this.CreateGraphics()) { Size size = CheckBoxRenderer.GetGlyphSize(sg, CheckBoxState.CheckedNormal); bitmapCheck = new Bitmap(size.Width, size.Height); using (Graphics g = Graphics.FromImage(bitmapCheck)) CheckBoxRenderer.DrawCheckBox(g, new Point(0, 0), CheckBoxState.CheckedNormal); size = CheckBoxRenderer.GetGlyphSize(sg, CheckBoxState.UncheckedNormal); bitmapCheckOff = new Bitmap(size.Width, size.Height); using (Graphics g = Graphics.FromImage(bitmapCheckOff)) CheckBoxRenderer.DrawCheckBox(g, new Point(0, 0), CheckBoxState.UncheckedNormal); } //DataGridColumn column; //dataGrid_Services.BeginUpdate(); //column = new DataGridColumn("", 50); //column.EditMode = EditModeType.ReadOnly; //column.DisplayMode = DataGridColumn.DisplayModeType.ImageOnly; //column.HorizontalAlign = HorizontalAlignment.Center; //column.ContentHorizontalAlign = HorizontalAlignment.Center; //column.ContentVerticalAlign = MailClient.UI.Controls.ControlDataGrid.VerticalAlignment.Center; //column.SetBindingImage("Enabled", bitmapCheck, bitmapCheckOff); //column.UseFixedWidth = true; //column.FixedWidth = 32; //dataGrid_Services.Columns.Add(column); //column = new DataGridColumn("", 50); //column.UseFixedWidth = false; //column.EditMode = EditModeType.ReadOnly; //column.Binding = "ProtocolName"; //dataGrid_Services.Columns.Add(column); //var servicesList = new BindableList<IAccountConfiguration>(account.MailConfiguration.AccountConfigurations.Where(a => !(a is Licensing.LicensingAccountConfiguration)).ToList()); //dataGrid_Services.SetDataSource(servicesList); //dataGrid_Services.EndUpdate(); // Security tab // TODO: set visibility if certificate is found //tab_Security.Visible = false; }
protected override void DrawNodeLabel(Graphics graphics, String label, Rectangle rect, NodeDrawState nodeState, NodeDrawPos nodePos, Font nodeFont, Object itemData) { var taskItem = (itemData as MindMapTaskItem); var realItem = GetRealTaskItem(taskItem); bool isSelected = (nodeState != NodeDrawState.None); Rectangle iconRect = Rectangle.Empty; if (taskItem.IsTask) // not root { // Checkbox Rectangle checkRect = CalcCheckboxRect(rect); if (m_ShowCompletionCheckboxes) { CheckBoxRenderer.DrawCheckBox(graphics, checkRect.Location, GetItemCheckboxState(realItem)); } // Task icon if (TaskHasIcon(realItem)) { iconRect = CalcIconRect(rect); if (m_TaskIcons.Get(realItem.ID)) { m_TaskIcons.Draw(graphics, iconRect.X, iconRect.Y); } rect.Width = (rect.Right - iconRect.Right - 2); rect.X = iconRect.Right + 2; } else if (m_ShowCompletionCheckboxes) { rect.Width = (rect.Right - checkRect.Right - 2); rect.X = checkRect.Right + 2; } } // Text Colour Color textColor = SystemColors.WindowText; if (!taskItem.TextColor.IsEmpty) { if (m_TaskColorIsBkgnd && !isSelected && !realItem.IsDone(true)) { textColor = DrawingColor.GetBestTextColor(taskItem.TextColor); } else if (isSelected) { textColor = DrawingColor.SetLuminance(taskItem.TextColor, 0.3f); } else { textColor = taskItem.TextColor; } } switch (nodeState) { case NodeDrawState.Selected: UIExtension.SelectionRect.Draw(this.Handle, graphics, rect.X, rect.Y, rect.Width, rect.Height, (Focused ? UIExtension.SelectionRect.Style.Selected : UIExtension.SelectionRect.Style.SelectedNotFocused), false); // opaque break; case NodeDrawState.DropTarget: UIExtension.SelectionRect.Draw(this.Handle, graphics, rect.X, rect.Y, rect.Width, rect.Height, UIExtension.SelectionRect.Style.DropHighlighted, false); // opaque break; } if (DebugMode()) { graphics.DrawRectangle(new Pen(Color.Green), rect); } // Text var format = DefaultLabelFormat(nodePos, isSelected); graphics.DrawString(label, nodeFont, new SolidBrush(textColor), rect, format); // Draw Windows shortcut icon if task is a reference if (taskItem.IsReference) { if (iconRect == Rectangle.Empty) { iconRect = rect; } else { iconRect.Y = (rect.Bottom - iconRect.Height); // don't want shortcut icon centred vertically } UIExtension.ShortcutOverlay.Draw(graphics, iconRect.X, iconRect.Y, iconRect.Width, iconRect.Height); } }
private void LstViewDrawSubItem(object sender, DrawListViewSubItemEventArgs e) { var listView = (TargetListView)sender; if (!listView.Painting) { return; } var target = e.Item.Tag as ISledTarget; if (target == null) { return; } var isLastColumn = e.ColumnIndex == (listView.Columns.Count - 1); // Used to compare against default drawing //if (!target.Imported) //{ // e.DrawDefault = true; // return; //} DrawBackground(e.Graphics, e.Bounds, listView.BackColor); DrawGridLines(e.Graphics, e.Bounds, listView.GridLinesColor); if (isLastColumn) { var extraneousFauxNonClientRect = new Rectangle( e.Bounds.Right, e.Bounds.Top, Bounds.Right - e.Bounds.Right, e.Bounds.Height); DrawBackground(e.Graphics, extraneousFauxNonClientRect, listView.BackColor); var extraneousFauxNonClientGridLinesRect = extraneousFauxNonClientRect; extraneousFauxNonClientGridLinesRect.Inflate(1, 0); DrawGridLines(e.Graphics, extraneousFauxNonClientGridLinesRect, listView.GridLinesColor); } // Start forming formatting flags var flags = TextFormatFlags.VerticalCenter; // Offset based on whether checkbox is drawn or not var iOffset = 0; // Draw a checkbox if first column if (e.ColumnIndex == 0) { var checkState = e.Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; var glyphSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, checkState); // Close to default ListView offset but not quite // exact. Not sure what their spacing values are. var iWidthOffset = (glyphSize.Width / 2) / 2; // Horizontal offset for creating new bounding // rectangle that excludes the checkbox iOffset = glyphSize.Width + (iWidthOffset * 2); // Try and center vertically within cell bounds var y = (e.Bounds.Height / 2) - (glyphSize.Height / 2); var pos = new Point(e.Bounds.X + iWidthOffset, e.Bounds.Y + y); // Draw checkbox finally CheckBoxRenderer.DrawCheckBox(e.Graphics, pos, checkState); } else { flags |= TextFormatFlags.HorizontalCenter; } // Calculate new bounds based on any offset var newBounds = new Rectangle( e.Bounds.X + iOffset, e.Bounds.Y, e.Bounds.Width - iOffset, e.Bounds.Height); // Check if the renderer wants to draw the items if (target.Plugin is ISledNetworkTargetsFormRenderer) { var args = new SledNetworkTargetsFormRenderArgs( e.Graphics, newBounds, e.Item.Font, e.Item.Selected, target, listView.TextColor, listView.HighlightTextColor, listView.HighlightBackColor); var renderer = (ISledNetworkTargetsFormRenderer)target.Plugin; switch (e.ColumnIndex) { case 0: renderer.DrawName(args); break; case 1: renderer.DrawHost(args); break; case 2: renderer.DrawPort(args); break; } // Don't draw any more if default drawing disabled if (!args.DrawDefault) { return; } } // Highlight cells if item is selected if (e.Item.Selected) { using (var brush = new SolidBrush(listView.HighlightBackColor)) e.Graphics.FillRectangle(brush, newBounds); } // Figure out text color var textColor = e.Item.Selected ? listView.HighlightTextColor : listView.TextColor; // Default font var font = e.Item.Font; // If imported target then italicize target name var bItalicized = target.Imported && (e.ColumnIndex == 0); // Italicize imported target name if (bItalicized) { font = new Font(e.Item.Font, FontStyle.Italic); } // Add ellipsis if text is wider than bounds { var textSize = TextRenderer.MeasureText(e.Graphics, e.SubItem.Text, font); if (textSize.Width > newBounds.Width) { flags |= TextFormatFlags.EndEllipsis; } } // Draw the item text TextRenderer.DrawText(e.Graphics, e.SubItem.Text, font, newBounds, textColor, flags); // Cleanup if (bItalicized) { font.Dispose(); } }
private void PackageSourcesListBox_DrawItem(object sender, DrawItemEventArgs e) { var currentListBox = (ListBox)sender; Graphics graphics = e.Graphics; e.DrawBackground(); if (e.Index < 0 || e.Index >= currentListBox.Items.Count) { return; } var currentItem = (Configuration.PackageSource)currentListBox.Items[e.Index]; using (StringFormat drawFormat = new StringFormat()) { using (Brush foreBrush = new SolidBrush(currentListBox.SelectionMode == SelectionMode.None ? SystemColors.WindowText : e.ForeColor)) { drawFormat.Alignment = StringAlignment.Near; drawFormat.Trimming = StringTrimming.EllipsisCharacter; drawFormat.LineAlignment = StringAlignment.Near; drawFormat.FormatFlags = StringFormatFlags.NoWrap; // the margin between the checkbox and the edge of the list box const int edgeMargin = 8; // the margin between the checkbox and the text const int textMargin = 4; // draw the enabled/disabled checkbox CheckBoxState checkBoxState = currentItem.IsEnabled ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; Size checkBoxSize = CheckBoxRenderer.GetGlyphSize(graphics, checkBoxState); CheckBoxRenderer.DrawCheckBox( graphics, new Point(edgeMargin, e.Bounds.Top + edgeMargin), checkBoxState); if (_checkBoxSize.IsEmpty) { // save the checkbox size so that we can detect mouse click on the // checkbox in the MouseUp event handler. // here we assume that all checkboxes have the same size, which is reasonable. _checkBoxSize = checkBoxSize; } GraphicsState oldState = graphics.Save(); try { // turn on high quality text rendering mode graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; // draw each package source as // // [checkbox] Name // Source (italics) int textWidth = e.Bounds.Width - checkBoxSize.Width - edgeMargin - textMargin; SizeF nameSize = graphics.MeasureString(currentItem.Name, e.Font, textWidth, drawFormat); // resize the bound rectangle to make room for the checkbox above var nameBounds = new Rectangle( e.Bounds.Left + checkBoxSize.Width + edgeMargin + textMargin, e.Bounds.Top, textWidth, (int)nameSize.Height); graphics.DrawString(currentItem.Name, e.Font, foreBrush, nameBounds, drawFormat); var sourceBounds = new Rectangle( nameBounds.Left, nameBounds.Bottom, textWidth, e.Bounds.Bottom - nameBounds.Bottom); graphics.DrawString(currentItem.Source, e.Font, foreBrush, sourceBounds, drawFormat); } finally { graphics.Restore(oldState); } // If the ListBox has focus, draw a focus rectangle around the selected item. e.DrawFocusRectangle(); } } }
//============================================================================* // OnMouseClick() //============================================================================* protected override void OnMouseClick(MouseEventArgs args) { int nX = args.X; int nY = args.Y; ListViewItem Item = GetItemAt(nX, nY); //----------------------------------------------------------------------------* // Find the Column that was clicked //----------------------------------------------------------------------------* int nColumn = 0; int nColumnX = 0; bool fColumnFound = false; if (Item != null) { foreach (ColumnHeader Column in Columns) { if (nX >= nColumnX && nX <= nColumnX + Column.Width) { fColumnFound = true; break; } nColumnX += Column.Width; nColumn++; } } if (fColumnFound) { ColumnHeader Header = Columns[nColumn]; Graphics g = Graphics.FromHwnd(this.Handle); SizeF TextSize = g.MeasureString(Item.SubItems[nColumn].Text, this.Font); //----------------------------------------------------------------------------* // Website Column //----------------------------------------------------------------------------* if (Header.Text == "Website") { if (Item.SubItems[nColumn].Text.Length > 0) { if (nX - nColumnX < (int)TextSize.Width) { try { System.Diagnostics.Process.Start(Item.SubItems[nColumn].Text); WebsiteVisited(Item); } catch { MessageBox.Show("Invalid Website URL. Correct the URL and try again.", "Invalid URL", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } //----------------------------------------------------------------------------* // Part Number Column //----------------------------------------------------------------------------* if (Header.Text == "Part Number" && Item.Text == "Batch Editor") { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { string strBatchNumber = Item.SubItems[1].Text; if (strBatchNumber.Length >= 7 && strBatchNumber.Substring(0, 6) == "Batch ") { strBatchNumber = strBatchNumber.Substring(6); } else { strBatchNumber = ""; } int nBatchID = 0; Int32.TryParse(strBatchNumber, out nBatchID); if (nBatchID > 0) { cBatch Batch = m_DataFiles.GetBatchByID(nBatchID); if (Batch != null) { cBatchForm BatchForm = new cBatchForm(Batch, m_DataFiles, null, cFirearm.eFireArmType.None, true); BatchForm.ShowDialog(); } } } } //----------------------------------------------------------------------------* // Caliber Column //----------------------------------------------------------------------------* if (Header.Text == "Caliber" || Header.Text == "Primary Caliber") { cCaliber Caliber = GetCaliberFromTag(Item); if (Caliber != null && !String.IsNullOrEmpty(Caliber.SAAMIPDF)) { Size BoxSize = CheckBoxRenderer.GetGlyphSize(g, (Item.Checked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal)); if ((nColumn == 0 && CheckBoxes && nX > 4 + BoxSize.Width && nX - 4 - BoxSize.Width - nColumnX < (int)TextSize.Width) || (nColumn == 0 && !CheckBoxes && nX > 4 && nX - nColumnX < (int)TextSize.Width) || (nColumn != 0 && nX > 4 && nX - nColumnX < (int)TextSize.Width)) { cCaliber.ShowSAAMIPDF(m_DataFiles, Caliber); } } } } base.OnMouseClick(args); }