[Problem solving] Unable to create a new stack protection page

Source: Internet
Author: User

[Problem Discovery]

The project requires several custom controls. Cainiao D defines an interface and intends to use polymorphism for unified calling. After two custom controls are completed, the project can run normally. However, when using the third Control, a problem occurs: After dragging the control to the interface, you cannot drag it to change the width of the control, A prompt "cannot create a new stack protection page" appears when you drag the page, and then vs crashes directly. After several attempts, I found that I could enter and change the width of the control, but there was still a crash.

[Problem solving]

Cainiao D searches for related solutions on the Internet, but almost all the answers are saying that recursive calls cause overflow. Cainiao D finds that there are recursive calls in its own program, but the first two controls are also called this recursive method. If there is a problem with the method itself, the two controls will certainly make an error, but the fact is that the two controls can be used normally. So the problem must be with the new custom control.

Because the crash occurs after changing the width of the control, you must check the width attribute. The following is some code:

Public int Width {get {return this. Width;} set {Width = value;
// Set the location of the control inside the custom control, for example, lable1.location = new Piont (); // to achieve a linkage effect
}}

At this time, Cainiao D noticed the prompt on the left side of the code:

Isn't Recursive call a recursion !!! It turns out that recursion leads to a crash. After this code is deleted, the control is dragged without any errors. The problem has been solved.

[Problem analysis]

Cainiao D does not understand why such writing would lead to recursion, so he starts the next search.

Using F12 on the Width in get, I found that the cursor only jumped up a line. It seems wrong and it feels a bit strange. Now that this is a custom Control and inherits the Control class, will the Control class be encapsulated. Then, go to the definition, and the following code shows the inheritance relationship:

Public partial class ExControlBox: UserControl, IControlCommonablepublic class UserControl: ContainerControlpublic class ContainerControl: role, role class controls: Control, IComponent, role class Control: Component, IDropTarget, role, IWin32Window, role, IComponent, IDisposable // Two attributes in the Control base class: public int Width {get; set;} public virtual string Text {get; set ;}

Actually, the Width attribute is found in the Control base class. When we see the Text attribute, we think that we have used override to overwrite the Text attribute. Can we rewrite the Width attribute in another way? Of course -- new. New is used as an operator to create objects and call Constructors. It is used as a modifier to hide inherited members in the base class (from msdn ).

As a result, the original Width attribute writing method is transformed, and the operation can be successful without a crash. The code is as follows:

New public int Width {get {return base. width;} set {base. width = value; // set the location of the control inside the custom control, for example, lable1.location = new Piont (); // to achieve a linkage effect }}

Summary:

1. When defining an attribute, pay attention to whether the attribute already exists in the base class. If so, you need to determine whether the attribute needs to be overwritten or hidden.

2. Be cautious when calling recursion; otherwise, overflow may occur, resulting in a crash.

Cainiao D hopes this article will help you.

[Problem solving] Unable to create a new stack protection page

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.