internal static void pic_Click(object sender, EventArgs e) { PictureBox pic = sender as PictureBox; // MessageBox.Show(pic.Tag.ToString()); // MessageBox.Show(.Text); Form f = pic.FindForm(); if (f != null) { Type t = f.GetType(); MenuInfo info = pic.Tag as MenuInfo; try { t.InvokeMember(info.MethodName, BindingFlags.Default | BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, f, new object[] { info.Right }); } catch (MissingMethodException ex) { //MessageBoxHelper.Show("找不到方法"+info.MethodName); } } //Console.WriteLine("click the menuItem!"+tmp.Text); //throw new Exception("The method or operation is not implemented."); }
public PicMenuItem(MenuInfo info) { pic = new PictureBox(); pic.Image = info.Image; // pic.Location = // pic.Size = info.Image.Size; pic.MouseMove += new MouseEventHandler(OnMouseMove); pic.MouseLeave += new EventHandler(OnMouseLeave); lb = new Label(); lb.Text = info.ShowText; this.Height = pic.Image.Height + lb.Height+1; pic.Click += new EventHandler(pic_Click); pic.Tag = info; // lb.BorderStyle = BorderStyle.FixedSingle; //Console.WriteLine("the PicMenuItem "+info.ShowText); // Console.WriteLine("image height:"+pic.Image.Height+"image width:"+pic.Image.Width); // Console.WriteLine("the pic location x:" + pic.Location.X); // Console.WriteLine("the pic location y:" + pic.Location.Y); // Console.WriteLine("the lb location x:" + lb.Location.X); // Console.WriteLine("the lb location y:" + lb.Location.Y); // this.BackColor = Color.Red; // this.BorderStyle = BorderStyle.FixedSingle; this.ResetLocation(); this.Controls.Add(pic); this.Controls.Add(lb); }