Adding a Custom Button to RadWindow Titlebar

10 posts, 0 answers
  1. Brian Bates
    Brian Bates avatar
    3 posts
    Member since:
    Aug 2006

    Posted 17 Aug 2011 Link to this post

    See Article: http://www.telerik.com/support/kb/aspnet-ajax/window/adding-a-custom-button-to-radwindow-titlebar.aspx

    I would like to know how to add a custom print button to RadWindow for WinForms.

    For example how to implement a print button in my window titlebar. Some typical scenarios include implementing help or print button based on this functionality.

    I would like to add buttons to the windows that I am using in a RadDock.  It it possible in WinForms?

  2. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 19 Aug 2011 Link to this post

    Hello Brian,

    Thank you for your question.

    To accomplish your scenario you can add a RadButtonElement to the TitleBar of RadDock control's FloatingWindows. I have attached a sample project for your reference.

    Please write back if you have additional questions.

    Best regards,
    Alexander
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Brian Bates
    Brian Bates avatar
    3 posts
    Member since:
    Aug 2006

    Posted 22 Aug 2011 Link to this post

    Alexander,

    Thank you for your response, and this will work perfectly, but is there a way to keep the button even when the window is docked?
  5. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 25 Aug 2011 Link to this post

    Hello Brian,

    Thank you for writing back.

    I have attached an updated project which adds print buttons to docked ToolWindows. Please let me know if I can assist you further.

    Kind regards,
    Alexander
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. Hesham Desouky
    Hesham Desouky avatar
    27 posts
    Member since:
    Oct 2012

    Posted 13 Nov 2011 Link to this post

    Thanks for the code.

    One more assistance required. How can I position the button element to the left of the auto-hide element
  7. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 16 Nov 2011 Link to this post

    Hello Hesham,

    Thank you for contacting me again.

    The auto-hide elements of RadDock are elements of the RadPageView control which do not allow inserting additional items. This feature request has been added to our PITS and we will implement it in a future release if more customers request it.

    Best regards,
    Alexander
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  8. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 30 Nov 2011 Link to this post

    How would you wire the events up? The code that creates the button is on the parent (dock host), but the button itself is on the child windows. The handler would need to be in the code behind for the child windows (in my case they are user controls), but i dont see how to wire those events up.
  9. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 02 Dec 2011 Link to this post

    Hello John,

    Thank you for writing.

    The buttons in this solution are created at run time and you can add handlers for their events when you create the buttons. In case you need to handle these events outside the form/user control which contains them, you can create custom events and raise them using the buttons event handlers.

    I hope it helps in your scenario.

    Best regards,
    Alexander
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  10. John Crumpton
    John Crumpton avatar
    12 posts
    Member since:
    Jul 2009

    Posted 03 Dec 2011 Link to this post

    I do have it working, but what I did looks a bit (maybe more than a bit) kludgy...

    From your example:
    private void AddButtons(DockWindow window)
          {
              if (window.DockState == DockState.Hidden || window.DockState == DockState.TabbedDocument)
              {
                  return;
              }
     
              DockLayoutPanel panel = ((ToolTabStrip)window.TabStrip).CaptionElement.Children[2] as DockLayoutPanel;
              if (panel.Children.Count < 5)
              {
                  RadButtonElement btnRefresh = new RadButtonElement();
                  btnRefresh.Image = refreshImage;
                  btnRefresh.ToolTipText = "Refresh Data";
                  btnRefresh.Name = "btnRefresh_" + window.Name.ToString();
                  btnRefresh.Click += new EventHandler(RefreshDashlet);
                  panel.Children.Insert(3, btnRefresh);
     
                  RadButtonElement btnGroup = new RadButtonElement();
                  btnGroup.Image = toolImage;
                  btnGroup.Name = "btnGroup_" + window.Name.ToString();
                  btnGroup.Click += new EventHandler(ShowConfig);
                  btnGroup.ToolTipText = "Select Group";
                  panel.Children.Insert(3, btnGroup);
              }
          }

    in the form which contains the Rad Dock control:
    public void ShowConfig(object sender, EventArgs e)
       {
           try
           {
               RadButtonElement btnGroup = (RadButtonElement)sender;
               string dl = btnGroup.Name.Split('_')[2];
               foreach (HostWindow window in this.DockHost.DockWindows)
               {
                   string cname = window.Name.Split('_')[0];
                   string g = window.Name.Split('_')[1];
                   if (g == dl)
                   {
                       switch (cname)
                       {
                           case "NewOpportunities":
                               Dashlets.NewOpportunities dash = (Dashlets.NewOpportunities)window.Content;
                               dash.ShowConfig();
                               return;
                       }
     
                   }
               }
           }
           catch (Exception ex)
           { }
       }

    .ShowConfig is a public method of the user control hosted in the dock window.
    I'm not really happy with this, but it does work.
    I don't see how I can directly wire the event since the new EventHandler method expects me to pass a method that exists on the same form... not in the user control that doesn't exist until runtime
    btnRefresh.Click += new EventHandler(RefreshDashlet);
  11. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 07 Dec 2011 Link to this post

    Hello John,

    Thank you for sharing your solution. A second approach to handle the buttons click event in your form is to create an event in the user control:
    public delegate void ButtonClickedEventHandler(object sender, ButtonClickedEventArgs e);
    public event ButtonClickedEventHandler ButtonClicked;
     
    public class ButtonClickedEventArgs : EventArgs
    {
        public readonly RadButtonElement Button;
     
        public ButtonClickedEventArgs(RadButtonElement button)
        {
            this.Button = button;
        }
    }

    The event arguments in the above snippet are just an example. You can include in them any useful in your case data.

    Then you can raise this event when a button is clicked:
    DockLayoutPanel panel = ((ToolTabStrip)window.TabStrip).CaptionElement.Children[2] as DockLayoutPanel;
    if (panel.Children.Count < 5)
    {
        RadButtonElement radButtonElement = new RadButtonElement();
        radButtonElement.Click += new EventHandler(radButtonElement_Click);
        radButtonElement.Text = "Print";
        panel.Children.Insert(3, radButtonElement);
    }
     
    //...
     
    private void radButtonElement_Click(object sender, EventArgs e)
    {
        if (this.ButtonClicked != null)
        {
            this.ButtonClicked(this, new ButtonClickedEventArgs((RadButtonElement)sender));
        }
    }

    And you can add a handler to this user control event in your form.

    Honestly, I am not sure if this approach is more convenient for your case than the one you described. Basically, these two approaches seem to be the most practical for this solution.

    Best regards,
    Alexander
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Back to Top
UI for WinForms is Visual Studio 2017 Ready