RadButtonElement subclass doesn't have correct style

2 posts, 1 answers
  1. Michael
    Michael avatar
    33 posts
    Member since:
    Mar 2009

    Posted 09 Apr 2009 Link to this post

    If I subclass RadButtonElement, the subclass no longer has the same style applied as a pure RadButtonElement.  Here's the simple code snippet:

                ... 
                panel.Children.Add(new RadButtonElement() { Text = "RadButtonElement" }); 
                panel.Children.Add(new MyRadButtonElement() { Text = "MyRadButtonElement" }); 
            } 
     
            class MyRadButtonElement : RadButtonElement 
            { 
            } 
     
     

    Can you tell me how to make my RadButtonElement have the same default style (e.g. background color, mouse rollover) as a regular RadButtonElement?

    Thanks,
    Michael Hewitt
    Precision Software Design, LLC

    For reference, here is the full body of my Form.OnLoad function:

            void Form1_Load(object sender, EventArgs e) 
            { 
                // Create element container to fill form 
                RadPanel elementsContainer = new RadPanel(); 
                this.Controls.Add(elementsContainer); 
                elementsContainer.Dock = DockStyle.Fill; 
                elementsContainer.BeginInit(); 
                elementsContainer.EndInit(); 
     
                // Create scroll viewer for scrollbar support 
                RadScrollViewer scrollViewer = new RadScrollViewer(); 
                elementsContainer.PanelElement.Children.Add(scrollViewer); 
     
                // Create panel to stack buttons 
                StackLayoutPanel panel = new StackLayoutPanel(); 
                scrollViewer.Viewport = panel; 
                panel.Orientation = Orientation.Vertical; 
                panel.Children.Add(new RadButtonElement() { Text = "RadButtonElement" }); 
                panel.Children.Add(new MyRadButtonElement() { Text = "MyRadButtonElement" }); 
            } 
     
            class MyRadButtonElement : RadButtonElement 
            { 
            } 
     
     

  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 10 Apr 2009 Link to this post

    Hello Michael,

    Thank you for the question.

    When you make a class which descends from a RadButtonElement class, you should override the ThemeEffectiveType and return the type of the parent class. This will allow you to use the theming mechanism for your class:
    public class MyRadButtonElement : RadButtonElement  
    {  
        protected override Type ThemeEffectiveType  
        {  
            get 
            {  
                return typeof(RadButtonElement);  
            }  
        }  
    }   

    If you have additional questions, feel free to contact me.

    All the best,
    Nikolay
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top