This is a migrated thread and some comments may be shown as answers.

Icon for docked window

18 Answers 470 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 14 Feb 2011, 05:25 PM
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.

18 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 14 Feb 2011, 06:21 PM
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
0
Robert
Top achievements
Rank 1
answered on 14 Feb 2011, 07:13 PM
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.
0
Richard Slade
Top achievements
Rank 2
answered on 15 Feb 2011, 10:20 AM
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
0
Ivan Todorov
Telerik team
answered on 17 Feb 2011, 02:16 PM
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
0
Robert
Top achievements
Rank 1
answered on 21 Feb 2011, 10:08 PM
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?
0
Accepted
Ivan Todorov
Telerik team
answered on 24 Feb 2011, 08:34 AM
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!
0
Robert
Top achievements
Rank 1
answered on 24 Feb 2011, 05:28 PM
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.
0
Robert
Top achievements
Rank 1
answered on 24 Feb 2011, 06:15 PM
Never mind -- figured it out.  Everything is working perfectly now.  Thanks again!
0
Ivan Todorov
Telerik team
answered on 28 Feb 2011, 05:34 PM
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!
0
norma
Top achievements
Rank 1
answered on 28 Feb 2011, 08:01 PM

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 
0
Richard Slade
Top achievements
Rank 2
answered on 01 Mar 2011, 11:04 AM
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
0
Ivan Todorov
Telerik team
answered on 02 Mar 2011, 09:28 AM
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!
0
Robert
Top achievements
Rank 1
answered on 11 Mar 2011, 09:21 PM
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.
0
Ivan Todorov
Telerik team
answered on 16 Mar 2011, 08:36 AM
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!
0
norma
Top achievements
Rank 1
answered on 24 Mar 2011, 11:56 PM
hi Richard and Ivan - 
Just wanted to say thanks for the help :)

norma
0
Ivan Todorov
Telerik team
answered on 30 Mar 2011, 11:24 AM
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
0
Lixandro
Top achievements
Rank 1
answered on 21 Jul 2015, 02:53 PM

 

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,

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jul 2015, 08:31 AM
Hello ,

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
Tags
Dock
Asked by
Robert
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Ivan Todorov
Telerik team
norma
Top achievements
Rank 1
Lixandro
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or