當前位置:編程學習大全網 - 源碼下載 - C#中的listview如何獲得垂直滾動條?

C#中的listview如何獲得垂直滾動條?

子類,重載WndProc方法,用windows api設置滾動條

使用系統;

使用系統。繪圖;

使用系統。Windows . Forms

命名空間WindowsApplication1

{

公共分部類表單1:表單

{

///& lt;總結& gt

///子類ListView,當View屬性為List時顯示垂直滾動條。

///& lt;/summary & gt;

公共類ListViewEx : ListView

{

【系統。runtime . interop services . dllimport(" user 32 . dll ")]

public static extern int show scroll bar(int ptr hWnd,int iBar,int b show);

const int SB _ HORZ = 0;

const int SB _ VERT = 1;

保護覆蓋無效WndProc(參考消息m)

{

如果(這個。視圖==視圖。列表)

{

ShowScrollBar(this。Handle,SB_VERT,1);

ShowScrollBar(this。Handle,SB_HORZ,0);

}

基地。WndProc(ref m);

}

}

///& lt;總結& gt

///測試代碼

///& lt;/summary & gt;

公共表單1()

{

initialize component();

//測試普通listview

ListView list = new ListView();

列表。視圖=視圖。列表;

這個。Controls.Add(列表);

列表。尺寸=新尺寸(100,100);

列表。位置=新點(100,100);

for(int I = 0;我& lt100;i++)

{

列表。Items.Add(新的ListViewItem(Guid。NewGuid()。ToString()));

}

//測試子類listview

list = new listview ex();

列表。視圖=視圖。列表;

這個。Controls.Add(列表);

列表。尺寸=新尺寸(100,100);

列表。位置=新點(300,100);

for(int I = 0;我& lt100;i++)

{

列表。Items.Add(新的ListViewItem(Guid。NewGuid()。ToString()));

}

}

}

}

  • 上一篇:tea1761的工作原理是什麽?
  • 下一篇:完成架構意味著什麽?
  • copyright 2024編程學習大全網