Hi,
Currently, I am using DontNetMagic library.. Now i want to switch to Telerik WinForms.
My requirement is to add a field (as highlighted in attached image) by inheriting any of CommandBar class in my own class.
The text (20%) will be updated as and when performs any zoom operation.
What is the recommended way to achieve the desired functionality?
Thanks,
Harshal
9 Answers, 1 is accepted
Here is how you can create such item and add it to the command bar:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
commandBarStripElement1.Items.Add(
new
MyZoomItem());
}
}
public
class
MyZoomItem : RadCommandBarBaseItem
{
public
MyZoomItem()
{
this
.DrawBorder =
true
;
this
.DrawText =
true
;
this
.DrawFill =
true
;
this
.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.SingleBorder;
this
.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid;
this
.BorderColor = Color.Black;
this
.Font =
new
Font(
"Segoe UI"
, 11, FontStyle.Bold);
this
.Text =
"20%"
;
this
.BackColor = Color.LightGreen;
this
.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
this
.Padding =
new
Padding(15, 0, 15, 0);
}
}
The attached image shows the result on my side.
I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Telerik by Progress
Thanks Dimitar..
I changed my approach & simply used CommandBarLabel to display my text..
Moving forward, I am facing a new issue; when i click on any on commandbarbutton, it is not shown as selected or is not highlighted...
Can you please suggest for this?
Thanks,
Harshal
Hi,
I am dynamically adding DocumentWindow, & CommandBarButton with respect to windows; But the shortcut key for few CommandBarButton are same in different windows (Control + Shift + I)
Issue here is, the shortcut keys work only for the first screen, and not for the second screen.
Please suggest a workaround for this.
Thanks,
Harshal.
Perhaps the images are covering the entire button and this is why there is no selection. Could you please try this by adding a blank new item and see if there are selection styles?
As to the shortcuts at hand, you can create a global shortcut and manually handle the key press, depending on the active window/control: Assigning Global RadShortcuts.
I hope this will be useful
Regards,
Dimitar
Telerik by Progress
Hi Dimitar,
I tried your suggestion as well as setting MinSize = New Size(50, 10) for commandbarbutton, but no success.
Any other workaround?
On mouse hover the respective button is highlighted, but once click is performed it does not maintain the selection.
Please suggest.
You need to use toggle buttons for this, not regular ones (see attached image).
Let me know how this works for you.
Regards,
Dimitar
Telerik by Progress
Hi Dimitar,
I tried with toggle buttons, but these are not suitable for my requirements.. I just need to highlight the clicked command bar button (refer attached image)
Please suggest.
Thanks,
Harshal
By default, the CommandBarButton does not support focus. What you can do is manually add a focus primitive to it. Here is an example for this:
public
class
MyButton : CommandBarButton
{
FocusPrimitive focusPrimitive;
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
var border =
new
BorderPrimitive();
focusPrimitive =
new
FocusPrimitive(border);
focusPrimitive.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
focusPrimitive.ForeColor = Color.Orange;
this
.Children.Add(focusPrimitive);
focusPrimitive.Visibility = ElementVisibility.Hidden;
}
protected
override
void
OnPropertyChanged(RadPropertyChangedEventArgs e)
{
base
.OnPropertyChanged(e);
if
(e.Property == RadElement.IsFocusedProperty)
{
if
((
bool
)
this
.GetValue(RadElement.IsFocusedProperty))
{
focusPrimitive.Visibility = ElementVisibility.Visible;
}
else
{
focusPrimitive.Visibility = ElementVisibility.Hidden;
}
}
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(CommandBarButton);
}
}
}
I hope this will be useful.
Regards,
Dimitar
Telerik by Progress