I want to position three buttons at the left edge of the main RadMenu of a form. These buttons need to be created, added, and removed from the menu programmatically, via C#. Looking through this forum I found a thread advising that I manually position the buttons, and attempted that - but the RadMenu's Size field seems to be holding an incorrect value, which is quite a bit too wide and results in the buttons ending up far off the right of the form and thus not visible. I know of no other way to get the menu width. Is there something else I need to do, or some other method I could try to make this work? I am using version 2011.3.11.1116. Thanks.
12 Answers, 1 is accepted
0
Bill
Top achievements
Rank 1
answered on 06 Dec 2011, 09:07 PM
Correction to my opening post: as indicated by the thread title, I want my three buttons on the *right* edge of the main menu. (They're going to replicate the standard minimize/maximize/close buttons for a maximized form, a measure that's necessary because we need to simulate having maximized and non-maximized forms open simultaneously, and normal maximization of an MDI form maximizes all the other MDI forms as well.)
0
Hello Bill,
Thank you for writing.
In your case, you can set the RightToLeft property of the RadMenu control. However, this property is inherited by the child elements, so you should set the RightToLeft property of your items to false. The following code snippet demonstrates this:
I hope you find this useful. If you have any further questions, feel free to ask.
Kind regards,
Ivan Todorov
the Telerik team
Thank you for writing.
In your case, you can set the RightToLeft property of the RadMenu control. However, this property is inherited by the child elements, so you should set the RightToLeft property of your items to false. The following code snippet demonstrates this:
this
.radMenu1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this
.radMenuItem1.RightToLeft =
false
;
this
.radMenuItem2.RightToLeft =
false
;
this
.radMenuItem3.RightToLeft =
false
;
I hope you find this useful. If you have any further questions, feel free to ask.
Kind regards,
Ivan Todorov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Bill
Top achievements
Rank 1
answered on 08 Dec 2011, 05:27 PM
I may have been unclear - I have several other items and submenus in this menu other than the three buttons, and they should remain left-aligned while the three buttons are right-aligned. For an example of what I am trying to accomplish, open up an MDI application such as Word or Excel, make sure there's a child window open and maximized and check out the right edge of the menu; it will have one or more buttons there allowing the user to close and possibly minimize or restore the child form, and of course the rest of the menu is left-aligned. That's what I want.
0
Hi Bill,
Thank you for clarifying this.
RadMenu has built-in minimize/maximize/close buttons which are automatically displayed when RadMenu is placed on an MDI container form. They stay right-aligned and behave just as you described. The following code snippet demonstrates how you can subscribe to their click event and add some custom logic:
If your RadMenu is not placed on an MDI container, then you can hide these buttons and use their container to insert your custom ones. This is demonstrated in the following code snippet:
I hope this will help you. Do not hesitate to write back if you need further assistance.
Greetings,
Ivan Todorov
the Telerik team
Thank you for clarifying this.
RadMenu has built-in minimize/maximize/close buttons which are automatically displayed when RadMenu is placed on an MDI container form. They stay right-aligned and behave just as you described. The following code snippet demonstrates how you can subscribe to their click event and add some custom logic:
this
.radMenu1.MenuElement.MinimizeButton.Click +=
new
EventHandler(MinimizeButton_Click);
this
.radMenu1.MenuElement.MaximizeButton.Click +=
new
EventHandler(MaximizeButton_Click);
this
.radMenu1.MenuElement.CloseButton.Click +=
new
EventHandler(CloseButton_Click);
If your RadMenu is not placed on an MDI container, then you can hide these buttons and use their container to insert your custom ones. This is demonstrated in the following code snippet:
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
foreach
(RadElement element
in
this
.radMenu1.MenuElement.SystemButtons.Children)
{
element.Visibility = ElementVisibility.Collapsed;
}
this
.radMenu1.MenuElement.SystemButtons.Visibility = ElementVisibility.Visible;
RadButtonElement button1 =
new
RadButtonElement();
button1.Text =
"Button 1"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button1);
RadButtonElement button2 =
new
RadButtonElement();
button2.Text =
"Button 2"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button2);
RadButtonElement button3 =
new
RadButtonElement();
button3.Text =
"Button 3"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button3);
}
}
I hope this will help you. Do not hesitate to write back if you need further assistance.
Greetings,
Ivan Todorov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Bill
Top achievements
Rank 1
answered on 12 Dec 2011, 07:53 PM
Those are exaclty the buttons I want, but I'm running into a bit of a problem - my menu is in fact placed on an MDI container, but I don't want the visibility of the buttons to be syncronized with the state of the MDI container's children. The SystemButtons menu element is currently closely tied to the state of the MDI children: if I open a child form in normal mode, the buttons disappear - both the original buttons and any others I add. This is undesireable to me; I want to control the buttons' visibility myself, having them appear or disappear at my discretion despite adding MDI children and none of them ever being maximized.
So, is there any way to decouple the SystemButtons menu from whatever is telling it to hide itself, or to intercept and prevent the visibility change? Or possibly replace it with some other panel that follows the same positioning rules that doesn't hide itself? Or, all else failing, I still could go back to manually positioning the buttons myself based on the menu size - assuming that I can get a correct Size valie for the RadMenu, that is.
Any thoughts?
So, is there any way to decouple the SystemButtons menu from whatever is telling it to hide itself, or to intercept and prevent the visibility change? Or possibly replace it with some other panel that follows the same positioning rules that doesn't hide itself? Or, all else failing, I still could go back to manually positioning the buttons myself based on the menu size - assuming that I can get a correct Size valie for the RadMenu, that is.
Any thoughts?
0
Hi Bill,
In your case, you can prevent changes to the Visibility property of the buttons' panel by using the following code:
I hope this will help you. Feel free to ask if you have any additional questions.
Regards,
Ivan Todorov
the Telerik team
In your case, you can prevent changes to the Visibility property of the buttons' panel by using the following code:
this
.radMenu1.MenuElement.SystemButtons.Visibility = ElementVisibility.Visible;
this
.radMenu1.MenuElement.SystemButtons.RadPropertyChanging +=
new
RadPropertyChangingEventHandler(SystemButtons_RadPropertyChanging);
void
SystemButtons_RadPropertyChanging(
object
sender, RadPropertyChangingEventArgs args)
{
if
(args.Property == RadElement.VisibilityProperty && Object.Equals(args.NewValue, ElementVisibility.Visible))
{
args.Cancel =
true
;
}
}
I hope this will help you. Feel free to ask if you have any additional questions.
Regards,
Ivan Todorov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Bill
Top achievements
Rank 1
answered on 16 Dec 2011, 12:53 AM
Unfortunately this did not correct my problem because under various circumstances (which may be related to changes in focus) the ControlButtons panel disappears without triggering the RadPropertyChanging event. I'm not even certain its Visibility is even changing; it's alternatively possible that the panel is vanishing due to being covered by another one - possibly the one that holds the items added to the menu's Items list, which appears to be positioned to cover the button area and beyond. Regardless, I continue to look for a solution.
0
Hi Bill,
Here is another approach of persisting the visibility of the buttons panel:
I have spent some time testing this approach and it appears to be working correctly in all cases.
Let me know if it work for you.
Best wishes,
Ivan Todorov
the Telerik team
Here is another approach of persisting the visibility of the buttons panel:
this
.radMenu1.MenuElement.SystemButtons.RadPropertyChanged +=
new
RadPropertyChangedEventHandler(SystemButtons_RadPropertyChanged);
void
SystemButtons_RadPropertyChanged(
object
sender, RadPropertyChangedEventArgs e)
{
if
(e.Property == RadElement.VisibilityProperty && !Object.Equals(e.NewValue, ElementVisibility.Visible))
{
this
.radMenu1.MenuElement.SystemButtons.Visibility = ElementVisibility.Visible;
}
}
I have spent some time testing this approach and it appears to be working correctly in all cases.
Let me know if it work for you.
Best wishes,
Ivan Todorov
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Bill
Top achievements
Rank 1
answered on 09 Jan 2012, 11:35 PM
I'm back, and this fix works. Thanks!
0
Bill
Top achievements
Rank 1
answered on 10 Jan 2012, 12:42 AM
Me again - on a separate but somewhat related subject, in an ideal world the buttons I show in the toolbar would look exactly like the ones that would show there if I used the normal maximization system, using the style employed in the rest of the application and all that. I see two possible avenues to this end:
1) access whatever image source or methods are used to apply the active style to those buttons, with the correct parameters to get the correct sizes and images for each button.
2) Actually use the existing buttons, removing the existing event handlers and replacing them with my own.
Approach 2 would obviously be easiest but so far I've had no luck removing the handler, and merely replicating the appearance of the button would be a perfect solution too. Do you have any suggestions about how to go about doing either?
1) access whatever image source or methods are used to apply the active style to those buttons, with the correct parameters to get the correct sizes and images for each button.
2) Actually use the existing buttons, removing the existing event handlers and replacing them with my own.
Approach 2 would obviously be easiest but so far I've had no luck removing the handler, and merely replicating the appearance of the button would be a perfect solution too. Do you have any suggestions about how to go about doing either?
0
Hi Bill,
I do not think it would be possible to remove the handlers of the built-in buttons because the C# language would not allow this. The best approach to this case would be to tell the styling system to apply the same styles to your buttons. To do this, they need to be of the same type as the built-in ones (e.g. RadImageButtonElement) and they need to have the Class property set as follows:
I hope this will help you. In case you have any further questions, do not hesitate to ask.
Regards,
Ivan Todorov
the Telerik team
I do not think it would be possible to remove the handlers of the built-in buttons because the C# language would not allow this. The best approach to this case would be to tell the styling system to apply the same styles to your buttons. To do this, they need to be of the same type as the built-in ones (e.g. RadImageButtonElement) and they need to have the Class property set as follows:
public
Form1()
{
InitializeComponent();
foreach
(RadElement element
in
this
.radMenu1.MenuElement.SystemButtons.Children)
{
element.Visibility = ElementVisibility.Collapsed;
}
RadImageButtonElement button1 =
new
RadImageButtonElement();
button1.Class =
"MinimizeButton"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button1);
RadImageButtonElement button2 =
new
RadImageButtonElement();
button2.Class =
"MaximizeButton"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button2);
RadImageButtonElement button3 =
new
RadImageButtonElement();
button3.Class =
"CloseButton"
;
this
.radMenu1.MenuElement.SystemButtons.Children.Add(button3);
}
I hope this will help you. In case you have any further questions, do not hesitate to ask.
Regards,
Ivan Todorov
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
0
Bill
Top achievements
Rank 1
answered on 12 Jan 2012, 10:56 PM
That worked perfectly; thank you very much! I think we can consider this topic resolved.