Overriding Events

4 posts, 0 answers
  1. Kenneth Jackson
    Kenneth Jackson avatar
    60 posts
    Member since:
    Dec 2007

    Posted 04 Aug 2008 Link to this post

    I wish to implement custom behavior on a form with a ribbon bar when the
    form is minimised.

    It's easy enough to trap the events of the minimise , maximise and close buttons -
    However , I am unable to replace these events with those of my own .
    In other words I want to be able to implement behavior to the minimise
    buttons' click event and stop the minimise button from doing anything else
    by default.

    I initially looked at the routedeventbehavior class and related classes but cannot
    find any code examples on how to use these correctly.
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 05 Aug 2008 Link to this post

    Hello Kenneth Jackson,

    Thank you for contacting me.

    I am not sure if I understand the details of your scenario. Still, you could implement your custom code when the form is minimized using Form.SizeChanged event:
    void Form1_SizeChanged(object sender, EventArgs e) 
        if (this.WindowState == FormWindowState.Minimized) 
        { 
            //Your custom code        
        } 

    You cannot cancel minimizing the form when the minimize button is clicked. You could only hide the button element and in this way prevent the user to minimize the form:
    (this.radRibbonBar1.RibbonBarElement.Children[0].Children[1].Children[1].Children[0].Children[0] as RadButtonElement).Visibility = Telerik.WinControls.ElementVisibility.Hidden; 

    If you have other questions, do not hesitate to contact me again.

    Best wishes,
    Martin Vasilev
    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
  4. Kenneth Jackson
    Kenneth Jackson avatar
    60 posts
    Member since:
    Dec 2007

    Posted 05 Aug 2008 Link to this post

    Thanks for your response,
    stopping the minimise event from happening is exactly what I wanted to do while being notified that the user had clicked the minimise button.

    For the purpose of other ribbonbar users who may want to do the same,
    what I did do is - I created a RadButtonElement called oMinimiseButton(declared withevents) and in the form_load event I set its Image property to the image property of the minimise button on the ribbonbar.

    I then removed the minimise button of the ribbonbar and added oMinimiseButton to the same collection. This worked perfectly and I'm
    able to trap the minimise buttons' click event and override the "minimise behavior" completely.

    Ofc you can do the same for the close and max buttons should you want to override the behaviors there also.

  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 06 Aug 2008 Link to this post

    Hi Kenneth,

    Thank you for sharing your approach with us. I am glad to see that you have found a solution that suits your scenario.

    If you need additional assistance, do not hesitate  to contact me again.

    Best wishes,
    Martin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top