One line of code solves the problem of destroying the dialog form in VB. NET without refreshing the main form

Source: Internet
Author: User

Showdialog is the call method of the mode form in VB. NET.

If you use the showdialog () method in VB. NET to call a sub-form, you will find that the nature of the mode form in VB. NET is somewhat different from that in VB6.

The position of the form is remembered. The position of each open form is the same as that of the last closed form. If you perform a cyclic value assignment in the subform, you will find that if you do not clear the array before the assignment, the array will be accumulated continuously.

The reason for these problems is that in VB. NET, the form closed by showdialog is actually hidden but not destroyed. No dispose is executed.

To completely destroy the form, you must add the dispose () method to the close or close button of the form. However, this will cause another problem. When the mode form is destroyed, the main form will be repainted. We can see that the main form is flashing, Which is unfriendly to some customers.

The directly close form is not completely destroyed. If you force dispose (), the main form will be refreshed. Is there really no perfect solution?

In fact, there are some methods and they are very simple. Or close () method, but the location is slightly different.

Example:

Main form mainfrm, subform subfrm

 1   Private     Sub  Button#click (  Byval Sender  As  System. object,  Byval  E  As  System. eventargs)  Handles  Button1.click
2
3 Subfrm. showdialog ()
4 Subfrm. Close ()
5   End sub

(ProgramWrite it in 2010. For other vs versions, you can try to see if the same result will be obtained)

The close () in the fourth row achieves the goal of completely destroying the form. The solution is simple. You can try it yourself!

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.