目标是创建电子表格类型的程序,例如Microsoft Excel。我已经创建了一个要创建其多个实例的单元格类。语法是否正确,或者我在逻辑上缺少什么?
到目前为止,我做了什么: -创建一个单元格类。 -初始化数组,只会得到一个错误。
public partial class form_welcomeScreen : Form
{
Label[] cellLetters = new Label[26];
Label[] cellNumbers = new Label[26];
Cell cell[] = new Cell[26];
char cellLetter = 'A';
int cellNumber = 1;
public form_welcomeScreen()
{
InitializeComponent();
}
private void Btn_newSheet_Click(object sender, EventArgs e)
{
for (int i = 0; i < 26; i++)
{
Cell cell = new Cell();
pnl_main.Controls.Add(cell.createCell());
cell.CellLetter = cellLetter;
cell.CellNumber = cellNumber;
cellLetter++;
cellNumber++;
}
}
}
class Cell : System.Windows.Forms.TextBox
{
private char cellLetter;
private int cellNumber;
private string cellID;
public char CellLetter
{
get { return cellLetter; }
set { cellLetter = value; }
}
public int CellNumber
{
get { return cellNumber; }
set { cellNumber = value; }
}
public string CellID
{
get { return cellID; }
set { cellID = CellLetter + Convert.ToString(CellNumber); }
}
public TextBox createCell()
{
TextBox cell = new TextBox();
cell.AcceptsReturn = true;
cell.Name = cellID;
cell.Size = new System.Drawing.Size(50, 25);
return cell;
}
我希望创建一个数组,这样我就可以创建一个完整的包含单元格的电子表格。
答案 0 :(得分:0)
该行:
Cell cell[] = new Cell[26];
给您不匹配的类型(cell
与cell[]
)。应该是:
Cell[] cell = new Cell[26];