我正在調試應用程序,我正在建立一個窗體(基於System.Windows.Form的一個非常小的擴展),這是打算在一個構造函數,並創建一個新的參數控制每個參數在構造函數。爲什麼我的控件中只有一個被添加到此表單中?
我現在的問題是,由於某種原因,我的ParameterControls被添加到窗體中,但只有第一個添加在操作結束時可見。
有問題的代碼和支持方法;如下:
class ConstructorDialog : Namespace.Forms.Form
{
protected void InitializeInterface()
{
if (this.TargetType == null)
{
throw new InvalidOperationException("Cannot GenerateFields for ConstructorDialog. ConstructorDialog TargetType is null.");
}
else if (this.TargetConstructor == null)
{
}
else
{
foreach(ParameterInfo Parameter in this.TargetConstructor.GetParameters())
{
try
{
ParameterControl NewParameterControl = new ParameterControl(Parameter);
NewParameterControl.Location = new Point(0, 30 + (30 * Parameter.Position));
this.AddControl(NewParameterControl);
continue;
}
catch (Exception e)
{
}
}
return;
}
}
}
class Namespace.Forms.Form : System.Windows.Forms.Form
{
public Control AddControl(Control Control)
{
if (Control == null)
throw new InvalidOperationException("Form cannot AddControl. Control is null.");
else
{
this.Controls.Add(Control);
return Control;
}
}
}
class Namespace.Debugging.ParameterControl : Namespace.Forms.UserControl
{
protected void InitializeInterface()
{
if (this.TargetParameter == null)
{
throw new InvalidOperationException("Cannot InitializeInterface for ConstructorParameterControl. ConstructorParameterControl TargetParameter is null.");
}
else
{
this.Controls.Clear();
this.AddLabel(this.TargetParameter.Name + "_Label", this.TargetParameter.Name, new Point(25,0));
return;
}
}
}
class Namespace.Forms.UserControl : System.Windows.Forms.UserControl
{
public Label AddLabel(String LabelName, String LabelText, Point Location)
{
if (String.IsNullOrEmpty(LabelName))
throw new ArgumentNullException();
else if (String.IsNullOrEmpty(LabelText))
throw new ArgumentNullException();
else
{
Label NewLabel = new Label();
NewLabel.Name = LabelName;
NewLabel.Text = LabelText;
NewLabel.Location = Location;
return this.AddLabel(NewLabel);
}
}
public Label AddLabel(Label Label)
{
if (Label == null)
throw new ArgumentNullException();
else
{
this.Controls.Add(Label);
return Label;
}
}
}
我的形式擴展仍處於起步階段,所以它很可能是我忽略了一些(尤其是因爲我的知識形式是唯一的徒弟,值得),但這個操作起來很簡單,在我評估應該工作。
一些調試信息:
The controls are being added to the base 'Controls' collection.
The positions of the controls are being set to what they ought to, so it is not a matter of them overlapping.
No exceptions are encountered during execution.
控件的寬度和高度是否設置爲正值?他們的可見屬性是否正確? –
我沒有手動更改後續方法中這些字段的值。在這些控件的構建中發生的所有事情都是創建一個新標籤並設置文本...我想我可以強制這些字段上的值,儘管... – DigitalJedi805
在沒有進入太遠之後,我遇到了這個問題,如你可以評估。 – DigitalJedi805