åç±»åï¼éè½½WndProcæ¹æ³ï¼ç¨windows api设置æ»å¨æ¡
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
/// <summary>
/// åç±»åListViewï¼å¨Viewå±æ§æ¯Listçæ¶ååºåç´æ»å¨æ¡
/// </summary>
public class ListViewEx : ListView
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int ShowScrollBar(IntPtr hWnd, int iBar, int bShow);
const int SB_HORZ = 0;
const int SB_VERT = 1;
protected override void WndProc(ref Message m)
{
if (this.View == View.List)
{
ShowScrollBar(this.Handle, SB_VERT, 1);
ShowScrollBar(this.Handle, SB_HORZ, 0);
}
base.WndProc(ref m);
}
}
/// <summary>
/// æµè¯ä»£ç
/// </summary>
public Form1()
{
InitializeComponent();
//æµè¯æ®élistview
ListView list = new ListView();
list.View = View.List;
this.Controls.Add(list);
list.Size = new Size(100, 100);
list.Location = new Point(100, 100);
for (int i = 0; i < 100; i++)
{
list.Items.Add(new ListViewItem(Guid.NewGuid().ToString()));
}
//æµè¯åç±»åçlistview
list = new ListViewEx();
list.View = View.List;
this.Controls.Add(list);
list.Size = new Size(100, 100);
list.Location = new Point(300, 100);
for (int i = 0; i < 100; i++)
{
list.Items.Add(new ListViewItem(Guid.NewGuid().ToString()));
}
}
}
}
温馨提示:答案为网友推荐,仅供参考