18 Answers, 1 is accepted
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
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
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,
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?
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,
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.
I am glad you have sorted this out.
If you have any further questions, feel free to ask.
Greetings,
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
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
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,
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.
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,
Just wanted to say thanks for the help :)
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,
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,
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