C#中的listview怎么才能得到垂直滚动条
2个回答
展开全部
子类化,重载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()));
}
}
}
}
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()));
}
}
}
}
2016-03-22
展开全部
private void Form1_Load(object sender, EventArgs e)
{
ListViewItem lw = new ListViewItem("aaaaaaaaaaaaaaaaaaaaaaaa");
listViewEx1.Items.Add(lw);
}
{
ListViewItem lw = new ListViewItem("aaaaaaaaaaaaaaaaaaaaaaaa");
listViewEx1.Items.Add(lw);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询