Basic use of dockpanel

Source: Internet
Author: User

I will not talk about the basic usage of dockpanel. There are a lot of online users. I want to talk about several small issues that need to be paid attention to when using dockpanel.

First:

People who have used dockpanel may encounter the following error:

Invalid Content: activecontent must be one of the visible contents, or null if there is no visible content.

The translation roughly means: Invalid Content: If there is no visible content, activecontent must be visible or empty.

For specific reasons, we can discuss each other. Let me talk about several situations that have this problem.

The this keyword in the Code indicates that the form of dockpanel is form1.

1) when the documentstyle of dockpanel is not dockingmdi, this problem occurs in the following code:

Frm_a FRMA = NULL;
// Determine whether the child form already exists in the dockpanel
Foreach (dockcontent frm in this.doc kpanel1.contents)
{
If (FRM is frm_a)
{
FRM. Activate (); // activate the subform
Return;
}
}

 

FRMA = new frm_a ();
FRMA. mdiparent = this;
Frma.show(this.doc kpanel1 );

Solution: Check whether the docker netstyle you set is dockingmdi. You can also try other methods (dockingwindow, dockingsdi, systemmdi)

2) When the documentstyle of the dockpanel is not set to dockingmdi, if you want to set the form frm_ B to the floating form on the left, you need to set the dockareas of the form frm_ B as and only dockleft, if you want to implement other functions, you can set other attributes on your own. For more information, see the following code:

Frm_ B frmb = NULL;
// Determine whether the child form already exists in the dockpanel
Foreach (dockcontent frm in this.doc kpanel1.contents)
{
If (FRM is frm_ B)
{
FRM. Activate (); // activate the subform
Return;
}
}

Frmb = new frm_ B ();
// Frmb. mdiparent = this;
Frmb.show(this.doc kpanel1, dockstate. dockleft );

Note: If you add a red comment to your code, the above error will be reported during the program running.

Solution: annotate the red code.

Cause: (individual Member member frmb.show(this.doc kpanel1, dockstate. dockleft); in fact, this Code sets the frmb to only dock to the left of the dockpanel. At this time, the frmb does not belong to the MDI subform, so once you add the red code, the program reports an error.

 

Second:

Drag, dock, and fix sub-forms (displayed in dockpanel)

Drag: If you want to make your child form any drag, keep the default value when setting the dockareas attribute of the child form, and do not modify it.

DOCK: First, you need to set the location of dockareas, which can be docked to the left, right, and bottom, or controlled by program code. Refer to the above Code.

Fixed: you only need to set dockareas of your form to document.

 

Third:

Judgment of subforms AND CONTENTS

In many cases, you need to determine the number of child forms or contents in the dockpanel. refer to the following code:

Foreach (form in this. mdichil.pdf)

{

// The docked form is not included in this judgment.

}

 

While

Foreach (dockcontent frm in this.doc kpanel1.contents)
{

// After this setting, all the inheritance and dockcontent forms will be included

}

 

Fourth:

Search for main forms and dynamically display subforms

Reference diagram:

Implemented functions: here we need to implement it. Right-click form a and right-click Form B to display Form B.

// The object of the main form
Form1 form1;

Private void showb_click (Object senders, eventargs E)
{

Getfrmmain (); // use this function to obtain form1

Foreach (Form frm in form1.mdichil.pdf)
{
If (FRM is frm_ B)
{
FRM. Activate ();
Return;
}
}

Frm_ B frmb = new frm_ B (this );
Frmb. mdiparent = form1;
Frmb.show(form1.doc kpanel1 );

}

 

Private void getfrmmain ()

{

If (this. Parent. parent! = NULL)
{
Form1 = (form1) This. Parent. parent;
}
Else
{
Form1 = (form1) This. Parent. Parent. parent;
}

}

 

Now it is in Form A. If the code for this keyword is not the main form, we need to obtain the main form object.

When form a is docked, this. Parent. Parent (four) is required)

When no call is made, only three this. Parent. Parent. parent are required.

Debugging code discovery: When stopping

This. parent is {weifenluo. winformsui. Docking. dockpane}

This. Parent. parent is {weifenluo. winformsui. Docking. dockwindow, borderstyle: system. Windows. Forms. borderstyle. None}

This. Parent. Parent. parent is {weifenluo. winformsui. Docking. dockpanel, borderstyle: system. Windows. Forms. borderstyle. None}

This. Parent. Parent. parent is {testeven handler. form1, text: form1} is the main form form1 we are looking.

 

When not docked:

This. parent is {weifenluo. winformsui. Docking. dockpane}

This. Parent. parent is {weifenluo. winformsui. Docking. dockpanel + autohidewindowcontrol, borderstyle: system. Windows. Forms. borderstyle. None}

This. Parent. Parent. parent is {testeven handler. form1, text: form1} is the main form form1 we are looking.

 

I have encountered four small problems during development, but the reasons may not be very clear. I forget to discuss each other and make progress together.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.