Avatar of Rama Tito
Rama Tito
Flag for Malaysia

asked on 

Create a class for customize right click

Hi, i am quite new for C# in class oriented program. I am trying to create a class for customize right click for mouse. While trying to run the program the error message pop up. Please do advice.


Error pop ups : Argument Exception was unhandled in Program.cs. As below

namespace Class_Calculator
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());   <<<<-------------------------Error pointed
        }
    }
}
////////////////////mouse.cs//////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Class_Calculator
{
    class mouse : Form
    {
        ContextMenuStrip mnu;
        ToolStripMenuItem mnuSwitch;
        ToolStripMenuItem mnuWire;
        ToolStripMenuItem mnuRelay;        

        public mouse()
        {
            this.mnu = new ContextMenuStrip();
            this.mnuSwitch = new ToolStripMenuItem("Switch");
            this.mnuWire = new ToolStripMenuItem("Wire");
            this.mnuRelay = new ToolStripMenuItem("Relay");


            mnuSwitch.Image = Image.FromFile(@"E:\C#\Uthaya Project\ico\ico\Switch.ico");
            mnuWire.Image = Image.FromFile(@"E:\C#\Uthaya Project\ico\ico\Wire.ico");
            mnuRelay.Image = Image.FromFile(@"E:\C#\Uthaya Project\ico\ico\Relay.ico");

            mnu.Items.AddRange(new ToolStripItem[] { mnuSwitch, mnuWire, mnuRelay }); 
        }
    }
}

///////////////////////Form1///////////////////////////////
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Class_Calculator
{
    public partial class Form1 : Form
    {
        

        public Form1()
        {
            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            this.ContextMenuStrip = mnu;
        }
    }
}

Open in new window

C#

Avatar of undefined
Last Comment
nishant joshi

8/22/2022 - Mon