我正在处理 Windows 窗体项目。在其中我需要一个继承类System.Windows.Forms.Form
,我将其命名为FormBase.cs
继承System.Windows.Forms.Form
类。但是在解决方案资源管理器中FormBase.cs
获得了类似于 Windows 窗体的视图。现在,当我尝试从解决方案资源管理器中打开文件时,它会在设计模式下打开。由于它很简单class
,我希望它必须在代码视图而不是设计视图中打开。为什么会发生?如果我想FormBase.cs
始终在代码视图中打开并在解决方案资源管理器中重新获得其类视图,我该怎么办?
FormBase.cs
好像 :
public class FormBase : System.Windows.Forms.Form
{
public virtual Dictionary<string, string> NonSaveableReasons()
{
Dictionary<string, string> _nonSavebleReasons = new Dictionary<string, string>();
//MaskedTextBox.MaskedTextBox and MaskedTextBox.MyCombo are Custom Components
//which are of type TextBox and ComboBox respectively
//having 2 more properties name as "IsMandatory" and "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 + " is 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 + " is 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;
}
}