johankj
johankj

Reputation: 1767

Getting current Tab/Document in DockPanel Suite

I'm using the DockPanel Suite by Weifen Luo in a little project (webbrowser) and have managed to be able to create tabs and navigate the webbrowser element inside each tab.

But how am I able to change the tabs title/name when the page is navigating to another site?

Basically I just need to get into the current tabs form.

Upvotes: 1

Views: 3444

Answers (4)

Whitney
Whitney

Reputation: 209

I needed the ability to check which document was active, and set that document to active again after changing some UI elements that automatically reset the active tab, so I used some pieces from here and the DockPanel FAQ, and did some digging to figure out the answer to this problem:

public string GetActive()
   { //Verify if forms that dock in main window are already open
      foreach (DockContent form in dockMain.Contents)
      {
         if (form.DockHandler.Pane.ActiveContent.DockHandler.Form.Name.ToString() == form.Name.ToString())
         {
            string formName = form.Name.ToString();
            return formName;
         }
      }
   return null;
   }

And then in some other method you will call:

string activeForm = GetActive();

Upvotes: 0

Ben
Ben

Reputation: 143

You can manage your own (assuming your Document Form is a specific class) by managing:

'FormClosing' and 'Activated' events

'Activated' set your own "active" document to 'this'. 'FormClosing' set your own "active" document to null.

FormClosing is just to catch the case where you are closing the last document. Activated is what manages everything else, like when a new document gets created and is made the active window, etc.

You can use a static global to manage focus. Then access it from anywhere else:

public partial class MyDocument : DockContent
{
   public static MyDocument ActiveDocument { get; private set; }

Upvotes: 0

user1399165
user1399165

Reputation: 116

You can get the current tab by using DockPanel's ActiveContent method. For example:

Form myForm = myDockPanel.ActiveContent();
myForm.TabText = "Stack Overflow";

DockPanel.ActiveDocument and DockPanel.ActivePane can also be useful.

Upvotes: 6

johankj
johankj

Reputation: 1767

After having worked on this a few weeks (not 'till now though :P) I have to say, that this is currently not possible.

Upvotes: 0

Related Questions