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

Setting Tab Color for selected and unseleced Document Windows

6 Answers 222 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 09 Jun 2011, 02:22 AM
Hi Telerik

I am trying to set the color of the tab on unselected document windows to "MistyRose" and the tab on the currently selected document window to "Snow" using the following code

    rDockModelPackage.ActiveWindowChanging+=new DockWindowCancelEventHandler(rDockModelPackage_ActiveWindowChanging);
    rDockModelPackage.ActiveWindowChanged += new DockWindowEventHandler(rDockModelPackage_ActiveWindowChanged);
}
private void rDockModelPackage_ActiveWindowChanged(object sender, DockWindowEventArgs e)
{
   SizeAndColorSelectedDocWindowTab(e.DockWindow.TabStrip.TabStripElement, Color.Snow, Color.MistyRose);
}
private void  rDockModelPackage_ActiveWindowChanging(object sender, DockWindowCancelEventArgs e)
{
    SizeAndColorUnSelectedDocWindowTab(e.OldWindow.TabStrip.TabStripElement, Color.Snow, Color.MistyRose);
}
And

private void SizeAndColorSelectedDocWindowTab(RadTabStripElement win, Color lightColour, Color darkColour)
{
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor = lightColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor2 = lightColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor3 = lightColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor4 = lightColour;
}
private void SizeAndColorUnSelectedDocWindowTab(RadTabStripElement win, Color lightColour, Color darkColour)
{
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor = darkColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor2 = darkColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor3 = darkColour;
        ((FillPrimitive)win.Children[0].Children[0].Children[0].Children[0].Children[0]).BackColor4 = darkColour;
}


The result is hit and miss with the color changes working sometimes and at others being a mixture of the 2. Any ideas as to why this might be happening?

Regards
Ian

6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 09 Jun 2011, 12:16 PM
Hi Ian,

Thank you for your question.

You are currently changing the colors of RadTabStripElement. Instead, you should change the colors of the FillPrimitive contained in the TabStripItem that each DocumentWindow has. Here is the correct code snippet:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
  
        this.radDock1.ActiveWindowChanging += new DockWindowCancelEventHandler(radDock1_ActiveWindowChanging);
        this.radDock1.ActiveWindowChanged += new DockWindowEventHandler(radDock1_ActiveWindowChanged);
  
        foreach (DocumentWindow dw in this.radDock1.DockWindows.DocumentWindows)
        {
            SizeAndColorUnSelectedDocWindowTab((FillPrimitive)dw.TabStripItem.Children[0], Color.Snow, Color.MistyRose); 
        }
    }
  
    void radDock1_ActiveWindowChanged(object sender, DockWindowEventArgs e)
    {
        SizeAndColorSelectedDocWindowTab((FillPrimitive)e.DockWindow.TabStripItem.Children[0], Color.Snow, Color.MistyRose);             
    }
  
    void radDock1_ActiveWindowChanging(object sender, DockWindowCancelEventArgs e)
    {
        SizeAndColorUnSelectedDocWindowTab((FillPrimitive)e.OldWindow.TabStripItem.Children[0], Color.Snow, Color.MistyRose); 
    }
  
    private void SizeAndColorSelectedDocWindowTab(FillPrimitive fill, Color lightColour, Color darkColour)
    {
        fill.BackColor = lightColour;
        fill.BackColor2 = lightColour;
        fill.BackColor3 = lightColour;
        fill.BackColor4 = lightColour;
    }
  
    private void SizeAndColorUnSelectedDocWindowTab(FillPrimitive fill, Color lightColour, Color darkColour)
    {
        fill.BackColor = darkColour;
        fill.BackColor2 = darkColour;
        fill.BackColor3 = darkColour;
        fill.BackColor4 = darkColour;
    }
}

I hope this helps. If you have additional questions, feel free to contact me.

Best wishes,
Nikolay
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Ian
Top achievements
Rank 1
answered on 09 Jun 2011, 02:29 PM
Hi Nikolay

That's brilliant mate thanks. I was gettng lost in the element object model. It's good to see that these things can be accessed more directly.

Now I just have to figure out how to maintain the selected tab color in groups of docwindows docked at the bottom and top of the dock. I guess I can distinguish by dock position and then by uppermost. What do you think? 

Regards
Ian
0
Nikolay
Telerik team
answered on 14 Jun 2011, 03:19 PM
Hello Ian,

Thank you for getting back to me.

I am not sure that I understand your scenario completely. Could you please describe it in greater detail? This will allow me to assist you further.

All the best,
Nikolay
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Ian
Top achievements
Rank 1
answered on 15 Jun 2011, 04:41 AM
Hi Nikolay,

I have created customised document windows with the added property of "DocumentGroup" which is a string which indicates the group to which I want the document to belong.

I want to be able to dock document windows together according to their DocumentGroup value AND maintain the tab color of the uppermost window in each group as Color.Snow.

With the code we have so far the selected tab is the correct color but ALL other tabs turn to Color.MistyRose.

I need the uppermost tabs in the other document groups to remain Color.Snow as if they were also selected(even though they are not)

Hope this helps to clarify

Regards
Ian
0
Accepted
Nikolay
Telerik team
answered on 15 Jun 2011, 12:54 PM
Hi Ian,

Yes, your additional details clarified the case. If I now understand correctly, you want to have one white tab item per DocumentGroup. I am attaching a sample project which demonstrates the approach. It is based on my previous code snippet. As to the process of docking a window to specific windows, our DragDropService will allow you to achieve your requirements.

I hope this helps.

Kind regards,
Nikolay
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Ian
Top achievements
Rank 1
answered on 15 Jun 2011, 07:54 PM
Hi Nickolay

Many thanks for your sample project. It solves my problem exactly.

Regards
Ian
Tags
Dock
Asked by
Ian
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Ian
Top achievements
Rank 1
Share this question
or