Brian Bates
                                            
                                    
    Top achievements
    
            
                
                Rank 1
            
    
                                        
                                        Brian Bates
                                        asked on 17 Aug 2011, 04:00 PM
                                    
                                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?
                                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?
9 Answers, 1 is accepted
0
                                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
                                        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 >>
0
                                
                                                    Brian Bates
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 22 Aug 2011, 01:05 PM
                                            
                                        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?
                                        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?
0
                                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 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 >>
0
                                
                                                    Hesham Desouky
                                                    
                                            
    Top achievements
    
            
                
                Rank 2
            
    
                                                
                                                answered on 13 Nov 2011, 05:09 PM
                                            
                                        Thanks for the code.
One more assistance required. How can I position the button element to the left of the auto-hide element
                                        One more assistance required. How can I position the button element to the left of the auto-hide element
0
                                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
                                        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.
0
                                
                                                    John Crumpton
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 30 Nov 2011, 06:44 PM
                                            
                                        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.
                                        0
                                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
                                        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.
0
                                
                                                    John Crumpton
                                                    
                                            
    Top achievements
    
            
                
                Rank 1
            
    
                                                
                                                answered on 03 Dec 2011, 11:55 AM
                                            
                                        I do have it working, but what I did looks a bit (maybe more than a bit) kludgy...
From your example:
 
 
in the form which contains the Rad Dock control:
 
.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
                                        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);0
                                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:
 
 
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:
 
 
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
                                        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.