473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Filmstrip control, adding a contextual menu to items

I have a filmstrip control on my windows C# app. It's populated with images. Is there anyway to add a right-click contextual menu to each image? I want the user to have the ability to right click and have some options (like open image in a graphics application).

Thanks for any help.
Feb 3 '09 #1
7 2847
vekipeki
229 Expert 100+
You can handle the Control.MouseUp event to display the menu:

Expand|Select|Wrap|Line Numbers
  1. private void yourControl_MouseUp
  2.     (object sender, MouseEventArgs e)
  3. {
  4.     if (e.Button == MouseButtons.Right)
  5.     {
  6.         System.Windows.Forms.ContextMenuStrip contextMenu = new ContextMenuStrip();
  7.         contextMenu.Items.Add("some menu item");
  8.         contextMenu.Show(sender as Control, e.X, e.Y);
  9.     }
  10. }
Feb 3 '09 #2
Ok, my control is named filmStrip2.

So here is what I did:

Expand|Select|Wrap|Line Numbers
  1. private void filmStrip2_MouseUp(object sender, MouseEventArgs e)
  2.         {
  3.             if (e.Button == MouseButtons.Right)
  4.             {
  5.                 System.Windows.Forms.ContextMenuStrip contextMenu = new ContextMenuStrip();
  6.                 contextMenu.Items.Add("some menu item");
  7.                 contextMenu.Show(sender as Control, e.X, e.Y);
  8.             }
  9.         }

And then in Form1.Designer.cs I put:
Expand|Select|Wrap|Line Numbers
  1. this.filmStrip2.MouseUp += new System.Windows.Forms.MouseEventHandler(filmStrip2_MouseUp);
Does this look correct? Because I couldn't get this to work.
Feb 3 '09 #3
I also tried this:

Expand|Select|Wrap|Line Numbers
  1. private void filmStrip2_OnImageClicked(object sender, EventArgs e)
  2. {
  3.     MouseEventArgs f = (MouseEventArgs)e;
  4.     if (f.Button == MouseButtons.Right)
  5.     {
  6.         System.Windows.Forms.ContextMenuStrip contextMenu = new ContextMenuStrip();
  7.         contextMenu.Items.Add("some menu item");
  8.         contextMenu.Show(sender as Control, f.X, f.Y);
  9.     }
  10. }
Of course in Form1.Designer.cs I have: this.filmStrip2.OnImageClicked += new System.EventHandler(this.filmStrip2_OnImageClicked );

But I get an exception saying that sender is null. It's weird because I can right click and display a message box containing sender.ToString and it displays correct information.
Feb 3 '09 #4
Plater
7,872 Expert 4TB
In your last example I think sender would be an instance of Image, which is not a Control, so that "sender as Control" line would send a "null" parameter
Feb 3 '09 #5
Ok, I figured it out. In case anyone searches for this problem, this is what I did:

Expand|Select|Wrap|Line Numbers
  1. private void filmStrip2_OnImageClicked(object sender, EventArgs e)
  2. {
  3.     MouseEventArgs f = (MouseEventArgs)e;
  4.     if (f.Button == MouseButtons.Right)
  5.     {
  6.         string controlIndex = sender.ToString().Substring(sender.ToString().Length-1,1);                
  7.         System.Windows.Forms.ContextMenuStrip contextMenu = new ContextMenuStrip();
  8.         contextMenu.Items.Add("some menu item");
  9.         try
  10.         {
  11.             contextMenu.Show(filmStrip2.Controls[0].Controls[Convert.ToInt32(controlIndex) * 2], f.X, f.Y);
  12.         }
  13.         catch { }
  14.     }
  15. }
Please let me know if I am doing anything inefficient. Thanks for your help vekipeki and plater.
Feb 3 '09 #6
vekipeki
229 Expert 100+
Well, the thing that looks a bit suspicious to me is getting the index from sender.ToString(). You are presuming that your sender.ToString() will return something like "Image#", where # is the index in Controls collection?

Are you sure that you index always has only 1 digit? (Sorry if I am writing nonsense, I haven't used this control before)
Feb 4 '09 #7
I have it programmed so that the image will always be product-#. But you're right about the # being 1 digit... that was dumb.

This should work: string controlIndex = sender.ToString().Split('-')[1];

Thanks a lot for the insight!
Feb 4 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dennis M. Marks | last post by:
Has anyone ever considered making a simulated contextual menu. I know that you can sometimes trap a right click or option click. Why not open up a window that would act as a menu when this happens?...
10
by: tmaster | last post by:
When I try to dynamically add a second sub menu item to this ContextMenu item, I get an error 'Specified argument was out of the range of valid values'. Private Sub mnuTopics_Show_Select(ByVal...
2
by: Jerry H. | last post by:
Windows Explorer in XP has some handy image browsing features that I'd like to incorporate into my own app. I'm referring to the "View" menu option that let's you selecte between Filmstrip,...
11
by: -D- | last post by:
How can I turn the visibility of the xml control on or off? <%@ Control Language="c#" AutoEventWireup="false" Codebehind="TopNavBar.ascx.cs" Inherits="compass.user_controls.TopNavBar"...
1
by: stinehelferw | last post by:
I need a right-click menu on a form list control with combobox controls. I used View->Toolbars->Customize to create a toolbar. I added ComboBox through commands tab. I set properties to Popup...
3
by: poolieweb | last post by:
I have created a custom user control which creates a ASPxMenu ( Same fucntion as standard menu control) from data retreved from a webservice (Reporting Services) which deals with user access. This...
2
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more...
0
by: Christian | last post by:
Hi all, i already posted this in dotnet.vb.controls but i need some help, so i cant wait... I have written a web control library and have some problems with it. The Library contains only two...
4
by: stuckagain | last post by:
Hi, I have a page with a scrollable DIV, and within that DIV, I have a few asp.net menu controls. The idea being, the user mouses over the small icons and is presented with a list of options. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.