Boblysan

Boblysan

  • NA
  • 66
  • 0

Well, I know what causes this now.. PLEASE HELP

Dec 9 2003 12:37 AM
**Form1.cs(125): No overload for method 'button1_Click' takes '0' arguments** Ok, I now know why this error comes up, but I am still very confused on how to fix it. I have created a very simple application with two forms. There is a button on form1 which does nothing more than bring up a second form via the showDialog() method. My goal is to call this same method from a context menu selection. When doing so, I continue to get the error from above. I understand that the error comes up because the information within the parentheses does not match.. The two conflicting pieces of code are: ******************************************************** private void button1_Click(object sender, System.EventArgs e) { Form2 frmNew = new Form2(); frmNew.ShowDialog(); } private void menuItem2_Click(object sender, System.EventArgs e) { button1_Click(); } ********************************************************** I don't understand what it is I need to put between the parentheses on the second item to make the compiler happy. If I attempt to match up both of them exactly, I receive a totally different error. Any information you all can provide would be much appreciated. Thanks, Bob ****** Full Code of Sample App ******** using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication1 { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.ContextMenu contextMenu1; private System.Windows.Forms.NotifyIcon notifyIcon1; private System.Windows.Forms.MenuItem menuItem1; private System.Windows.Forms.MenuItem menuItem2; private System.ComponentModel.IContainer components; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.button1 = new System.Windows.Forms.Button(); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.menuItem2 = new System.Windows.Forms.MenuItem(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(144, 56); this.button1.Name = "button1"; this.button1.TabIndex = 0; this.button1.Text = "Test"; this.button1.Click += new System.EventHandler(this.button1_Click); // // contextMenu1 // this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem2}); // // notifyIcon1 // this.notifyIcon1.ContextMenu = this.contextMenu1; this.notifyIcon1.Text = "notifyIcon1"; this.notifyIcon1.Visible = true; // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "Exit"; // // menuItem2 // this.menuItem2.Index = 1; this.menuItem2.Text = "Test"; this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(352, 234); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1}); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void button1_Click(object sender, System.EventArgs e) { Form2 frmNew = new Form2(); frmNew.ShowDialog(); } private void menuItem2_Click(object sender, System.EventArgs e) { button1_Click(); } } }

Answers (2)