Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3395624
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:18:41+00:00 2026-05-18T04:18:41+00:00

my goal is to open a ContextMenuStrip on right click remember this click x

  • 0

my goal is to open a ContextMenuStrip on right click remember this click x and y and then on clicking on one of the given items to do something till now this is what i have done:

public delegate void mydelegate(string s);

public Form1()
{
    InitializeComponent();
    m_MyContextMenuStrip = new ContextMenuStrip();
    m_MyContextMenuStrip.Opening += new System.ComponentModel.CancelEventHandler(cms_Opening);
    this.ContextMenuStrip = m_MyContextMenuStrip; 
}

void cms_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
    m_MyContextMenuStrip.Items.Clear();

    location1 = m_MyContextMenuStrip.PointToClient(new Point(0, 0));
    location = m_MyContextMenuStrip.PointToScreen(new Point(0, 0));
    // Populate the ContextMenuStrip control with its default items.
    m_MyContextMenuStrip.Items.Add("-");
    m_MyContextMenuStrip.Items.Add("Apples");
    m_MyContextMenuStrip.Items.Add(location.X.ToString() + "and  " + location.Y.ToString());

    m_MyContextMenuStrip.Items.Add("aaaa", null, new EventHandler(onaaaClick));
    // Set Cancel to false. 
    // It is optimized to true based on empty entry.
    e.Cancel = false;
}

private void onaaaClick(object sender, EventArgs e)
{
    //will handle the click on aaa

    Form2 f2 = new Form2(functodel);
    f2.Show();
}

void functodel(string s)
{
    Label l = new Label();
    l.Text = s;

    l.Top = location.Y - 108;
    l.Left = location.X - 100;
    //l.Left = this.Location.X - location.X;  

    l.BorderStyle = BorderStyle.FixedSingle;
    this.Controls.Add(l);
    l.BringToFront();
}

where Form2 is:

private mydelegate m_del;

public Form2(mydelegate del)
{
    m_del = del;
    InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
    m_del(textBox1.Text);
    this.Close();
}

my problem is when i click on the right click i am not getting the location i want, i am getting another location. can someone explain to me what am i doing wrong ?

  1. how to get the right location.

  2. how to get a ContextMenuStrip where i had only once an item?

  3. let’s say on the given label i am righting i want to click on the right click and get another optiones then in m_ContextMenuStrip (delete item and change color) how do i do that?

Edit:

I would try to explain my motivation better

my goal is a picture where you click on the right click on coordinate(x and y ) openes for you a there a menu(menu1) just like you do on windows desktop the menu top left is the coordinate you have clicked and from this coordinate a menu is opened (just like i want to change or open something on the desktop it doesn’t opened in the left top corner of desktop it’s opened where I have clicked ).

when the aaa item is clicked i want another form to be opened and from there with the delegate open new label form1
now when this label is clicked with right click i want another menu to be opened (let’s call it menu2)

menu1 and menu2 are different creatures

I might have missed the main concept?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:18:41+00:00Added an answer on May 18, 2026 at 4:18 am

    You could access the mouse coordinates and calculate that to the point of your picturebox (in this test a panel)?

    You would calculate it on the opening event of the menustrip.

    And MousePosition is a static property on the Control class.

    public partial class Form1 : Form {
    
        private void pnlClickOnMe_MouseClick(object sender, MouseEventArgs e) {
            Point mouseLocation = MousePosition;
            // get point of mouse relative to pnlClickOnMe
            Point pointYouAreInterestedIn = pnlClickOnMe.PointToClient(mouseLocation); 
            lblShowCoordinates.Text = string.Format("{0} - {1}", pointYouAreInterestedIn.X, pointYouAreInterestedIn.Y);
        }
    
        public Form1() {
            InitializeComponent();
        }
    
        #region designer
        private void InitializeComponent() {
            this.lblShowCoordinates = new System.Windows.Forms.Label();
            this.pnlClickOnMe = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            this.lblShowCoordinates.AutoSize = true;
            this.lblShowCoordinates.Location = new System.Drawing.Point(32, 18);
            this.lblShowCoordinates.Size = new System.Drawing.Size(35, 13);
            this.pnlClickOnMe.BackColor = System.Drawing.SystemColors.ActiveCaption;
            this.pnlClickOnMe.Location = new System.Drawing.Point(31, 64);
            this.pnlClickOnMe.Size = new System.Drawing.Size(206, 152);
            this.pnlClickOnMe.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pnlClickOnMe_MouseClick);
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.pnlClickOnMe);
            this.Controls.Add(this.lblShowCoordinates);
            this.ResumeLayout(false);
            this.PerformLayout();
    
        }
    
        #endregion
    
        private System.Windows.Forms.Label lblShowCoordinates;
        private System.Windows.Forms.Panel pnlClickOnMe;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal here is to open temp.php, explode by ### (line terminator), then by
The end goal is for the user to download a .csv file. Right now
I am using the SharpZipLib open source .net library from www.icsharpcode.net My goal is
My goal is to gather input and open files based on that input. FILE*
The goal is to have the user select a java program, then my program
My goal is to collect all unknown phone numbers from the Call Log. This
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My Goal I would like to have a main processing thread (non GUI), and
My goal is to maintain a web file server separately from my main ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.