Windows窗体中的动态菜单栏可能吗? [英] Dynamic menustrip in windows form is possible?

查看:51
本文介绍了Windows窗体中的动态菜单栏可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

文件

退出

我尝试在Windows窗体中执行动态菜单条.

第一亲本的形式是永久固定的.生成有关数据库的子项.

我刚刚用Name,ParentId,image,eventhandler创建了一个数据表.

在Windows窗体代码中..

hi friends,

File
new
exit

i try to do Dynamic menu strip in windows form,.

the first parent is permanently fixed in form. the child are generated regarding the database.

i just created a data table with Name, ParentId, image, eventhandler.

in windows form code,..

string MyConString = "server=192.168.1.100;User Id=root;Persist Security Info=True;database=cms";
            MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "select * from menu_details";
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                string a = Convert.ToString(1);
                if (Reader[5].ToString() == a)
                {
                    string j = @"D:\cms-image\";
                    string k = Reader[13].ToString();
                    tsm_File.DropDownItems.Add(Reader[1].ToString(), Image.FromFile(j + k), new EventHandler(newToolStripMenuItem_Click));
                }                
            }
            connection.Close();



在那我达到一半.但我想为每个更改EventHandler.可能吗?.



In that i reach half,. but i wanna change EventHandler for each,. is it possible?. if possible means how.?

推荐答案

理想情况下,您应该可以对所有菜单项使用相同的事件.
只需检查发送对象并根据发送者编写代码(在菜单单击处理程序中).
Ideally, you should be able to use the same event for all menu items.
Just check the send object and write code based on the sender (in the menu click handler).


这篇关于Windows窗体中的动态菜单栏可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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