返回信息流SplitterContainer上面再放tablelayout之类的控件,dock.fill 然后再放ListBox
在然后试试
这是一条镜像帖。来源:北邮人论坛 / dot-net / #3710同步于 2012/5/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖
Re: [求助]郁闷的SplitterContainer问题
ahomer
2012/5/10镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
【 在 dao 的大作中提到: 】
: 嗯,N多次拖拽之后偶然发现,ListBox高度以单行高度为单位,不足将用边框补齐。
:
果然是这样,知道原因了以后,还是很容易解决的,这个就需要自己绘制边框了.将 drawMode 设置为OwnerDrawVariable,也就是说自己绘制边框.
接下来出来一下 两个事件,第一个是 MeasureItem,第二个是DrawItem;这两个事件的意思很明白了,这里我给一个参考的结果.可以按自己的要求改其他的.
private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemWidth = 15;
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
int index = e.Index;//获取当前要进行绘制的行的序号,从0开始。
Graphics g = e.Graphics;//获取Graphics对象。
Rectangle bound = e.Bounds;//获取当前要绘制的行的一个矩形范围。
string text = listBox1.Items[index].ToString();//获取当前要绘制的行的显示文本。
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{//如果当前行为选中行。
//绘制选中时要显示的蓝色边框。
g.DrawRectangle(Pens.Blue, bound.Left, bound.Top, bound.Width - 1, bound.Height - 1);
Rectangle rect = new Rectangle(bound.Left, bound.Top,
bound.Width, bound.Height);
//绘制选中时要显示的蓝色背景。
g.FillRectangle(Brushes.Blue, rect);
//绘制显示文本。
TextRenderer.DrawText(g, text, this.Font, rect, Color.Black,
TextFormatFlags.VerticalCenter | TextFormatFlags.Left);
}
else
{
g.FillRectangle(Brushes.White, bound);
TextRenderer.DrawText(g, text, this.Font, bound, Color.Black,
TextFormatFlags.VerticalCenter | TextFormatFlags.Left);
}
}
【 在 dao 的大作中提到: 】
: 一个Form,一个Vertical的SplitterContainer,上下各一ListBox。
: 开始效果:
:
: ...................
[upload=2][/upload] 10表示没有压力~~
【 在 buptwm 的大作中提到: 】
: [upload=1][/upload][upload=2][/upload] 10表示没有压力~~
vs2010 使用的是.net4 , System.Windows.Forms 这个库已经重新写过了。