ListViewItemStates问题

问题描述

protectedoverridevoidOnDrawItem(DrawListViewItemEventArgse){base.OnDrawItem(e);DrawItemInternal(e);}internalvoidDrawItemInternal(DrawListViewItemEventArgse){RectanglebackRect=e.Bounds;Graphicsg=e.Graphics;ListViewItemitem=e.Item;ListViewItemStatesitemState=e.State;ImageListimageList=item.ImageList;boolbDrawImage=(imageList!=null)&&(item.ImageIndex!=-1||!string.IsNullOrEmpty(item.ImageKey));boolbSelected=(itemState&ListViewItemStates.Selected)!=0;if(bDrawImage){DrawImage(g,item,bSelected);}if(bDrawImage==true){backRect.X=backRect.X+20;backRect.Width=backRect.Width-20;}Rectanglerect=newRectangle(backRect.X,backRect.Y,backRect.Width-1,backRect.Height-1);//Console.WriteLine(itemState.ToString());if(itemState==(ListViewItemStates.Focused|ListViewItemStates.ShowKeyboardCues|ListViewItemStates.Selected)){RectangleFrectf=newRectangleF(backRect.X,backRect.Y,backRect.Width-1,backRect.Height-0.5f);using(SolidBrushblueBrush=newSolidBrush(Color.FromArgb(49,106,196))){g.FillRectangle(blueBrush,rectf);}using(Penpen1=newPen(Color.Black)){pen1.DashStyle=System.Drawing.Drawing2D.DashStyle.Dot;g.DrawRectangle(pen1,rect);}}if(itemState==(ListViewItemStates.Focused|ListViewItemStates.ShowKeyboardCues)){using(Penpen1=newPen(Color.Black)){pen1.DashStyle=System.Drawing.Drawing2D.DashStyle.Dot;g.DrawRectangle(pen1,rect);}}Console.WriteLine(itemState.ToString());}

我订制了自己的listvie,并且重绘了item.当我鼠标点击item的时候,背景是蓝色,并且有虚线框围绕。代码如下:if(itemState==(ListViewItemStates.Focused|ListViewItemStates.ShowKeyboardCues|ListViewItemStates.Selected))但是上面的代码是我在windowxsxp下实现的,如果在win7下面,判断条件就要变成如下:if(itemState==(ListViewItemStates.Focused|ListViewItemStates.Selected))为什么会这样?

时间: 2024-10-01 18:44:22

ListViewItemStates问题的相关文章

C# ListView 如何重绘 图标 按比例缩放

问题描述 C#ListView如何重绘图标按比例缩放只做到了再item边框绘线,求大神帮忙指点下怎么调整image按比例缩放try{Graphicsg=e.Graphics;Rectanglerect=Rectangle.Empty;Imageimage=imageList2.Images[e.Item.ImageIndex];stringfname=listView1.Items[e.Item.ImageIndex].Name;rect=newRectangle(e.Bounds.Left,e