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

Add commandbar class through custom class

9 Answers 174 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
harshal
Top achievements
Rank 1
harshal asked on 18 Jan 2017, 12:39 PM

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

Sort by
0
Dimitar
Telerik team
answered on 19 Jan 2017, 08:44 AM
Hello Harshal,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
harshal
Top achievements
Rank 1
answered on 19 Jan 2017, 09:56 AM

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

0
harshal
Top achievements
Rank 1
answered on 19 Jan 2017, 11:20 AM

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.

0
Dimitar
Telerik team
answered on 19 Jan 2017, 11:44 AM
Hi 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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
harshal
Top achievements
Rank 1
answered on 19 Jan 2017, 11:56 AM

Hi Dimitar,

I tried your suggestion as well as setting MinSize = New Size(50, 10) for commandbarbutton, but no success.

Any other workaround?

0
harshal
Top achievements
Rank 1
answered on 19 Jan 2017, 11:59 AM

On mouse hover the respective button is highlighted, but once click is performed it does not maintain the selection.

Please suggest.

0
Dimitar
Telerik team
answered on 19 Jan 2017, 02:08 PM
Hello Harshal,

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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
harshal
Top achievements
Rank 1
answered on 20 Jan 2017, 07:41 AM

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

0
Dimitar
Telerik team
answered on 20 Jan 2017, 01:38 PM
Hi 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
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
CommandBar
Asked by
harshal
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
harshal
Top achievements
Rank 1
Share this question
or