C# 如何在C中创建按钮#

C# 如何在C中创建按钮#,c#,class,button,inheritance,C#,Class,Button,Inheritance,请帮我创建按钮。我有一个问题,当我运行应用程序,所以我看不到任何按钮从我的代码。我的代码中有一个bug 步骤1)(按钮属性类) 步骤2)(按钮位置和大小的类别) 步骤3)(表单初始化组件中的脚本) Collection=newcollection(); GraphicClassStructure类结构=新的GraphicClassStructure(); 公共构建编辑器() { 初始化组件(); this.Cursor=NativeMethods.LoadCustomCursor(Path.Co

请帮我创建按钮。我有一个问题,当我运行应用程序,所以我看不到任何按钮从我的代码。我的代码中有一个bug

步骤1)(按钮属性类)

步骤2)(按钮位置和大小的类别)

步骤3)(表单初始化组件中的脚本)

Collection=newcollection();
GraphicClassStructure类结构=新的GraphicClassStructure();
公共构建编辑器()
{
初始化组件();
this.Cursor=NativeMethods.LoadCustomCursor(Path.Combine(collection.source,collection.Cursor));
maxSkillPoint.Text=collection.maxSkill.ToString();
classStructure.CreateClassButtons();
this.Controls.Add(classStructure.classBackround);
对于(int i=0;i<3;i++)
{
开关(一)
{
案例0:
classStructure.resetTree.Location=新系统.Drawing.Point(classStructure.Location[0][0][2],classStructure.Location[0][1][2]);
打破
案例1:
classStructure.resetTree.Location=新系统.Drawing.Point(classStructure.Location[0][0][3],classStructure.Location[0][1][3]);
打破
案例2:
classStructure.resetTree.Location=新系统.Drawing.Point(classStructure.Location[0][0][4],classStructure.Location[0][1][4]);
打破
}
classStructure.resetTree.Click+=新事件处理程序(resetTreekOneEvent\u Click);
classStructure.resetTree.Tag=i;
this.Controls.Add(classStructure.resetTree);
}
开关(UniqueValue.character)
{
“巫师”一案:
MessageBox.Show(“巫师”);
classStructure.menu.Click+=newsystem.EventHandler(巫师单击);
classStructure.menu.MouseEnter+=新系统.EventHandler(巫师\u MouseEnter);
classStructure.menu.MouseLeave+=新系统.EventHandler(魔术师\u MouseLeave);
打破
案例“龙骑士”:
MessageBox.Show(“龙骑士”);
classStructure.menu.Click+=newsystem.EventHandler(dragonKnightText\u Click);
classStructure.menu.MouseEnter+=新系统.EventHandler(dragonKnightText\u MouseEnter);
classStructure.menu.MouseLeave+=新系统.EventHandler(dragonKnightText_MouseLeave);
打破
案例“圣堂武士”:
MessageBox.Show(“圣堂武士”);
classStructure.menu.Click+=newsystem.EventHandler(templar\u Click);
classStructure.menu.MouseEnter+=新系统.EventHandler(templar\u MouseEnter);
classStructure.menu.MouseLeave+=新系统.EventHandler(templar_MouseLeave);
打破
案例“夜刃”:
MessageBox.Show(“夜刃”);
classStructure.menu.Click+=newsystem.EventHandler(nightblade_Click);
classStructure.menu.MouseEnter+=新系统.EventHandler(nightblade_MouseEnter);
classStructure.menu.MouseLeave+=新系统.EventHandler(nightblade_MouseLeave);
打破
}
this.Controls.Add(this.classStructure.menu);
}

不显示任何按钮。请帮帮我。

您所有的按钮都有大小(0,0)和位置(0,0)。
您错误地使用了数组。例如,代码
newint[89]
创建了一个包含89个元素的数组,所有元素都为零。但看起来您想存储一个
int
值89。
您需要以这种方式更改代码:
声明

// 2 pairs of square brackets instead of 3
public int[][] Location;
public int[][] Size;
Location = new int[][]
{
    new int[]
    {
        // Menu
        89,
        // Class
        325,
        // Reset Tree
        410,
        615,
        823
    },
...
初始化

// 2 pairs of square brackets instead of 3
public int[][] Location;
public int[][] Size;
Location = new int[][]
{
    new int[]
    {
        // Menu
        89,
        // Class
        325,
        // Reset Tree
        410,
        615,
        823
    },
...
使用:

    this.menu.Location = new System.Drawing.Point(Location[0][0], Location[1][0]);
但更好的方法是以以下方式重新设计位置和大小数据结构:

Point[] Location; // instead of int[][] Location
Size[] Size; // instead of int[][] Size

我的代码中有一个bug。
调试一下,它可能会帮助你。尽量减少你正在处理的代码量,你很快就会发现罪犯。从你发布的代码中,我看不到按钮添加到表单的位置。使用设计器为开始添加按钮。动态创建按钮是一项高级任务。您的解决方案帮助了我,真的,thx和我使用您的观点来确定点和大小。
Point[] Location; // instead of int[][] Location
Size[] Size; // instead of int[][] Size