问题描述
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))为什么会这样?