Object[] button=new Object[10]; int position_x;
int position_y;
int num = 0; private void new_button_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
(Button)button[i] = new Button();
(Button)button[i].Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
(Button)button[i].Name = "my_button";
(Button)button[i].Size = new Size(100 + position_x, 100 + position_y);
(Button)button[i].TabIndex += 1;
(Button)button[i].Text = "This is my new one.";
(Button)button[i].UseVisualStyleBackColor = true;
(Button)button[i].Visible = true;
(Button)button[i].Parent = this;
position_x += 10;
position_y += 10;
(Button)button[i].BringToFront();
}
}运行结果:
------ 已启动生成: 项目: WindowsFormsApplication1, 配置: Debug Any CPU ------
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\WindowsFormsApplication1.exe /resource:obj\Debug\WindowsFormsApplication1.Form1.resources /resource:obj\Debug\WindowsFormsApplication1.Properties.Resources.resources /target:winexe Form1.cs Form1.Designer.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(36,27): 错误 CS1061: “object”不包含“Location”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Location”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(37,27): 错误 CS1061: “object”不包含“Name”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Name”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(38,27): 错误 CS1061: “object”不包含“Size”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Size”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(39,27): 错误 CS1061: “object”不包含“TabIndex”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“TabIndex”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(40,27): 错误 CS1061: “object”不包含“Text”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(41,27): 错误 CS1061: “object”不包含“UseVisualStyleBackColor”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“UseVisualStyleBackColor”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(42,27): 错误 CS1061: “object”不包含“Visible”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Visible”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(43,27): 错误 CS1061: “object”不包含“Parent”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Parent”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(55,27): 错误 CS1061: “object”不包含“BringToFront”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“BringToFront”(是否缺少 using 指令或程序集引用?)编译完成 -- 9 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
int position_y;
int num = 0; private void new_button_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
(Button)button[i] = new Button();
(Button)button[i].Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
(Button)button[i].Name = "my_button";
(Button)button[i].Size = new Size(100 + position_x, 100 + position_y);
(Button)button[i].TabIndex += 1;
(Button)button[i].Text = "This is my new one.";
(Button)button[i].UseVisualStyleBackColor = true;
(Button)button[i].Visible = true;
(Button)button[i].Parent = this;
position_x += 10;
position_y += 10;
(Button)button[i].BringToFront();
}
}运行结果:
------ 已启动生成: 项目: WindowsFormsApplication1, 配置: Debug Any CPU ------
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\WindowsFormsApplication1.exe /resource:obj\Debug\WindowsFormsApplication1.Form1.resources /resource:obj\Debug\WindowsFormsApplication1.Properties.Resources.resources /target:winexe Form1.cs Form1.Designer.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(36,27): 错误 CS1061: “object”不包含“Location”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Location”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(37,27): 错误 CS1061: “object”不包含“Name”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Name”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(38,27): 错误 CS1061: “object”不包含“Size”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Size”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(39,27): 错误 CS1061: “object”不包含“TabIndex”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“TabIndex”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(40,27): 错误 CS1061: “object”不包含“Text”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Text”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(41,27): 错误 CS1061: “object”不包含“UseVisualStyleBackColor”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“UseVisualStyleBackColor”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(42,27): 错误 CS1061: “object”不包含“Visible”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Visible”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(43,27): 错误 CS1061: “object”不包含“Parent”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“Parent”(是否缺少 using 指令或程序集引用?)
F:\Guide Snake\GS\WindowsFormsApplication1\Form1.cs(55,27): 错误 CS1061: “object”不包含“BringToFront”的定义,并且找不到可接受类型为“object”的第一个参数的扩展方法“BringToFront”(是否缺少 using 指令或程序集引用?)编译完成 -- 9 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
解决方案 »
- C# 查询Oracle数据库通过Parameter传递参数的问题
- app_code 文件夹有申明类 Controls 无法找继承
- textbox怎么用代码换行··
- c# 如何获取Win2003中的已连接用户名称,怎样断开一个已连接用户?
- 统计连续出现次数
- C#中OnMouseWheel不能响应
- 用C#和ADO.NET开发遇到数据临时保存的问题,请高手指点
- 关于动态链接库问题
- 请问数据源的值变化后,控件的值会不会自动变化。
- C#写桌面日历记事提示软件
- 如何设置 multiline=true 的textbox中每行的高度?
- class clasname <Type>...这个<Type>是啥意思...我在别人的问题看到的不解之外...进来看看代码
{
button[i] = new Button();
((Button)button[i]).Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
((Button)button[i]).Name = "my_button";
((Button)button[i]).Size = new Size(100 + position_x, 100 + position_y);
((Button)button[i]).TabIndex += 1;
((Button)button[i]).Text = "This is my new one.";
((Button)button[i]).UseVisualStyleBackColor = true;
((Button)button[i]).Visible = true;
((Button)button[i]).Parent = this;
position_x += 10;
position_y += 10;
((Button)button[i]).BringToFront();
}
你最好在for刚开始处用 button b = (button)button[i];
然后后面都用b来代替((Button)button[i]),这样就不用每句话都执行一次转换了
Object[] button=new Object[10]; int position_x;
int position_y;
int num = 0; private void new_button_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
//button[i] = new Button();
//((Button)button[i]).Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
//((Button)button[i]).Name = "my_button";
//((Button)button[i]).Size = new Size(100 + position_x, 100 + position_y);
//((Button)button[i]).TabIndex += 1;
//((Button)button[i]).Text = "This is my new one.";
//((Button)button[i]).UseVisualStyleBackColor = true;
//((Button)button[i]).Visible = true;
//((Button)button[i]).Parent = this;
//position_x += 10;
//position_y += 10;
//((Button)button[i]).BringToFront();
Button b= (Button)button[i];
b.Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
b.Name = "my_button";
b.Size = new Size(100 + position_x, 100 + position_y);
b.TabIndex += 1;
b.Text = "This is my new one.";
b.UseVisualStyleBackColor = true;
b.Visible = true;
b.Parent = this;
position_x += 10;
position_y += 10;
b.BringToFront();
}
}因为提示得好...但是行不通...有这样的想法挺好...性能问题...
以下异常提示...
未处理的“System.NullReferenceException”类型的异常出现在 WindowsFormsApplication1.exe 中。其他信息: 未将对象引用设置到对象的实例。
不是...是单击按钮后...就会生成...10个大小不同...坐标X,Y递加10,Z轴递加的10个button你可以COPY到自己机子试试的啊...
{
Button b = new Button();
b.Location = new System.Drawing.Point(211 + position_x, 134 + position_y);
b.Name = "my_button";
b.Size = new Size(100 + position_x, 100 + position_y);
b.TabIndex += 1;
b.Text = "This is my new one.";
b.UseVisualStyleBackColor = true;
b.Visible = true;
b.Parent = this;
position_x += 10;
position_y += 10;
b.BringToFront();
button[i] = b;
}