In doing. NET project, you often encounter problems when designing the interface, where object references are not set to object instances, and the solution is given below:
1, for WinForm and ASP. NET interface design can do as follows:
WinForm Project:
protected override void OnLoad (EventArgs e) { base. OnLoad (e); if (String.Compare (). Process.getcurrentprocess (). ProcessName, "devenv") = = 0) return; Other related code, or //if (String.Compare (Process.getcurrentprocess (). ProcessName, "devenv")! = 0) // { //Other related codes, //}// or// if (!this. DesignMode) //{ } }
Sometimes it is necessary to add some action to the constructor (although this is not advocated), the problem arises, and the write in the constructor is slightly different.
Public burohomefrm () { InitializeComponent (); if (String.Compare (). Process.getcurrentprocess (). ProcessName, "devenv")! = 0) { //other code ..... }
Or
if (!this. DesignMode) //{ other code } //If you still write it, you will get an error. //if (String.Compare (). Process.getcurrentprocess (). ProcessName, "devenv") = = 0) // return; }
ASP. NET can refer to the above wording
2, for WPF, you can refer to the above wording, there is another way of writing
if (! Designerproperties.getisindesignmode (this)) { //other code
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C # Design interface, object references are not set to an object instance problem solution