Context(PopUp) Menu in Windows cursor position

F

Frank Uray

Hi all

How can I display a Menu in windows within a
C# application without any form.
It has to be shown on the current windows cursor position.

Thanks for any help.

Regards
Frank
 
F

Family Tree Mike

Frank Uray said:
Hi all

How can I display a Menu in windows within a
C# application without any form.
It has to be shown on the current windows cursor position.

Thanks for any help.

Regards
Frank


Loosely based on the msdn doc for ContextMenus:

public partial class Form1 : Form
{
private ContextMenu cm = new ContextMenu();

public Form1()
{
InitializeComponent();
this.ContextMenu = cm;
cm.Popup +=new EventHandler(MyPopupEventHandler);
}

private void MyPopupEventHandler(System.Object sender,
System.EventArgs e)
{
// Define the MenuItem objects to display for the TextBox.
MenuItem menuItem1 = new MenuItem("&Copy");
MenuItem menuItem2 = new MenuItem("&Find and Replace");
// Define the MenuItem object to display for the PictureBox.
MenuItem menuItem3 = new MenuItem("C&hange Picture");

// Clear all previously added MenuItems.
cm.MenuItems.Clear();
cm.MenuItems.Add(menuItem1);
cm.MenuItems.Add(menuItem2);
cm.MenuItems.Add(menuItem3);
}
 
F

Family Tree Mike

Family Tree Mike said:
Loosely based on the msdn doc for ContextMenus:

public partial class Form1 : Form
{
private ContextMenu cm = new ContextMenu();

public Form1()
{
InitializeComponent();
this.ContextMenu = cm;
cm.Popup +=new EventHandler(MyPopupEventHandler);
}

private void MyPopupEventHandler(System.Object sender,
System.EventArgs e)
{
// Define the MenuItem objects to display for the TextBox.
MenuItem menuItem1 = new MenuItem("&Copy");
MenuItem menuItem2 = new MenuItem("&Find and Replace");
// Define the MenuItem object to display for the PictureBox.
MenuItem menuItem3 = new MenuItem("C&hange Picture");

// Clear all previously added MenuItems.
cm.MenuItems.Clear();
cm.MenuItems.Add(menuItem1);
cm.MenuItems.Add(menuItem2);
cm.MenuItems.Add(menuItem3);
}


Sorry, I misread what you needed. Are you asking how to add a menu item to
windows explorer context menu, such as when you click on the desktop?
 
F

Frank Uray

Hi Mike

Thank you for you effort.

I just wanted to display a Menu on the current cursor position.

I have found out, it is quite simple:
this.contextMenuStrip1.Show(200, 200);

Thanks anyway

Frank

P.S. By the way:
Do you know how to programmaticly paste
the clipboard, also at the current cursor position ?
 
F

Family Tree Mike

Frank Uray said:
Hi Mike

Thank you for you effort.

I just wanted to display a Menu on the current cursor position.

I have found out, it is quite simple:
this.contextMenuStrip1.Show(200, 200);

Thanks anyway

Frank

P.S. By the way:
Do you know how to programmaticly paste
the clipboard, also at the current cursor position ?


You can get the data by using System.Windows.Forms.Clipboard. Normally
though, pasting is enabled to controls. In other words, it should "just
work".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top