WinForm Custom Button Menu

Source: Internet
Author: User

Fill out other report buttons
private void Btnwriterep_click (object sender, EventArgs e)
{
Try
{
Point P1 = new Point ();
Point P = this.btnWriteRep.Location;

P1. X = p.x;
P1. Y = p.y + btnwriterep.height;
ContextMenuStrip. Show (This.flowlayoutpanel3, p1);
}
catch (Exception ex)
{

}
}
Load fill out other report drop-down button menu
private bool Loaddropbutton ()
{
Try
{
ContextMenuStrip = new ContextMenuStrip ();//drop-down menu
ContextMenuStrip. Font = new Font ("Arial", 10f);
List<reportlistitem> reportlist = basedeclar. Getreportlistitem ("Y");
foreach (Reportlistitem rep in Reportlist)
{
ContextMenuStrip. Items.Add (AddMenu ("[" + Rep. BBZT_MC + "]" + Rep. Name, Rep. Value, Rep. BBZT_MC));
}
Divider Line
Toolstripseparator line = new Toolstripseparator ();
ContextMenuStrip. Items.Add (line);

ContextMenuStrip. Items.Add (AddMenu ("Select more reports ...", "", ""));
ContextMenuStrip. itemclicked + = new Toolstripitemclickedeventhandler (contextmenustrip_itemclicked);
return true;
}
catch (Exception e)
{
MessageBox.Show ("Load button (fill out other report) menu failed");
return false;
}
}
Drop-down Item click event
void Contextmenustrip_itemclicked (object sender, ToolStripItemClickedEventArgs e)
{
Try
{
if (ischanged)
{
if (MessageBox.Show ("Data has changed, whether save", "hint", messageboxbuttons.yesno) = = Dialogresult.yes)
{
Btnsave_click (sender, NULL);
}
Else
{
Loadaxcelldata ();
Axcell1.readfrombuffer (prebytes);
}
Ischanged = false;
}
Select more reports to display all reports
if (E.clickeditem.text.contains ("Select More Reports"))
{
Isclosemenu = true;
ContextMenuStrip. Items.removeat (ContextMenuStrip. ITEMS.COUNT-1);
List<reportlistitem> reportlist = basedeclar. Getreportlistitem ("N");
foreach (Reportlistitem rep in Reportlist)
{
ContextMenuStrip. Items.Add (AddMenu ("[" + Rep. BBZT_MC + "]" + Rep. Name, Rep. Value, Rep. BBZT_MC));
}
ContextMenuStrip. Closing + = new Toolstripdropdownclosingeventhandler (contextmenustrip_closing);
}
Else
{
Isclosemenu = false;
Axcell1.setsheetvisible (Axcell1.getcursheet (), false);
Axcell1.setsheetvisible (Axcell1.getsheetindex (E.clickeditem.name), true);
Axcell1.setcursheet (Axcell1.getsheetindex (e.clickeditem.name));
}
}
catch (Exception ex)
{

}
}
Drop-down menu close to decide whether to close
void Contextmenustrip_closing (object sender, Toolstripdropdownclosingeventargs e)
{
if (Isclosemenu)
{
if (E.closereason = = Toolstripdropdownclosereason.appclicked | | e.closereason = = Toolstripdropdownclosereason.keyboard)
E.cancel = false;
Else
E.cancel = true;
}
}

WinForm Custom Button Menu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.