Icon for docked window

19 posts, 1 answers
  1. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 14 Feb 2011 Link to this post

    I might be missing something obvious here, but how can I display a form's icon on the left side of the title bar when the form is contained within a DockWindow?  The icon only seems to show when the form is displayed as a normal window.
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 14 Feb 2011 Link to this post

    Hello Robert,

    I presume that you are using RadDock to display MDI Child windows with AutoDetect MDI Children set to true. Is that right?
    If so, then this is how to display the form's icon in the tab

    this.radDock1.DockWindowAdded += new Telerik.WinControls.UI.Docking.DockWindowEventHandler(this.radDock1_DockWindowAdded);
    private void radDock1_DockWindowAdded(object sender, DockWindowEventArgs e)
    {
        RadForm form = ((RadForm)radDock1.ActiveWindow.ActiveControl);
        Image img = new Bitmap(form.Icon.ToBitmap(), new Size(16, 16));
        e.DockWindow.TabStripItem.Image = img;
    }

    Hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 14 Feb 2011 Link to this post

    I'm not using MDI; I'm just opening each form and docking it using radDock1.DockControl(form, DockPosition).  I had already tried setting the TabStripItem.Image property of the HostWindow returned from DockControl(), but it seems to have no effect.
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 15 Feb 2011 Link to this post

    Hi Robert,
    Ok, so you are manually adding a ToolWindow. I will see if I can find a way to do that for you and let you know as soon as I can
    Richard
  6. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 17 Feb 2011 Link to this post

    Hello Robert,

    Setting an image to the TabStripItem only works when you are adding your control to a tabbed document, for example:
    Form window = new Form1();
    HostWindow hostWindow = radDock1.DockControl(window, Telerik.WinControls.UI.Docking.DockPosition.Left);
    radDock1.AddDocument(hostWindow);
    hostWindow.TabStripItem.Image = new Bitmap(window.Icon.ToBitmap(), new Size(16, 16));

    If you are not using tabbed document, it is a bit harder to add image since the tool window does not have a built-in image. Here is how it should be done:
    Form window = new Form1();
    HostWindow hostWindow = radDock1.DockControl(window, Telerik.WinControls.UI.Docking.DockPosition.Left);
    ImagePrimitive primitive = new ImagePrimitive();
    primitive.Image = new Bitmap(window.Icon.ToBitmap(), new Size(16, 16));
    primitive.SetValue(DockLayoutPanel.DockProperty, Telerik.WinControls.Layouts.Dock.Left);
    (hostWindow.DockTabStrip as ToolTabStrip).CaptionElement.Children[2].Children.Insert(0, primitive);

    I hope this will help you. Do not hesitate to ask if you have any further questions.

    All the best,
    Ivan Todorov
    the Telerik team
  7. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 21 Feb 2011 Link to this post

    This worked well, thank you. The only problems I'm having now are:

    1) The icon disappears when I re-dock the window in a different location.

    2) There is no icon when I undock the window and make it floating, but the icon reappears when I dock the window again.


    Can you help me out again?
  8. Answer
    Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 24 Feb 2011 Link to this post

    Hi Robert,

    You should subscribe to the DockStateChanged event and change icons depending on what the DockState of your form is. Here is a sample code:
    public partial class MainForm : Form
    {
        private HostWindow hostWindow;
        private Form dockedWindow = new Form1();
        private ImagePrimitive iconImage;
     
        public MainForm()
        {
            InitializeComponent();
     
            iconImage = new ImagePrimitive();
            iconImage.Image = new Bitmap(dockedWindow.Icon.ToBitmap(), new Size(16, 16));
            iconImage.SetValue(DockLayoutPanel.DockProperty, Telerik.WinControls.Layouts.Dock.Left);
        }
     
        private void radButton1_Click(object sender, EventArgs e)
        {
            hostWindow = radDock1.DockControl(dockedWindow, Telerik.WinControls.UI.Docking.DockPosition.Left);
            (hostWindow.DockTabStrip as ToolTabStrip).CaptionElement.Children[2].Children.Insert(0, iconImage);
            hostWindow.Image = new Bitmap(dockedWindow.Icon.ToBitmap(), new Size(16, 16));
            hostWindow.DockManager.DockStateChanged += new DockWindowEventHandler(DockManager_DockStateChanged);   
        }
     
        void DockManager_DockStateChanged(object sender, DockWindowEventArgs e)
        {
            if (hostWindow.DockState == DockState.Floating)
            {
                hostWindow.FloatingParent.Icon = dockedWindow.Icon;
                hostWindow.FloatingParent.ShowIcon = true;
                hostWindow.FloatingParent.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
                hostWindow.FloatingParent.FormElement.TitleBar.IconPrimitive.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            }
            if (hostWindow.DockState == DockState.Docked)
            {
                if (!(hostWindow.DockTabStrip as ToolTabStrip).CaptionElement.Children[2].Children.Contains(iconImage))
                {
                    (hostWindow.DockTabStrip as ToolTabStrip).CaptionElement.Children[2].Children.Insert(0, iconImage);
                }
            }
        }
    }

    I hope this is helpful. If you are still experiencing problems, do not hesitate to write back.

    Kind regards,
    Ivan Todorov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  9. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 24 Feb 2011 Link to this post

    It works, thanks!

    Just one small detail left: when I re-dock by dragging a floating window to a dock location, the icon shows up correctly in the docked window.  However, if I double-click on the the titlebar of a floating window to dock it, 2 icons appear in the docked window.
  10. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 24 Feb 2011 Link to this post

    Never mind -- figured it out.  Everything is working perfectly now.  Thanks again!
  11. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 Feb 2011 Link to this post

    Hello Robert,

    I am glad you have sorted this out.

    If you have any further questions, feel free to ask.

    Greetings,
    Ivan Todorov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  12. norma
    norma avatar
    3 posts
    Member since:
    Jun 2010

    Posted 28 Feb 2011 Link to this post


    hi,

    is there a way for changing the displayed name (text) and icon image
    of a tabbed document window on run-time?

    i tried doing so, and the form seemed to ignore me :)

    for a workaround i have tried refreshing the tabbed document by removing it and creating a new one 
    with the desired text and icon.. but than - (of course) the tabbed window is created at a new position on the tab strip..
    if the answer to my previous question is "no"
    could you help me find a way of positioning a new dockwindow (hostwindow) in the exact same place on the tab strip
    as the one i am replacing?

    thank you,
    norma 
  13. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Mar 2011 Link to this post

    Hello Norma,

    You can change the text and the image on a Document Tab in the following way.

    this.documentWindow1.Text = "Hello";
    this.documentWindow1.Image = Image.FromFile(@"your file path");

    Hope that helps
    Richard
  14. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 02 Mar 2011 Link to this post

    Hi Norma,

    In my previous post you can find out how you can acccess the tab item when hosting controls in a tabbed document
    Form window = new Form1();
    HostWindow hostWindow = radDock1.DockControl(window, Telerik.WinControls.UI.Docking.DockPosition.Left);
    radDock1.AddDocument(hostWindow);
    hostWindow.TabStripItem.Image = new Bitmap(window.Icon.ToBitmap(), new Size(16, 16));
    hostWindow.TabStripItem.Text = "Form title: " + window.Text;

    I hope this will help you.

    Greetings,
    Ivan Todorov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  15. Robert
    Robert avatar
    6 posts
    Member since:
    Jul 2010

    Posted 11 Mar 2011 Link to this post

    In using this solution, I have found that it doesn't work when I tab-ify the windows; it seems that the tabbed windows share a common tabstrip, so that when I switch between the tabs the form-specific icons do not change.

    Are there events associated with dragging a DockWindow into a tabbed group, and with selecting a new tab?  RadDock.DockStateChanged doesn't fire in the first case.
  16. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 16 Mar 2011 Link to this post

    Hi Robert,

    I can't seem to reproduce your scenario. On my end the DockStateChanged fires properly and the tab item gets its image from the host window's image. May be I am missing something about your case, so could you please post a code sample. This will let me investigate in details and provide you with more appropriate answer. It will be best if you open a new support ticket and send me a sample project that I can run locally. This will help me to provide you with a quicker response.

    I am looking forward to your reply.

    Regards,
    Ivan Todorov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  17. norma
    norma avatar
    3 posts
    Member since:
    Jun 2010

    Posted 24 Mar 2011 Link to this post

    hi Richard and Ivan - 
    Just wanted to say thanks for the help :)

    norma
  18. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 30 Mar 2011 Link to this post

    Hi Norma,

    We are glad to hear that our answers helped you. If you have any other questions, feel free to ask.

    @Robert:

    Hi Robert,

    Did you manage to get your things running? Do not hesitate to ask if you need any help.

    Greetings,
    Ivan Todorov
    the Telerik team
  19. Lixandro
    Lixandro  avatar
    1 posts
    Member since:
    Nov 2013

    Posted 21 Jul 2015 Link to this post

     

    this.radDock.DockStateChanged += new Telerik.WinControls.UI.Docking.DockWindowEventHandler(this.radDock_DockStateChanged); ​

     

    private void radDock_DockStateChanged(object sender, DockWindowEventArgs e)         {             Icon icon = null;             var host = (HostWindow)e.DockWindow;             if (host.Content is Form)                 icon = ((Form)host.Content).Icon;             switch (e.DockWindow.DockState)             {                 case DockState.Floating:                     e.DockWindow.FloatingParent.Icon = icon;                     e.DockWindow.FloatingParent.ShowIcon = true;                     e.DockWindow.FloatingParent.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;                     e.DockWindow.FloatingParent.FormElement.TitleBar.IconPrimitive.Visibility = ElementVisibility.Visible;                     break;                 case DockState.Docked:                 case DockState.TabbedDocument:                     host.TabStripItem.TabPanel.Image = new Bitmap(icon.ToBitmap(), new Size(16, 16));                     break;             }         }​

     

    Regards,

     

  20. Dess
    Admin
    Dess avatar
    1606 posts

    Posted 24 Jul 2015 Link to this post

    Hello Lixandro,

    Thank you for writing back.

    It seems that the provided code snippet is similar to the one suggested by Ivan Todorov in the post from 24-Feb-2011. However, in addition, it handles the case when the floating form is docked as a tabbed document. Thank you for sharing with the community this small update of the code example.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready