开发者

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 cu开发者_C百科rrent tabs form.


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.


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


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; }


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜