如何使ListBox在mouseover上成长。 [英] How to make a ListBox grow on mouseover.

查看:73
本文介绍了如何使ListBox在mouseover上成长。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UserControl中有一个ListBox,它有点小。我希望当用户将鼠标悬停在它上面以使其更长时,以便他们可以在列表中看到更多项目。



所以当鼠标在ListBox上面时,我希望它增长到当前长度的3倍,我也不希望它延伸到其余的控制它坐在。

I have a ListBox in a UserControl and it is a little small. I want when the user hovers the mouse over it to make it longer so they can see more items in the list.

So when the mouse is over the ListBox I want it to grow to 3 times the current length, I also don't want it to stretch out the rest of the control it is sitting in.

推荐答案

listBox1.MouseEnter += new System.EventHandler(listBox1_MouseEnter);
listBox1.MouseLeave += new System.EventHandler(listBox1_MouseLeave);

private void listBox1_MouseEnter(object sender, System.EventArgs e) 
{
    listBox1.Size = new Size(100, 100) // change this to the larger size you want
}

private void listBox1_MouseLeave(object sender, System.EventArgs e) 
{
    listBox1.Size = new Size(100, 100) // change this to the original size
}


请看我对这个问题的评论。您需要的所有操作都可以通过列表框处理这两个事件来完成:

http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseenter(v = vs.110)的.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleave(v = vs.110).aspx [ ^ ]。



问题是(请参阅我对解释问题的问题的评论的第二个陈述):怎么办?你可以做不同的事情。您可以暂时减少其他控件(例如 TextBox )的空间,并为列表框提供更多空间。其中一个简单的方法是使用开源控件 SplitContainer

http://wpfsplitcontainer.codeplex.com/ [ ^ ]。



您可以将列表框作为其中一个分割部分的子项,并为其他控件留下其他部分。当鼠标进入列表框时,您可以更改分割比率,为列表框提供更多空间。



-SA
Please see my comment to the question. All the action you need can be done by handling these two events by the list box:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseenter(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.uielement.mouseleave(v=vs.110).aspx[^].

The question is (see the second statement of my comment to the question explaining the problem): what to do? You can do different things. You can temporarily reduce the room for some other controls (such as TextBox) and give more room to your list box. One of the simple ways to do this would be using the open-source control SplitContainer:
http://wpfsplitcontainer.codeplex.com/[^].

You could put your list box as a child of one of the split parts, and leave another parts for some other control(s). When your mouse enters the list box, you can change the split ratio to give more room to your list box.

—SA


除非:



1.您的布局为ListBox提供了扩展和收缩的空间,没有任何重叠或重叠的问题,其他控件或Windows:



......或者......



2.你重新调整ListBox所在的UserControl以显示ListBox,并且可能调整其他控件的位置,在内部和外部,UserControl:



可能拥有ListBox:



1.剪切超出其UserControl边界的位置



2.重叠其他控件



3.与其他控件重叠
Unless:

1. your layout provides room for the ListBox to expand and contract without any problems of overlapping, or being overlapped by, other Controls or Windows:

... or ...

2. you re-size the UserControl the ListBox is in to display the ListBox as you wish, and possibly adjust the positions of other controls, inside and outside, the UserControl:

You may have the ListBox either:

1. clipped where it goes outside the bounds of its UserControl

2. overlapping other controls

3. being overlapped by other controls


这篇关于如何使ListBox在mouseover上成长。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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