0
大家。我的計劃是創建一個單獨的類,我將在其中聲明所有的標籤和文本框值。但要做到這一點,我必須從表單繼承。問題是,當我從窗體繼承時,我的類變成了窗體並從它自身調用元素。將標籤和文本框的屬性設置爲公共不會有幫助。有任何想法嗎?從表單c繼承#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Assignment2v3
{
class Declarations : Form1
{
public List<Label> ErrRep
{ get; set; }
public List<TextBox> TextBoxes
{ get; set; }
public List<ComboBox> ComboBoxes
{ get; set; }
public Declarations()
{
ErrRep = DeclareErrorReports();
TextBoxes = DeclareTextBoxes();
ComboBoxes = DeclareComboBoxes();
}
List<Label> DeclareErrorReports()
{
var ER = new List<Label>();
ER.Add(errorReport1);
ER.Add(errorReport2);
ER.Add(errorReport3);
return ER;
}//Would be used if try catch worked
List<TextBox> DeclareTextBoxes()
{
List<TextBox> TextBoxes = new List<TextBox>();
TextBoxes.Add(textBoxPizza1);
TextBoxes.Add(textBoxPizza2);
TextBoxes.Add(textBoxPizza3);
return TextBoxes;
}//Puts all textBoxes into a list
List<ComboBox> DeclareComboBoxes()
{
var ComboBoxes = new List<ComboBox>();
ComboBoxes.Add(comboBoxPizza1);
ComboBoxes.Add(comboBoxPizza2);
ComboBoxes.Add(comboBoxPizza3);
return ComboBoxes;
}//Puts all comboboxes into a list
//^Boring declarations
}
}
這是什麼意思:問題是,當我從窗體繼承我的類變成窗體並從它自己調用元素。 – CodingYoshi
在屏幕截圖上查看。 Declarations.cs成爲一種形式。它甚至有一個設計選項,像一個正常的窗體形式 – alex3wielki
以及繼承是如何工作的。如果這不是你想要的,那麼重新提出你的問題,並告訴我們你想完成什麼,並且有人可以告訴你如何完成。整個繼承點是:我需要基類所有的東西,再加上我會添加更多。 – CodingYoshi