gpt4 book ai didi

c# - 如何在按钮上显示菜单项单击工具条

转载 作者:太空宇宙 更新时间:2023-11-03 15:11:37 25 4
gpt4 key购买 nike

我正在开发一个应用程序,我必须从数据库动态加载工具条上的菜单。到目前为止,我已经创建了菜单及其工作,现在我必须在工具条按钮单击事件上显示该菜单。

这是我的代码:

private void toolstripform_Load(object sender, EventArgs e)
{
this.IsMdiContainer = true;
this.Controls.Add(toolStrip1);
string slctcmd = string.Format("SELECT * FROM MNU_PARENT where MENUPARVAL = 2 ");
DataTable dt = qc.DataReaderTable(slctcmd);
foreach(DataRow dr in dt.Rows)
{
ToolStripMenuItem MnuStripItem = new ToolStripMenuItem(dr["MAINMNU"].ToString());
SubMenu(MnuStripItem, dr["MENUPARVAL"].ToString());
toolStrip1.Items.Add(MnuStripItem);
}
}
public void SubMenu(ToolStripMenuItem mnu, string submenu)
{
string slctcmd = string.Format("SELECT FRM_NAME FROM MNU_SUBMENU WHERE MENUPARVAL='" + submenu + "'");
DataTable dt = qc.DataReaderTable(slctcmd);
foreach(DataRow dr in dt.Rows)
{
ToolStripMenuItem SSMenu = new ToolStripMenuItem(dr["FRM_NAME"].ToString(), null, new EventHandler(ChildClick));
mnu.DropDownItems.Add(SSMenu);
}
}
private void ChildClick(object sender, EventArgs e)
{
// MessageBox.Show(string.Concat("You have Clicked ", sender.ToString(), " Menu"), "Menu Items Event",MessageBoxButtons.OK, MessageBoxIcon.Information);
string slctcmd = string.Format("SELECT FRM_CODE FROM MNU_SUBMENU WHERE FRM_NAME= '" + sender.ToString() + "'");
DataTable dtransaction = qc.DataReaderTable(slctcmd);
Assembly frmAssembly = Assembly.LoadFile(Application.ExecutablePath);
foreach(Type type in frmAssembly.GetTypes())
{
//MessageBox.Show(type.Name);
if (type.BaseType == typeof (Form))
{
if (type.Name == dtransaction.Rows[0][0].ToString())
{
Form frmShow = (Form) frmAssembly.CreateInstance(type.ToString());
// then when you want to close all of them simple call the below code
foreach(Form form in this.MdiChildren)
{
form.Close();
}
frmShow.MdiParent = this;
frmShow.StartPosition = FormStartPosition.CenterScreen;
//frmShow.WindowState = FormWindowState.Maximized;
//frmShow.ControlBox = false;
frmShow.Show();
}
}
}
}

目前显示的是: currently showing this..

我希望它显示如下: I want like this..

最佳答案

     MnuStripItem.MouseDown += new MouseEventHandler(mainM_MouseDown);

    private void mainM_MouseDown(object sender, MouseEventArgs e)
{
//if (e.Button == MouseButtons.Left)
if (e.Button == MouseButtons.Right)
{
cMenuS_main_it.Show(Cursor.Position);
}
}

关于c# - 如何在按钮上显示菜单项单击工具条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com