将填充添加到WinForms中的最后一个ListView项 [英] Add padding to last ListView item in WinForms

查看:125
本文介绍了将填充添加到WinForms中的最后一个ListView项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在列表视图的最后一项和控件底部之间添加一些额外的空间?我不想在列表底部添加一个空项目.

How can I add some extra space between the last item in a listview and the bottom of the control? I don't want to add an empty item to the bottom of the list.

推荐答案

您不能直接执行此操作.不幸的是ListView的样式选项非常有限.

You can't do this directly. Unfortunately the styling options of ListView are rather limited.

除非您要所有者绘画它..它功能强大而且并不难.但是即使在那我也怀疑Items是否可以具有不同的Heights ..

Unless you go for owner-drawing it.. Which is powerful and not very hard. But even there I doubt that the Items can have different Heights..

但是您可以使用一个简单的技巧:

But there is a simple trick you can use:

删除LV的边框,并将其放置在具有适当边框的Panel内. Dock它在那里Fill面板并给面板一个Padding可能是(0; 0; 0,10)和瞧,它将始终是一个10像素的Padding,看起来好像它属于到ListView ..

Remove the LV's borders and place it inside a Panel with appropriate borders. Dock it there to Fill the Panel and give the Panel a Padding of maybe (0;0;0,10) and voila, the will always be a Padding of 10 pixels that looks as if it belongs to the ListView..

您可以将这些行放在Form.Load中,以使其在启动时起作用:

Instead of using the Designer, you could put these lines in the Form.Load to make it work on startup:

Panel P = new Panel();
P.BackColor = listView1.BackColor;
P.Location = listView1.Location;
P.Size = listView1.Size;
P.Padding = new System.Windows.Forms.Padding(0,0,0,10);
P.BorderStyle = listView1.BorderStyle;
listView1.BorderStyle = BorderStyle.None;
listView1.Parent = P;
listView1.Dock = DockStyle.Fill;
this.Controls.Add(P);

这篇关于将填充添加到WinForms中的最后一个ListView项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆