Home > Net >  Winform, control and form have what?
Winform, control and form have what?

Time:10-22

I in the first form1 winform, set up a panel, and then through the code, and a panel with form2 size form, or within the form3 all controls in the panel respectively,
Now find, also can put the control in the control, and then put the control in the panel,
A little bit confused, in this case, the form what is the difference between the form and control? Are all the same?

CodePudding user response:

Just test found that if put in form1 is control, then write data in the inside control, and other page again to switch back and forth, return, data will continue to keep, but if it's form2 or form3, then switch back later, before the entry of data will all disappear, equivalent to reload all of the controls,
Therefore, I boldly speculate that for the panel, the load control is one-off, switching back and forth, do not need to secondary load control, and if the form, every time I switch back, have to reload the inside controls,
In other words, the control is more save computer memory?
Don't know me either of these conjectures right, please correct me,

CodePudding user response:

Found life cycle and recycling mechanism, but did not find the reason,
Although I can't see your code but I can guess, is your fill to the new form from during the presentation of the new devices to create variables, and are not variable method, so you will render the from to new devices for the variable existed, so after you close the new form variables have no recovery, again after open a new form data retention,
But in new Windows components, that is, every time control is to create the form calls InitializeComponent () method to initialize the closed form of the components. The Dispose () to recycle, so empty form content,

So you find the phenomenon and the reason why you want to do not fit, this is really just a form component recovery and form components not recycling variable life cycle issues,

CodePudding user response:

Code? If you switch to Form is new?

CodePudding user response:

Are inherited the control, the problem of switch should be you that a few button code is different

CodePudding user response:

Public class Form: ContainerControl

Public class ContainerControl: ScrollableControl, IContainerControl

Public class ScrollableControl: Control, IArrangedElement, IComponent, IDisposable

Public class Control: Component, IDropTarget ISynchronizeInvoke, IWin32Window, IArrangedElement, IBindableComponent, IComponent, IDisposable


So, what is the relationship between them, you see see,

Whether data, depending on your own, you are a new again, or to bing data, is dealing with the show themselves is not known

CodePudding user response:

Form is the Form, the Form inside container, the container inside Control, general development is carried out in this order, as for the bundle or add the data is yourself, Form if click the close button, to open is the need to reload the data, the Load is to Load the data, Control the inside your own drawing Control

CodePudding user response:

Oh, the code is very simple, the CONTROL and the FORM of basic load,
After loading, the content in the textbox is I knock up manually, just verify the switch will not retain data after,

Load Control code:
Public book ()
{
InitializeComponent();
Test=new test ();
Test2=new test2 ();
}
Private Test Test;
Private Test2 Test2.

Private void book_Load (object sender, EventArgs e)
{
Panel2. Controls. The Add (test2);
}

Private void button1_Click (object sender, EventArgs e)
{
Panel2. Controls. The Clear ();
Panel2. Controls. The Add (test2);
}

Private void button2_Click (object sender, EventArgs e)
{
Panel2. Controls. The Clear ();
Panel2. Controls. The Add (test);
}

Load the Form code:
Private void button3_Click (object sender, EventArgs e)
{
Form5 form=new Form5 ();
Form the TopLevel=false;
Panel2. Controls. The Add (form);
Form. FormBorderStyle=FormBorderStyle. None;
Form. The Show ();
Form. BringToFront ();
}

CodePudding user response:

Because has been by loading the form to another form of a panel on page updates, by chance, to try to load control, found as and the form has the same function, so wonder what is the difference between the two
  •  Tags:  
  • C#