This is a migrated thread and some comments may be shown as answers.

Assigning ContextMenu to RadButtonElement

7 Answers 118 Views
Panelbar (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jaroslav Bucek
Top achievements
Rank 1
Jaroslav Bucek asked on 18 Aug 2008, 01:11 PM
Hi,

I am using RadPanelBar with RadButtonElement controls on it. I whould like to assign a context menu to every single RadButtonElement but I have some problems regarding this.

1. RadButtonElement dos not contain ContextMenu property, so I cannot assign the menu to it.

2. When I right click on RadButtonElement, it fires a click event, what I do not want. Is it possible to disable such a behavior?

TIA
Jaroslav

7 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 18 Aug 2008, 02:56 PM
Hi Jaroslav Bucek,

Thank you for this question.

In this case, you could use a descendant class of RadButtonElement that processes the OnMouseDown event. Consider the following code snippet:

public class MyButton : RadToggleButtonElement 
    protected override void OnMouseDown(MouseEventArgs e) 
    { 
        if (e.Button == MouseButtons.Right) 
        { 
            RadContextMenu menu = new RadContextMenu(); 
            menu.Items.Add(new RadMenuItem("Item 1")); 
            menu.Items.Add(new RadMenuItem("Item 2")); 
            menu.Items.Add(new RadMenuItem("Item 3")); 
            menu.Show(Control.MousePosition); 
        } 
        else 
        { 
            base.OnMouseDown(e); 
        }            
    }    
  
    protected override Type ThemeEffectiveType 
    { 
        get { return typeof(RadToggleButtonElement); } 
    } 

I hope this helps. Do not hesitate to contact us if you have further questions.

Kind regards,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jaroslav Bucek
Top achievements
Rank 1
answered on 19 Aug 2008, 07:43 AM
Interesting idea. I would prefer not to create as many context menus as buttons. When I will create about 50 buttons, it seems very inefficient to me to create 50 context menus, moreover when all should has same items.

Second problem I see is, that I should create menu items inside of button descendant class. I could create some kind of event (OnContextMenuBind or whatever) but it doesn't look clear to me.

The question is: could you begin support context menu at least with RadButtonElement?

The second question becomes from your example: How can I determine the button that was the source control of context menu pop up? (e.g. class ContextMenuStrip has property SourceControl). I could put the button into Tag property, but is it really the best and the one way to do it?

Thanks in advance,
Jaroslav Bucek
0
Accepted
Jack
Telerik team
answered on 20 Aug 2008, 07:07 AM
Hi Jaroslav Bucek,

Thank you for getting back to me.

You could add a property of type RadContextMenu in the descendant class and set all buttons to point to one context menu.

As an alternative solution, you could process the OnMouseDown method of the RadPanelBar and check the coordinates to find the correct button. This can be done by using the GetElementAtPoint method. Consider the code below:

RadElement element = mycontrol.ElementTree.GetElementAtPoint(e.Location); 
if (element is RadToggleButtonElement) 
 


We will consider adding support for context menus in RadButtonElement in one of our upcoming releases.

Currently there is no SourceControl property in RadContextMenu. This is a good feature and I will log it in our feature requests. I agree, that using the Tag property is not the best way but it is a working option.

I hope this helps. Do not hesitate to write me if you have other questions.

Best wishes,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jaroslav Bucek
Top achievements
Rank 1
answered on 20 Aug 2008, 08:47 AM
Hi Jack,

thank you for your time. I did it as you mentioned already ;-)

Anyhow, I recommend you - Telerik - to consider if it is good idea to fire a Click event with right mouse button. Such a behavior is unexpected in classic controls. Or you should change the delegate of the Click event and pass MouseEventArgs instead EventArgs parameter.

Regards,
Jaroslav
0
Jack
Telerik team
answered on 21 Aug 2008, 09:38 AM
Hi Jaroslav,

I am glad to see you have resolved this issue. We appreciate your feedback and will consider these suggestions for implementation in our upcoming releases.

Please let me know if you have further questions.

Greetings,
Jack
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mohammed
Top achievements
Rank 1
answered on 13 Apr 2009, 04:54 AM

sorry for disturbing in ur thread .........i want a solution for this problem its urgent.....


RadButtonElement

carouselItem = new RadButtonElement();

.....
....
.....


 

 

this.radCarousel2.Items.Add(carouselItem);


HOW TO WRITE CLICK EVENT in this carouselitem that has been generated programatically......

thx and regards,
Muzzammil

 

0
Deyan
Telerik team
answered on 14 Apr 2009, 04:25 PM
Hi Mohammed,

I am not quite sure that I correctly understand your goal.

However, if you want to provide a handler for the Click event of the RadButtonElement object, you could use the following code snippet:

RadButtonElement element = new RadButtonElement(); 
 
element.Click += new EventHandler(OnRadButtonElement_Click); 
 
 
... 
... 
 
private void OnRadButtonElement_Click(object sender, EventArgs args) 
 
 
I hope this will help.

Greetings,
Deyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Panelbar (obsolete as of Q2 2010)
Asked by
Jaroslav Bucek
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jaroslav Bucek
Top achievements
Rank 1
Mohammed
Top achievements
Rank 1
Deyan
Telerik team
Share this question
or