如何使用列表框创建菜单,列表框可​​以显示文本旁边的图片 [英] How to create a menu using a listbox which can display pictures next to its text

查看:109
本文介绍了如何使用列表框创建菜单,列表框可​​以显示文本旁边的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://farm9.staticflickr.com/8241/8487654049_f9be29062d_z.jpg [ ^ ]



这是Demon Tool Lite Preference窗口表格我想设计相同的布局可以有人建议如何实现这个吗?

http://farm9.staticflickr.com/8241/8487654049_f9be29062d_z.jpg[^]

This is Demon Tool Lite Preference window form i want to design same layout can anybody suggest how to achieve this?

推荐答案

你可以使用带图片的列表框[ ^ ],当列表框中选定的索引发生变化时,您可以在右侧区域加载另一个用户控件。



使用 OnSelectedItemChanged - Event [ ^ ]列表视图以查找列表框''索引已更改。

使用右侧区域放置面板并将用户控件添加到面板:



You can use a list box with pictures [^] at the left hand side for the menu and when the selected index on the list box changes you can load another user control on the area on the right hand side.

Use the OnSelectedItemChanged - Event[^] of the list view to find out when the listbox'' index was changed.
Use the area on the right to place there a panel and add your user control to the panel:

//Add this line of code to your form loading method.
listbox.OnSelectedIndexChanged += new EventHandler(listbox_OnSelectedItemChanged);

//Add this method to the code behind of the form
private void listbox_OnSelectedItemChanged(object sender, EventArgs e)
{
   myPanel.Controls.Clear();//myPanel is the Panel where your user control is placed inside

   //MenuItemEnum is an Enum where you store your different menu item types
   //I preassume that the listbox is filled with members of the menuitemenum type.
   //Change this behavior if this should be not the case.
   if((MenutItemEnum)listbox.SelectedItem == MenuItemEnum.General)
   {
        YourUserControl yourUserControl = new YourUserControl();
        myPanel.Controls.Add(yourUserControl);
   }
}





欢呼,

Marco Bertschi



cheers,
Marco Bertschi


这篇关于如何使用列表框创建菜单,列表框可​​以显示文本旁边的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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