Add commandbar class through custom class

10 posts, 0 answers
  1. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 18 Jan Link to this post

    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

  2. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 19 Jan Link to this post

    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.
  3. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 19 Jan in reply to Dimitar Link to this post

    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

  4. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 19 Jan in reply to harshal Link to this post

    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.

  5. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 19 Jan Link to this post

    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.
  6. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 19 Jan in reply to Dimitar Link to this post

    Hi Dimitar,

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

    Any other workaround?

  7. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 19 Jan in reply to harshal Link to this post

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

    Please suggest.

  8. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 19 Jan Link to this post

    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.
  9. harshal
    harshal avatar
    13 posts
    Member since:
    Nov 2016

    Posted 20 Jan in reply to Dimitar Link to this post

    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

  10. Dimitar
    Admin
    Dimitar avatar
    1871 posts

    Posted 20 Jan Link to this post

    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.
Back to Top