c# - Can I make a class which inherits from System.Windows.Forms.Form class always open in code view? -


i working on windows form project. in need 1 class inherit system.windows.forms.form, name formbase.cs , inherit system.windows.forms.form class. in solution explorer formbase.cs got view windows form.. when try open file solution explorer open in design mode. since simple class expect must open in code view not in design view. why happens? should if want formbase.cs open in code view , regain class view in solution explorer? formbase.cs looks :

public class formbase : system.windows.forms.form {     public virtual dictionary<string, string> nonsaveablereasons()     {         dictionary<string, string> _nonsaveblereasons = new dictionary<string, string>();          //maskedtextbox.maskedtextbox , maskedtextbox.mycombo custom components         //which of type textbox , combobox respectively         //having 2 more properties name "ismandatory" , "labelname"          foreach (maskedtextbox.maskedtextbox masktextbox in this.controls.oftype<maskedtextbox.maskedtextbox>())         {             if (masktextbox.ismandatory && string.isnullorempty(masktextbox.text) && !_nonsaveblereasons.containskey(masktextbox.name))                 _nonsaveblereasons.add(masktextbox.name, masktextbox.labelname + " mandatory.");         }          foreach (maskedtextbox.mycombo mycombo in this.controls.oftype<maskedtextbox.mycombo>())         {             if (mycombo.ismandatory && string.isnullorempty(mycombo.text) && !_nonsaveblereasons.containskey(mycombo.name))             {                 if (!_nonsaveblereasons.containskey(mycombo.name))                     _nonsaveblereasons.add(mycombo.name, mycombo.labelname + " mandatory.");             }         }          return _nonsaveblereasons;     }      public string getvalidationstringmsg(dictionary<string, string> nonsavableresons)     {         return nonsavableresons != null ? string.join(environment.newline, nonsavableresons.select(a => a.value).toarray()) : string.empty;     } } 

you can use system.componentmodel.designercategoryattribute prevent visual studio opening 1 particular file in designer. there 2 ways can apply attribute.

option a

step 1. apply attribute formbase, specifying "" category:

[system.componentmodel.designercategory("")] public class formbase : system.windows.forms.form 

step 2. apply attribute every form deriving formbase, specifying "form" category:

[system.componentmodel.designercategory("form")] public partial class mainform : formbase 

note must use qualified type name of attribute. doesn't work:

// bad code - don't use using system.componentmodel;  [designercategory("")] public class formbase : system.windows.forms.form 

option b

in formbase.cs, above formbase, add dummy class , apply attribute it, specifying "" category:

[system.componentmodel.designercategory("")] internal class unused { }  public class formbase : system.windows.forms.form {     // ... } 

with approach, don't need apply attribute every form deriving formbase, @ cost of unused class.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -