private void lvObservations_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { using (var sf = new StringFormat()) { // Draw the standard header background. e.DrawBackground(); Font font = SystemFonts.MenuFont; // Draw the header text. using (var headerFont = (Font)font.Clone()) { if (e.Header.Text == "Trash") { int height = lvObservations.Font.Height; int heightHalf = height / 2; var bounds = e.Bounds; var size = new Rectangle(bounds.X + (bounds.Width / 2) - heightHalf, bounds.Y + (bounds.Height / 2) - heightHalf, height, height); e.DrawBackground(); e.Graphics.DrawImage(Properties.Resources.GsDelete, size); } else { sf.Alignment = StringAlignment.Center; e.DrawBackground(); e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, sf); } } } }
public void DrawBackground_NullGraphics_ThrowsNullReferenceException() { var e = new DrawListViewColumnHeaderEventArgs(null, new Rectangle(1, 2, 3, 4), -1, new ColumnHeader(), ListViewItemStates.Checked, Color.Red, Color.Blue, SystemFonts.DefaultFont); if (Application.RenderWithVisualStyles) { Assert.Throws <ArgumentNullException>("dc", () => e.DrawBackground()); } else { Assert.Throws <NullReferenceException>(() => e.DrawBackground()); } }
private void mListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { if (e.ColumnIndex == 0 && mListView.CheckBoxes) { e.DrawBackground(); CheckBoxState checkBoxState = CheckBoxState.UncheckedNormal; try { switch (Convert.ToInt32(e.Header.Tag)) { case 0: checkBoxState = CheckBoxState.UncheckedNormal; break; case 1: checkBoxState = CheckBoxState.MixedNormal; break; case 2: checkBoxState = CheckBoxState.CheckedNormal; break; } CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), checkBoxState); } catch (Exception) { } } else { e.DrawDefault = true; } }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { base.OnDrawColumnHeader(e); if (e.ColumnIndex == 0) { var headerCheckBox = new CheckBox { Text = "", Visible = true }; SuspendLayout(); e.DrawBackground(); headerCheckBox.BackColor = Color.Transparent; headerCheckBox.UseVisualStyleBackColor = true; headerCheckBox.BackgroundImage = Resources.ListViewHeaderCheckboxBackgroud; headerCheckBox.SetBounds(e.Bounds.X, e.Bounds.Y, headerCheckBox.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)). Width, headerCheckBox.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)). Height); headerCheckBox.Size = new Size(headerCheckBox.GetPreferredSize(new Size(e.Bounds.Width - 1, e.Bounds.Height)).Width + 1, e.Bounds.Height); headerCheckBox.Location = new Point(4, 0); Controls.Add(headerCheckBox); headerCheckBox.Show(); headerCheckBox.BringToFront(); e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.Left); headerCheckBox.CheckedChanged += OnHeaderCheckboxCheckedChanged; ResumeLayout(true); } else { e.DrawDefault = true; } }
private void ListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { Graphics graphics = e.Graphics; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint; Rectangle _columnHeaderRectangle = new Rectangle(e.Bounds.X, e.Bounds.Y, Width - 1, e.Bounds.Height - 1); // Draws the column header background. if (_standardHeader) { e.DrawBackground(); } else { e.Graphics.FillRectangle(new SolidBrush(_columnHeaderColor), _columnHeaderRectangle); } StringFormat _stringFormat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; Rectangle _textRectangle = new Rectangle(e.Bounds.X + itemPadding, e.Bounds.Y + itemPadding, e.Bounds.Width - (itemPadding * 2), e.Bounds.Height - (itemPadding * 2)); // Draw the header text. e.Graphics.DrawString(e.Header.Text, headerFont, new SolidBrush(headerText), _textRectangle, _stringFormat); }
private void OnDrawHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); e.DrawText(); if (SortColumn != e.ColumnIndex) { return; } if (sortOrder == SortOrder.None) { return; } Image img = null; if (sortOrder == SortOrder.Ascending) { img = ArrowDrawer.get().getImage(0); } else { img = ArrowDrawer.get().getImage(1); } Rectangle rect = new Rectangle(e.Bounds.Right - 16, e.Bounds.Bottom - 16, 11, 11); e.Graphics.DrawImage(img, rect); }
/// <summary> /// Overridden Draw Column Header /// </summary> /// <param name="e"></param> protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { string sortText = _lvColumnSorter.Order == SortOrder.Ascending ? "↓" : "↑"; using (StringFormat sf = new StringFormat()) { // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; // Draw the standard header background. e.DrawBackground(); e.Graphics.DrawString(e.Header.Text, this.Font, Brushes.Black, e.Bounds, sf); if (e.ColumnIndex == _lvColumnSorter.SortColumn) { sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Near; Rectangle newBounds = e.Bounds; newBounds.Width = newBounds.Width - 2; e.Graphics.DrawString(sortText, _sortFont, Brushes.Black, newBounds, sf); } } }
private void resultListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { if (e.ColumnIndex == 0) { var cck = new CheckBox(); // With... Text = ""; Visible = true; resultListView.SuspendLayout(); e.DrawBackground(); cck.BackColor = e.BackColor; cck.UseVisualStyleBackColor = true; cck.SetBounds(e.Bounds.X, e.Bounds.Y, cck.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)).Width, cck.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)).Width); cck.Size = new Size((cck.GetPreferredSize(new Size((e.Bounds.Width - 1), e.Bounds.Height)).Width + 1), e.Bounds.Height); cck.Location = new Point(4, 0); cck.CheckState = _headerCheckState; resultListView.Controls.Add(cck); cck.Show(); cck.BringToFront(); e.DrawText((TextFormatFlags.VerticalCenter | TextFormatFlags.Left)); cck.Click += resultListViewheaderCheckAll; resultListView.ResumeLayout(true); } else { e.DrawDefault = true; } }
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { if (e.ColumnIndex == 0) { e.DrawBackground(); var value = false; try { value = Convert.ToBoolean(e.Header.Tag); } catch (Exception) { /* ignore */ } CheckBoxRenderer.DrawCheckBox( e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), value ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); } else { e.DrawDefault = true; } }
// Handle DrawColumnHeader event private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { // Draw the column header normally e.DrawDefault = true; e.DrawBackground(); e.DrawText(); }
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { TextFormatFlags flags = TextFormatFlags.LeftAndRightPadding; e.DrawBackground(); CheckBoxRenderer.DrawCheckBox(e.Graphics, ClientRectangle.Location, state); e.DrawText(flags); }
void lvLibrary_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { //https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw%28v=vs.110%29.aspx using (StringFormat sf = new StringFormat()) { // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } // Draw the standard header background. e.DrawBackground(); // Draw the header text. using (Font headerFont = new Font("Helvetica", 10, FontStyle.Bold)) { e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, sf); } } }
private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { if (SortingInfo == null || e.ColumnIndex != (int)SortingInfo.SortColumn) { e.DrawBackground(); e.DrawText(TextFormatFlags.VerticalCenter); return; } e.DrawBackground(); e.DrawText(TextFormatFlags.VerticalCenter); var image = SortingInfo.SortDirection == SortDirection.Ascending ? Resources.ascending : Resources.descending; var x = e.Bounds.X + e.Bounds.Width - image.Width - 5; var y = (e.Bounds.Height - image.Height) / 2 - 1; e.Graphics.DrawImage(image, x, y); }
//</Snippet4> //<Snippet5> // Draws column headers. private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { using (StringFormat sf = new StringFormat()) { // Store the column text alignment, letting it default // to Left if it has not been set to Center or Right. switch (e.Header.TextAlign) { case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; break; } // Draw the standard header background. e.DrawBackground(); // Draw the header text. using (Font headerFont = new Font("Helvetica", 10, FontStyle.Bold)) { e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, sf); } } return; }
// Token: 0x0600013C RID: 316 RVA: 0x0001895C File Offset: 0x00016B5C private void listView4_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { bool flag = e.ColumnIndex == 0 && this.first == 0; if (flag) { this.first = 1; CheckBox checkBox = new CheckBox(); base.Visible = true; this.listViewRRS.SuspendLayout(); e.DrawBackground(); checkBox.BackColor = Color.Transparent; checkBox.UseVisualStyleBackColor = true; checkBox.SetBounds(e.Bounds.X, e.Bounds.Y, checkBox.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)).Width, checkBox.GetPreferredSize(new Size(e.Bounds.Width, e.Bounds.Height)).Width); checkBox.Size = new Size(checkBox.GetPreferredSize(new Size(e.Bounds.Width - 1, e.Bounds.Height)).Width + 1, e.Bounds.Height); checkBox.Location = new Point(3, 0); this.listViewRRS.Controls.Add(checkBox); checkBox.Show(); checkBox.BringToFront(); e.DrawText(TextFormatFlags.VerticalCenter); checkBox.Click += this.Bink; this.listViewRRS.ResumeLayout(true); } else { e.DrawDefault = true; } }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { TextFormatFlags flags = TextFormatFlags.Left | TextFormatFlags.VerticalCenter; e.DrawBackground(); e.Graphics.FillRectangle(new SolidBrush(AppearanceSettings.HeaderBackColor), e.Bounds); TextRenderer.DrawText(e.Graphics, e.Header.Text, Font, e.Bounds, AppearanceSettings.HeaderForeColor, flags); }
private void lstMods_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { TextFormatFlags flags = TextFormatFlags.LeftAndRightPadding; e.DrawBackground(); CheckBoxRenderer.DrawCheckBox(e.Graphics, DrawOffset, state); e.DrawText(flags); }
private void UofListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); Rectangle rect = e.Bounds; this.headerHeight = rect.Height; DrawHeader(rect, e.Graphics, e.Header.Text, e.Header.TextAlign); }
private void fastListViewMain_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis); var bound = e.Bounds; e.Graphics.DrawLine(this.fastListViewMain.GridLineColorPen, bound.X, bound.Y + bound.Height - 1, bound.X + bound.Width, bound.Y + bound.Height - 1); }
public void DrawListViewColumnHeaderEventArgs_DrawBackground_Invoke_Success(Rectangle bounds, ColumnHeader header, ListViewItemStates state, Color foreColor, Color backColor, Font font) { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewColumnHeaderEventArgs(graphics, bounds, -1, header, state, foreColor, backColor, font); e.DrawBackground(); } }
/// <summary> /// Draws Column Header text /// </summary> private void DataListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { //Draw the standard header background. e.DrawBackground(); //Draw header text using (StringFormat sf = new StringFormat()) e.Graphics.DrawString(e.Header.Text, DataListView.Font, Brushes.Black, e.Bounds, sf); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Must have this when owner draw is turned on, even if this item isn't custom drawn. /// </summary> /// ------------------------------------------------------------------------------------ protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { if (m_sortColumn != e.ColumnIndex) { e.DrawDefault = true; base.OnDrawColumnHeader(e); return; } e.DrawDefault = false; e.DrawBackground(); // For some reason, the default formatting doesn't yield the same result you // get when letting the base class draw the text. This formatting is as close // as I could get to that. Maybe it's a Windows 7 thing. var flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis | TextFormatFlags.SingleLine | TextFormatFlags.NoPadding; if (RightToLeft == RightToLeft.Yes) { flags |= TextFormatFlags.RightToLeft; } e.DrawText(flags); // Draw the arrow glyph, indicating the sort direction. The // arrow will be drawn from its wider end to the point. int inc = 1; int start = e.Bounds.Top + ((e.Bounds.Height - 5) / 2) - 1; if (m_sortOrder == SortOrder.Ascending) { // Draw fat end at the bottom and move up. start += 4; inc = -1; } var pt1 = new Point(e.Bounds.Right - 20, start); var pt2 = new Point(pt1.X + 8, start); // Draw four lines, each successive line being two pixels shorter // than the previous and one line up or down from the previous. for (int i = 0; i < 4; i++) { e.Graphics.DrawLine(SystemPens.ControlDark, pt1, pt2); pt1.X++; pt2.X--; pt1.Y += inc; pt2.Y += inc; } // Draw the point. Since a line cannot be 1 pixel long, draw a vertical // line that starts at the pixel that is the point and ends one pixel // into the body of the arrow. pt2.Y -= inc; e.Graphics.DrawLine(SystemPens.ControlDark, pt1, pt2); }
public void DrawBackground_HasGraphics_Success() { using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { var e = new DrawListViewColumnHeaderEventArgs(graphics, new Rectangle(1, 2, 3, 4), -1, new ColumnHeader(), ListViewItemStates.Checked, Color.Red, Color.Blue, SystemFonts.DefaultFont); e.DrawBackground(); } }
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); bool value = Convert.ToBoolean(e.Header.Tag); CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), value ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal : System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal); }
private void HiddenWindowsListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { switch (e.ColumnIndex) { case 1: e.DrawBackground(); e.Graphics.AddImage(e.Bounds, ActionResource.lockwindow_small); break; case 2: e.DrawBackground(); e.Graphics.AddImage(e.Bounds, ActionResource.tack_small); break; default: e.DrawDefault = true; break; } }
//============================================================================* // OnDrawColumnHeader() //============================================================================* protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs args) { args.DrawBackground(); string strText = Columns[args.ColumnIndex].Text; Font HeaderFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold); SizeF TextSize = args.Graphics.MeasureString(strText, HeaderFont); Bitmap SortImage = SortingOrder == SortOrder.Ascending ? sm_SortAscendingImage : sm_SortDescendingImage; int nImageWidth = 0; if (args.ColumnIndex == SortingColumn) { nImageWidth = SortImage.Width; } int nX = args.Bounds.X; int nY = (args.Bounds.Height / 2) - (HeaderFont.Height / 2); switch (Columns[args.ColumnIndex].TextAlign) { case HorizontalAlignment.Center: nX += (int)((args.Bounds.Width / 2) - ((TextSize.Width + nImageWidth + 5) / 2)); args.Graphics.DrawString(strText, HeaderFont, Brushes.Black, nX, nY); nX += (int)TextSize.Width + 5; break; case HorizontalAlignment.Right: nX += (args.Bounds.Width - (int)TextSize.Width); args.Graphics.DrawString(strText, HeaderFont, Brushes.Black, nX, nY); nX -= (int)(5 + nImageWidth); break; case HorizontalAlignment.Left: args.Graphics.DrawString(strText, HeaderFont, Brushes.Black, nX, nY); nX += (int)TextSize.Width + 5; break; } if (args.ColumnIndex == SortingColumn) { args.Graphics.DrawImage(SortImage, nX, nY); } }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { e.DrawBackground(); DrawText(e.Graphics, Columns[e.ColumnIndex].Text, e.Bounds, SystemBrushes.WindowText, StringAlignment.Center, false); }
//private Image sd() //{ // ImageList imgList = new ImageList(); // imgList.ImageSize = new Size(1, 20); //} protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { base.OnDrawColumnHeader(e); Image imgTemp = new Bitmap(1, 40, e.Graphics); using (StringFormat sf = new StringFormat()) { switch (e.Header.TextAlign) { case HorizontalAlignment.Left: sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; break; case HorizontalAlignment.Center: sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; break; case HorizontalAlignment.Right: sf.Alignment = StringAlignment.Far; sf.LineAlignment = StringAlignment.Center; break; } var g = e.Graphics; TextFormatFlags flags = GetFormatFlags(e.Header.TextAlign); e.DrawBackground(); using (Font headerFont = new Font("宋体", 12, FontStyle.Bold)) { TextRenderer.DrawText( g, e.Header.Text, headerFont, e.Bounds, Color.Black, flags | TextFormatFlags.GlyphOverhangPadding); //e.Graphics.DrawString(e.Header.Text, headerFont, // Brushes.Black, e.Bounds, sf); } } }
protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e) { if (Type == null || Type.Columns == null) { return; } e.DrawBackground(); e.Graphics.FillRectangle(MetroBlue, e.Bounds); e.Graphics.DrawRectangle(Pens.Gray, e.Bounds); int stringWidth = (int)e.Graphics.MeasureString(e.Header.Text, EffectiveFont).Width; e.Graphics.DrawString(e.Header.Text, EffectiveFont, MetroBlack, new Point(e.Bounds.Location.X + (e.Header.TextAlign == HorizontalAlignment.Right?(e.Header.Width - stringWidth):(e.Header.TextAlign == HorizontalAlignment.Center?((e.Header.Width - stringWidth) / 2):0)), e.Bounds.Location.Y)); }
private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { if (e.ColumnIndex == 0) { //stan checkboxa zapisuję w tagu nagłówka //zaraz po wyrenderowaniu tag jest null co metoda Convert.ToBoolean zwraca jako false bool isChecked = Convert.ToBoolean(e.Header.Tag); CheckBoxState state = isChecked ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal; TextFormatFlags flags = TextFormatFlags.VerticalCenter; e.DrawBackground(); CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + 4), state);//ClientRectangle.Location e.DrawText(flags); } else { e.DrawDefault = true; } }