DrawBackground() public méthode

public DrawBackground ( ) : void
Résultat void
 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;
     }
 }
Exemple #2
0
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            base.OnDrawColumnHeader(e);
            e.DrawBackground();
            e.DrawText();

            //e.BackColor = System.Drawing.Color.AliceBlue;
        }
        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;
            }
        }
 /// <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);
 }
Exemple #5
0
        /// <summary>
        /// Performs custom actions when owner draws columns header</summary>
        /// <param name="e">Draw ListView column header event args</param>
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            base.OnDrawColumnHeader(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.
                var bound = e.Bounds;
                bound.Y += 3;
                bound.X += 8;
                if (e.ColumnIndex == 0)
                    bound.X += CheckBoxWidth;

                var brush = Enabled ? m_columnHeaderTextBrush : m_columnHeaderTextBrushDisabled;
                e.Graphics.DrawString(e.Header.Text, HeaderFont, brush, bound, sf);


                if (e.ColumnIndex == m_sortColumn) // Draw sort arrow
                {
                    float w = e.Graphics.MeasureString(e.Header.Text, HeaderFont).Width;
                    if (m_sortColumn == 0)
                        w += CheckBoxWidth + 2; 
                    if (e.Bounds.Width > w + s_sortAscendingImage.Width + 8) // get enough room left for the arrow icon
                    {
                        Point pt = new Point(e.Bounds.Location.X + e.Bounds.Width - s_sortAscendingImage.Width - 4,
                        e.Bounds.Top + (e.Bounds.Height - s_sortAscendingImage.Height) / 2);
                        if (m_sortDirection == ListSortDirection.Ascending)
                            e.Graphics.DrawImage(s_sortAscendingImage, pt);
                        else
                            e.Graphics.DrawImage(s_sortDescendingImage, pt);
                    }
                }

                if (CheckBoxes && e.ColumnIndex ==0)
                {
                    // draw check mark
                    Point pt = new Point(e.Bounds.Location.X, e.Bounds.Top + 3);
                    e.Graphics.DrawString(m_tickSymbol, m_tickFont, Enabled ? m_columnHeaderCheckMarkBrush : m_columnHeaderCheckMarkBrushDisabled, pt);
                   
                    // draw a vertical line to make check mark appear in its own column                 
                    e.Graphics.DrawLine(m_columnHeaderSeparatorPen, CheckBoxWidth, e.Bounds.Top,
                        CheckBoxWidth, e.Bounds.Bottom - 2);
                   
                }
            }
        }
Exemple #6
0
 private void DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
 {
     e.DrawDefault = true;
     e.DrawBackground();
     e.DrawText();
 }
Exemple #7
0
        private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawBackground();
              var brush = regularStateBrush;
              if (e.Header.Index == 1)
            brush = currentStateBrush;
              else if (e.Header.Index == 2)
            brush = previousStateBrush;

              Rectangle r = e.Bounds;
              r.X += 5;
              r.Y += 4;
              DrawString(e.Graphics, e.Header.Text, e.Header.ListView.Font, brush, r);
        }
Exemple #8
0
 private void lvPlugins_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
 {
     if (e.ColumnIndex == 0)
     {
         e.DrawBackground();
         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 ? System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal :
             System.Windows.Forms.VisualStyles.CheckBoxState.UncheckedNormal);
     }
     else
     {
         e.DrawDefault = true;
     }
 }
Exemple #9
0
        private static void OnDrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            using ( StringFormat sf = new StringFormat())
            {
                // Workout the text alignment
                switch( e.Header.TextAlign)
                {
                    case HorizontalAlignment.Center:
                        sf.Alignment = StringAlignment.Center;
                        break;
                    case HorizontalAlignment.Right:
                        sf.Alignment = StringAlignment.Far;
                        break;
                }

                // Draw the standard background
                e.DrawBackground();

                // Draw the header text
                using ( Font headerFont = new Font(View.Font.FontFamily, View.Font.Size))
                {
                    e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Blue, e.Bounds, sf);
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Takes care of drawing a column header using an image.
        /// </summary>
        /// <param name="e">The DrawListViewColumnHeader event arguments.</param>
        /// <param name="colH">The ColumnHeader to be drawn.</param>
        /// <param name="img">The Image where to draw the column.</param>
        private static void DrawColumnHeader(DrawListViewColumnHeaderEventArgs e, ColumnHeader colH, Image img)
        {
            int width = TextRenderer.MeasureText(" ", e.Font).Width;
            string text = colH.Text;
            HorizontalAlignment textAlign = colH.TextAlign;
            TextFormatFlags flags = (textAlign == HorizontalAlignment.Left) ? TextFormatFlags.GlyphOverhangPadding : ((textAlign == HorizontalAlignment.Center) ? TextFormatFlags.HorizontalCenter : TextFormatFlags.Right);
            flags |= TextFormatFlags.WordEllipsis | TextFormatFlags.VerticalCenter;

            if (img != null)
            {
                int halfWidth = width / 2;

                Rectangle imgBounds = new Rectangle(e.Bounds.Location.X + halfWidth, e.Bounds.Location.Y + 1, e.Bounds.Size.Height, e.Bounds.Size.Height - 3);
                Rectangle txtBounds = new Rectangle(imgBounds.Location.X + imgBounds.Size.Width + halfWidth, e.Bounds.Location.Y, e.Bounds.Size.Width - (imgBounds.Size.Width + 2 * halfWidth), e.Bounds.Size.Height);

                e.DrawBackground();
                e.Graphics.DrawImage(img, imgBounds);
                TextRenderer.DrawText(e.Graphics, text, e.Font, txtBounds, e.ForeColor, flags);
            }
            else
            {
                e.DrawBackground();
                TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, e.ForeColor, flags);
            }
        }
Exemple #11
0
		void DhListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
		{
			var paleBlue = Color.FromArgb(187, 235, 254);
			var veryPaleBlue = Color.FromArgb(227, 247, 255);
			var lightBlue = Color.LightBlue;
			var drawRect = e.Bounds;
			// For some reason Bounds.Height is much too big. Bigger than our whole control!
			drawRect.Height = Height - 4;
			int imageIndex;
			//e.Header.Index is it's index in the original, un-dragged list of columns.
			//m_columnIconIndexes is indexed by the current display position of columns that require the icon to be displayed.
			var currentDisplayPositionOfColumn = OrderForColumnsDisplay[e.Header.Index];
			if (!m_columnIconIndexes.TryGetValue(currentDisplayPositionOfColumn, out imageIndex))
				imageIndex = -1;
			if (imageIndex >= 0)
				drawRect.Width -= m_imgList.ImageSize.Width;

			var topHeight = drawRect.Height / 2 - 1;
			var drawText = e.Header.Text;
			var realSize = e.Graphics.MeasureString(drawText, e.Font);
			if ((e.State & ListViewItemStates.Selected) != 0)
			{
				using (var brush = new SolidBrush(paleBlue))
				{
					e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, topHeight));
				}
				using (var brush = new SolidBrush(lightBlue))
				{
					e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top + topHeight, e.Bounds.Width, e.Bounds.Height - topHeight));
				}
			}
			else if (e.Bounds.Contains(PointToClient(Cursor.Position))) // seems to be no state that indicates mouse is in it...Hot should but doesn't.
			{
				m_hotRectangle = e.Bounds;
				if (m_timer == null)
				{
					m_timer = new Timer();
					m_timer.Interval = 50;
					m_timer.Tick += m_timer_Tick;
					m_timer.Start();
				}
				m_cTicks = 0;
				if (realSize.Width > drawRect.Width)
				{
					m_tooltipText = drawText;
				}
				else
				{
					m_tooltipText = null;
				}
				using (var brush = new SolidBrush(veryPaleBlue))
				{
					e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, topHeight));
				}
				using (var brush = new SolidBrush(paleBlue))
				{
					e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Left, e.Bounds.Top + topHeight, e.Bounds.Width, e.Bounds.Height - topHeight));
				}
			}
			else
			{
				e.DrawBackground(); // standard background
			}
			// Draw the header text.
			if (realSize.Width > drawRect.Width)
			{
				// Guess how much we can fit.
				int len = (int)(drawText.Length * drawRect.Width / realSize.Width) + 1;

				// Subtract more until it fits.
				do
				{
					len = len - 1;
					Debug.Assert(len >= 0, "length should not be negative");
					drawText = drawText.Substring(0, len) + "\x2026"; // ellipsis
					realSize = e.Graphics.MeasureString(drawText, e.Font);
				} while (len > 0 && realSize.Width > drawRect.Width);

				// Add any more that fits.
				while (len < e.Header.Text.Length - 1)
				{
					len = len + 1;
					var possibleText = e.Header.Text.Substring(0, len) + "\x2026"; // ellipsis
					realSize = e.Graphics.MeasureString(possibleText, e.Font);
					if (realSize.Width > drawRect.Width)
						break; // we can't add this one more character.
					drawText = possibleText; // we can fit this much at least.
				}
			}
			using (StringFormat sf = new StringFormat())
			{
				sf.Trimming = StringTrimming.Character;
				sf.FormatFlags = StringFormatFlags.NoWrap;
				sf.LineAlignment = StringAlignment.Far; // bottom

				//if (drawRect.Height > realSize.Height - 2)
				//{
				//    drawRect = new Rectangle(drawRect.X, drawRect.Top + drawRect.Height - (int)realSize.Height - 2, drawRect.Width, (int)realSize.Height + 2);
				//}
				e.Graphics.DrawString(drawText, e.Font,
					Brushes.Black, drawRect, sf);
			}
			if (imageIndex >= 0)
			{
				var size = m_imgList.ImageSize;
				m_imgList.Draw(e.Graphics, e.Bounds.Right - 2 - size.Width, e.Bounds.Top + 2, imageIndex);
			}
		}
        private void ListViewOnDrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            e.DrawBackground();
            e.Graphics.FillRectangle(new SolidBrush(CurrentBaseSkin.BackColor), e.Bounds);
            e.Graphics.DrawLine(new Pen(CurrentBaseSkin.ForeColor, 1), e.Bounds.Left, e.Bounds.Bottom - 2,
                e.Bounds.Right,
                e.Bounds.Bottom - 2);
            e.Graphics.DrawLine(new Pen(CurrentBaseSkin.ForeColor, 1), e.Bounds.Left - 1, e.Bounds.Bottom - 2,
                e.Bounds.Left - 1,
                0);

            using (var sf = new StringFormat
            {
                Alignment = StringAlignment.Near,
                LineAlignment = StringAlignment.Center
            })
                e.Graphics.DrawString(e.Header.Text, CurrentBaseSkin.Font, new SolidBrush(CurrentBaseSkin.ForeColor),
                    e.Bounds, sf);
        }
        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);
                }
            }
        }
		/// <summary>
		/// Owner draw requires drawing the column header as well as the list items.  See LT-7007.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void currentList_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
		{
			e.DrawBackground();
			e.DrawText();
		}
Exemple #15
0
 private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
 {
     e.DrawBackground();
     e.DrawText();
 }
Exemple #16
0
        void SortableListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            bool fSorted = (this._sortColumn == e.ColumnIndex);

            if (fSorted)
            {
                e.DrawBackground();
                e.DrawText(TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis);

                //如果是排序,并且图片不为空,那么绘制图标
                if (fSorted && (_imageAscending != null) && (this._imageDescending != null))
                {
                    Point ptImage = new Point(e.Bounds.Left + (int)e.Graphics.MeasureString(e.Header.Text + "XY", e.Font).Width, (e.Bounds.Top + e.Bounds.Bottom - _imageAscending.Height) / 2);
                    e.Graphics.DrawImage((this._sortOrder > 0) ? _imageAscending : _imageDescending, ptImage);
                }

                this.Refresh();
            }
            else
            {
                e.DrawDefault = true;
            }
        }
Exemple #17
0
        private void KaiListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            StringFormat sf = new StringFormat();
            sf.LineAlignment = StringAlignment.Center;

            if (0 == e.ColumnIndex)
            {
                sf.Alignment = StringAlignment.Center;
            }
            else
            {
                switch (e.Header.TextAlign)
                {
                    case HorizontalAlignment.Left:
                    {
                        sf.Alignment = StringAlignment.Near;
                        break;
                    }
                    case HorizontalAlignment.Center:
                    {
                        sf.Alignment = StringAlignment.Center;
                        break;
                    }
                    case HorizontalAlignment.Right:
                    {
                        sf.Alignment = StringAlignment.Far;
                        break;
                    }
                }
            }

            e.DrawBackground();
            Font f = new Font("Arial", 9, FontStyle.Bold);
            e.Graphics.DrawString(e.Header.Text, f, SystemBrushes.WindowText, e.Bounds, sf);
        }