本文整理汇总了C#中System.Windows.Forms.DrawListViewItemEventArgs.DrawBackground方法的典型用法代码示例。如果您正苦于以下问题:C# DrawListViewItemEventArgs.DrawBackground方法的具体用法?C# DrawListViewItemEventArgs.DrawBackground怎么用?C# DrawListViewItemEventArgs.DrawBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DrawListViewItemEventArgs
的用法示例。
在下文中一共展示了DrawListViewItemEventArgs.DrawBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IconListView_DrawItem
private void IconListView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
IconListViewItem item = e.Item as IconListViewItem;
if (item == null)
{
e.DrawDefault = true;
return;
}
// Draw item
e.DrawBackground();
Pen border = SystemPens.ControlLight;
if (e.Item.Selected)
{
if (this.Focused)
border = SystemPens.Highlight;
else
border = SystemPens.ButtonFace;
}
int centerSpacing = (e.Bounds.Width - this.TileSize.Width - TilePadding.Horizontal) / 2 + TilePadding.Left;
Rectangle newBounds = new Rectangle(e.Bounds.X + centerSpacing, e.Bounds.Y + TilePadding.Top, this.TileSize.Width, this.TileSize.Height);
e.Graphics.DrawRectangle(border, newBounds);
//e.Graphics.DrawString("Whatever", this.Font, e., 0, 0);
int x = e.Bounds.X + (newBounds.Width - item.Icon.Width) / 2 + centerSpacing + 1;
int y = e.Bounds.Y + (newBounds.Height - item.Icon.Height) / 2 + TilePadding.Top + 1;
Rectangle rect = new Rectangle(x, y, item.Icon.Width, item.Icon.Height);
Region clipReg = new Region(newBounds);
e.Graphics.Clip = clipReg;
e.Graphics.DrawIcon(item.Icon, rect);
string text = string.Format("{0} x {1}", item.Icon.Width, item.Icon.Height);
SizeF stringSize = e.Graphics.MeasureString(text, this.Font);
int stringWidth = (int) Math.Round(stringSize.Width);
int stringHeight = (int) Math.Round(stringSize.Height);
x = e.Bounds.X + (e.Bounds.Width - stringWidth - TilePadding.Horizontal) / 2 + TilePadding.Left;
y = e.Bounds.Y + this.TileSize.Height + verticalSpacing + TilePadding.Top;
clipReg = new Region(e.Bounds);
e.Graphics.Clip = clipReg;
if (e.Item.Selected)
{
if (this.Focused)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight, x - 1, y - 1, stringWidth + 2, stringSize.Height + 2);
e.Graphics.DrawString(text, this.Font, SystemBrushes.HighlightText, x, y);
}
else
{
e.Graphics.FillRectangle(SystemBrushes.ButtonFace, x - 1, y - 1, stringWidth + 2, stringSize.Height + 2);
e.Graphics.DrawString(text, this.Font, SystemBrushes.ControlText, x, y);
}
}
else
e.Graphics.DrawString(text, this.Font, SystemBrushes.ControlText, x, y);
}
示例2: HiddenWindowsListView_DrawItem
private void HiddenWindowsListView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
WindowInfo currentItem = (e.Item as WindowListViewItem).Window;
switch (this.View)
{
case View.LargeIcon:
e.DrawDefault = false;
e.DrawBackground();
Rectangle itemBounds = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Width, 65));
//if (e.Item.Selected)
// e.Graphics.FillRectangle(SystemColors.Highlight.ToBrush(), e.Bounds);
Rectangle iconBounds = e.Graphics.AddImage(e.Bounds, currentItem.ApplicationIcon, null,
(e.Item.Selected) ? 16 : 18);
e.Graphics.AddImage(e.Bounds,
(currentItem.IsPasswordProtected)
? ActionResource.lockwindow_small
: ActionResource.unlockwindow_small, ImageOverlayPosition.TopLeft);
if (currentItem.IsPinned)
e.Graphics.AddImage(e.Bounds, ActionResource.tack_small, ImageOverlayPosition.TopRight);
//e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.EndEllipsis | TextFormatFlags.HorizontalCenter);
Rectangle rec = new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width - 4,
e.Bounds.Height - 4);
TextRenderer.DrawText(e.Graphics, e.Item.Text, e.Item.Font, rec, e.Item.ForeColor,
TextFormatFlags.Bottom | TextFormatFlags.Left | TextFormatFlags.EndEllipsis
| TextFormatFlags.ExpandTabs | TextFormatFlags.SingleLine);
//e.DrawFocusRectangle();
break;
default:
e.DrawDefault = true;
break;
}
if ((bool) e.Item.SubItems[1].Tag != currentItem.IsPasswordProtected)
{
e.Item.SubItems[1].Tag = currentItem.IsPasswordProtected;
e.Item.SubItems[1].Text = currentItem.IsPasswordProtected ? "Yes" : "No";
}
if ((bool) e.Item.SubItems[2].Tag != currentItem.IsPinned)
{
e.Item.SubItems[2].Tag = currentItem.IsPinned;
e.Item.SubItems[2].Text = currentItem.IsPinned ? "Yes" : "No";
}
}
示例3: listView1_DrawItem
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
string previewStr = char.ConvertFromUtf32(LastChar);
var sf = new StringFormat(StringFormatFlags.NoFontFallback);
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
var font = new Font(e.Item.Text, 72f, FontStyle.Regular, GraphicsUnit.Pixel);
var smallFont = new Font(e.Item.Text, 12f, FontStyle.Regular, GraphicsUnit.Pixel);
e.Graphics.DrawString(previewStr, font, SystemBrushes.WindowText, e.Bounds, sf);
RectangleF labelRect = new RectangleF(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - 24), e.Bounds.Width, 24);
e.Graphics.DrawString(e.Item.Text, smallFont, SystemBrushes.WindowText, labelRect, sf);
}
示例4: lvIcons_DrawItem
private void lvIcons_DrawItem(object sender, DrawListViewItemEventArgs e) {
e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
if ((e.State & ListViewItemStates.Hot) != 0 && (e.State & ListViewItemStates.Selected) == 0) {
this._ItemHoverRenderer.DrawBackground(e.Graphics, e.Bounds);
} else if ((e.State & ListViewItemStates.Hot) != 0 && (e.State & ListViewItemStates.Selected) != 0) {
this._Selectedx2Renderer.DrawBackground(e.Graphics, e.Bounds);
} else if ((e.State & ListViewItemStates.Selected) != 0) {
this._ItemSelectedRenderer.DrawBackground(e.Graphics, e.Bounds);
} else {
e.DrawBackground();
}
var ico = _Icons[(int)e.Item.Tag].Icon;
if (ico.Width <= 48) {
e.Graphics.DrawIcon(_Icons[(int)e.Item.Tag].Icon,
e.Bounds.X + (e.Bounds.Width - ico.Width) / 2, e.Bounds.Y + (e.Bounds.Height - ico.Height) / 2 - 5);
}
e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordEllipsis);
}
示例5: lstFunctions_DrawItem
void lstFunctions_DrawItem(object sender, DrawListViewItemEventArgs e)
{
var tag = e.Item.Tag;
if (tag == null || tag.GetType() != typeof(Function))
{
e.DrawDefault = true;
}
else
{
e.DrawBackground();
}
}
示例6: C1_DrawItem
void C1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
if (main == null)
return;
e.DrawBackground();
e.DrawFocusRectangle();
RectangleF E = e.Bounds;
SizeF Q = e.Graphics.MeasureString(e.Item.Text, F);
Guid g = Guid.Empty;
if (e.Item.Tag is gCInventory_PS_Wrapper.InventoryItem)
g = (e.Item.Tag as gCInventory_PS_Wrapper.InventoryItem).ItemGuid;
else g = (Guid)e.Item.Tag;
if (ResourceManager.Rects.ContainsKey(g))
{
RectangleF r0 = ResourceManager.Rects[g];
RectangleF r1 = E;
r1.Height -= Q.Height;
float sh = (r1.Height / r0.Height);
float sw = (r1.Width / r0.Width);
if (sw > sh)//new box not heigh enough
{
float h = r0.Height * sh;
float w = r0.Width * sh;
float q0 = (r1.Width - w) / 2.0f;
r1.X += q0;
r1.Width = w;
r1.Height = h;
}
else
{
}
e.Graphics.DrawImage(main, r1, r0, GraphicsUnit.Pixel);
}
e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter);
}
示例7: lstFiles_DrawItem
private void lstFiles_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawBackground();
e.DrawDefault = true;
e.DrawText();
e.DrawFocusRectangle();
}
示例8: lstShow_DrawItem
private void lstShow_DrawItem(object sender, DrawListViewItemEventArgs e)
{
ListView listView = new ListView();
listView = (ListView)sender;
e.DrawBackground();
e.Graphics.DrawString(listView.Items[e.ItemIndex].Text, e.Item.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
for (int i = 0; i < _lstResult.Count; i++)
{
if (e.ItemIndex.ToString() == _lstResult[i])
{
bool selected = ((e.State & ListViewItemStates.Selected) == ListViewItemStates.Selected);
//搜尋過後尚未選取發生的事件
if(!selected)
{
e.Graphics.FillRectangle(new SolidBrush(Color.Silver), e.Bounds);
e.Graphics.DrawString(listView.Items[e.ItemIndex].Text, e.Item.Font, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
}
//搜尋過選取時發生的事件
else
{
}
}
//搜尋過後不符合的項目想發生的事件往這寫
}
if (((e.State & ListViewItemStates.Selected) == ListViewItemStates.Selected))
{
////設定指定物件填充背景的大小
//Rectangle r = new Rectangle(e.Bounds.Left + 4, e.Bounds.Top, TextRenderer.MeasureText(e.Item.Text, e.Item.Font).Width, e.Bounds.Height);
////設定填充的顏色和無間
//e.Graphics.FillRectangle(SystemBrushes.Highlight, r);
////設定物件中的字體顏色
//e.Item.ForeColor = SystemColors.HighlightText;
//e.DrawText();
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
e.Graphics.DrawString(listView.Items[e.ItemIndex].Text, e.Item.Font, Brushes.White, e.Bounds, StringFormat.GenericDefault);
}
e.DrawFocusRectangle();
}
示例9: ForwardListView_DrawItem
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,
//.........这里部分代码省略.........
示例10: lvTitles_DrawItem
private void lvTitles_DrawItem(object sender, DrawListViewItemEventArgs e)
{
//if (e.Index < 0) return;
// Find the printing bounds
int x = e.Bounds.X;
int y = e.Bounds.Y;
//int w = e.Bounds.Width;
//int w = lvTitles.Size.Width - 20;
int w = lvTitles.ClientRectangle.Width;
int h = e.Bounds.Height;
// Create the brushes
if (_brushTitleListSelected == null)
{
_brushTitleListSelected = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.LimeGreen, Color.PaleGreen);
_brushTitleListFolder = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.Gainsboro, Color.Silver);
_brushTitleListFolderSelected = new LinearGradientBrush(new Point(0, 0), new Point(0, e.Bounds.Height), Color.Silver, Color.LightGreen);
}
Title currentTitle = null;
int? currentTitleID = null;
if (e.Item.Text == "All Media")
{
currentTitle = new Title();
currentTitle.Name = e.Item.Text;
currentTitle.TitleType = TitleTypes.Collection;
}
else
{
currentTitleID = Convert.ToInt32(e.Item.Text);
currentTitle = _movieList[(int)currentTitleID];
}
// Setup string formatting
StringFormat stf = new StringFormat();
stf.Trimming = StringTrimming.EllipsisCharacter;
stf.FormatFlags = StringFormatFlags.NoWrap;
e.DrawBackground();
if ((currentTitle.TitleType & TitleTypes.AllFolders) != 0)
{
// Folder specific paint goes here
if (lvTitles.SelectedItems.ContainsKey(currentTitle.Id.ToString()))
{
e.Graphics.FillRectangle(_brushTitleListFolderSelected, x, y, w, h);
}
else
{
e.Graphics.FillRectangle(_brushTitleListFolder, x, y, w, h);
}
e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);
int titleCount = 0;
if (currentTitleID == null)
{
titleCount = _movieRootCount;
}
else
{
if (_movieCount.ContainsKey((int)currentTitleID))
{
titleCount = _movieCount[(int)currentTitleID];
}
}
e.Graphics.DrawString("Total titles " + titleCount.ToString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(x, y + 18, w - 65, h), stf);
e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);
}
else
{
if (lvTitles.SelectedItems.ContainsKey(currentTitle.Id.ToString()))
{
e.Graphics.FillRectangle(_brushTitleListSelected, x, y, w, h);
}
// Media specific paint goes here
e.Graphics.DrawString(currentTitle.Name, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(x, y + 2, w - 65, h), stf);
e.Graphics.DrawString(currentTitle.ReleaseDate.ToShortDateString(), new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Black), new RectangleF(w - 60, y + 2, w, h), stf);
//e.Graphics.DrawString(currentTitle.Runtime.ToString() + " minutes, " + currentTitle.Studio, new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Gray), new RectangleF(8, y + 16, w - 40, h), stf);
e.Graphics.DrawString(currentTitle.Runtime.ToString() + " minutes", new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular), new SolidBrush(Color.Gray), new RectangleF(x + 22, y + 19, w - 102, h), stf);
// Draw percentage complete box
Image MetaPercentage = ImgMetaPercentage1;
if (currentTitle.PercentComplete <= .2M)
{
MetaPercentage = ImgMetaPercentage1;
}
else if (currentTitle.PercentComplete <= .4M)
{
MetaPercentage = ImgMetaPercentage2;
}
else if (currentTitle.PercentComplete <= .6M)
{
MetaPercentage = ImgMetaPercentage3;
}
else if (currentTitle.PercentComplete <= .8M)
//.........这里部分代码省略.........
示例11: ArgumentsList_DrawItem
private void ArgumentsList_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawBackground();
if(e.ItemIndex < ArgumentsList.Items.Count - 1)
{
CheckBoxState State = e.Item.Checked? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal;
Size CheckSize = CheckBoxRenderer.GetGlyphSize(e.Graphics, State);
CheckBoxRenderer.DrawCheckBox(e.Graphics, new Point(e.Bounds.Left + 4, e.Bounds.Top + (e.Bounds.Height - CheckSize.Height) / 2), State);
DrawItemLabel(e.Graphics, SystemColors.WindowText, e.Item);
}
else
{
DrawItemLabel(e.Graphics, SystemColors.GrayText, e.Item);
}
}
示例12: FileStatusListView_DrawItem
private void FileStatusListView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
if (e.Bounds.Height <= 0 || e.Bounds.Width <= 0 || e.ItemIndex < 0)
return;
e.DrawBackground();
Color color;
if (e.Item.Selected)
{
e.Graphics.FillRectangle(SystemBrushes.Highlight, e.Bounds);
color = SystemColors.HighlightText;
}
else
color = SystemColors.WindowText;
e.DrawFocusRectangle();
e.Graphics.FillRectangle(Brushes.White, e.Bounds.Left, e.Bounds.Top, ImageSize, e.Bounds.Height);
int centeredImageTop = e.Bounds.Top;
if ((e.Bounds.Height - ImageSize) > 1)
centeredImageTop = e.Bounds.Top + ((e.Bounds.Height - ImageSize) / 2);
var image = e.Item.ImageList.Images[e.Item.ImageIndex];
if (image != null)
e.Graphics.DrawImage(image, e.Bounds.Left, centeredImageTop, ImageSize, ImageSize);
GitItemStatus gitItemStatus = (GitItemStatus)e.Item.Tag;
string text = GetItemText(e.Graphics, gitItemStatus);
if (gitItemStatus.IsSubmodule && gitItemStatus.SubmoduleStatus != null && gitItemStatus.SubmoduleStatus.IsCompleted)
text += " " + gitItemStatus.SubmoduleStatus.Result.AddedAndRemovedString();
e.Graphics.DrawString(text, e.Item.ListView.Font,
new SolidBrush(color), e.Bounds.Left + ImageSize, e.Bounds.Top);
}
示例13: OnDrawItem
// ********************************************************************************
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <returns></returns>
/// <created>UPh,31.10.2015</created>
/// <changed>UPh,31.10.2015</changed>
// ********************************************************************************
protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
if (e.Item.Selected)
e.Graphics.FillRectangle(_SelectedItemBrush, e.Bounds);
else
e.DrawBackground();
TermListItem item = GetItemAt(e.ItemIndex);
Color tbcolor = Color.Empty;
if (TermBaseSet != null)
{
if (item != null)
tbcolor = TermBaseSet.GetDisplayColor(item.TermBaseID);
}
if (tbcolor != Color.Empty)
{
SolidBrush brush = new SolidBrush(tbcolor);
Rectangle rcBar = e.Bounds;
rcBar.Width = 4;
e.Graphics.FillRectangle(brush, rcBar);
}
Rectangle rect = e.Bounds;
rect.X += 4;
rect.Y += 2;
if (item != null && item.Status == TermStatus.prohibited)
{
e.Graphics.DrawImage(Resources.Prohibited_sm, rect.Left, rect.Top);
rect.X += 12;
}
e.Graphics.DrawString(e.Item.Text, Font, _TextBrush, rect.X, rect.Y);
e.DrawFocusRectangle();
}
示例14: listView_DrawItem
private void listView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
if (e.Item.Tag != null)
{
e.Item.Checked = (bool)e.Item.Tag;
}
e.DrawBackground();
e.DrawText();
}
示例15: listView1_DrawItem
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawBackground();
Rectangle itemRect = new Rectangle(e.Bounds.Left+2 ,
e.Bounds.Top+1,
e.Bounds.Width - 4-1,
e.Bounds.Height - 2);
//画线
e.Graphics.DrawLine(new Pen(new SolidBrush(Color.FromArgb(240, 240, 240))),
new Point(itemRect.X, itemRect.Y + itemRect.Height),
new Point(itemRect.X + itemRect.Width - 4, itemRect.Y + itemRect.Height));
//if (listView1.SelectedIndices.Count > 1)
//{
// itemRect = new Rectangle(e.Bounds.Left + 3,
// e.Bounds.Top,
// e.Bounds.Width - 4,
// e.Bounds.Height);
//}
//draw mouse move item back
if (listViewItem1 != null &&
e.Item == listViewItem1 && NativeInterop.IsWinVista)
{
e.Graphics.FillRectangle(brush3, itemRect);
e.Graphics.DrawRectangle(pen3, itemRect);
//listView1.Refresh();
}
//focusd item
if ((e.State & ListViewItemStates.Focused) != 0)
{
e.Graphics.DrawRectangle(pen1, itemRect);
focusedListViewItem1 = e.Item;
}
//draw selected item
if (e.Item.Selected)
{
if (listView1.Focused)
{
e.Graphics.FillRectangle(brush1, itemRect);
e.Graphics.DrawRectangle(pen1, itemRect);
}
else
{
e.Graphics.FillRectangle(brush2, itemRect);
e.Graphics.DrawRectangle(pen2, itemRect);
}
}
Size size = TextRenderer.MeasureText(e.Item.Text, listView1.Font);
//text
Rectangle textRect = new Rectangle(e.Item.Bounds.Left + 16 + 8,
e.Item.Bounds.Top + size.Height/2 -2 ,
e.Item.Bounds.Width - 50,
20);
//e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Red)), textRect);
e.Graphics.DrawString(e.Item.Text, listView1.Font, new SolidBrush(listView1.ForeColor), textRect);
//HTML Icon
Rectangle imgRect = new Rectangle(4,
e.Item.Bounds.Top + 8,
16,
16);
e.Graphics.DrawImage(pictureBox1.Image, imgRect);
//e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Blue)), imgRect);
//ATTACH IMG
//string filename = path + "\\" + e.Item.Text + fileExt;
//listView1.Items[Index].SubItems[1].Text = filename;
string attachdir = DirectoryCore.Get_AttachmentsDirectory(e.Item.SubItems[1].Text);
if (Directory.Exists(attachdir))
{
Rectangle attachRect = new Rectangle(e.Bounds.Right - 22,
e.Item.Bounds.Top + 8,
16,
16);
e.Graphics.DrawImage(pictureBox2.Image, attachRect);
//e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), attachRect);
}
}