首页 新闻 赞助 找找看

已定义了一个名为“InitializeComponent”的具有相同参数类型的成员,如何解决?

0
悬赏园豆:10 [已解决问题] 解决于 2012-01-28 21:21

C#代码:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace paint1
{
public partial class Form1 : Form
{
private Graphics g;
//创建Graphics实例
private Rectangle rc;
//定义Rectangle全局变量
private void InitializeComponent()
{
this.button1=new System.Windows.Forms.Button();
this.button2=new System.Windows.Forms.Button();
this.button3=new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location=new System.Drawing.Point(36,182);
this.button1.Name="Button1";
this.button1.Size=new System.Drawing.Size(75,32);
this.button1.TabIndex=0;
this.button1.Text="画椭圆";
this.button1.Click+=new System.EventHandler(this.button1_Click);
this.button2.Location=new System.Drawing.Point(124,182);
this.button2.Name="Button2";
this.button2.Size=new System.Drawing.Size(75,32);
this.button2.TabIndex=1;
this.button2.Text="填充";
this.button2.Click+=new System.EventHandler(this.button2_Click);
this.button3.Location=new System.Drawing.Point(210,184);
this.button3.Name="Button3";
this.button3.Size=new System.Drawing.Size(75,32);
this.button3.TabIndex=2;
this.button3.Text="画字";
this.button3.Click+=new System.EventHandler(this.button3_Click);
this.AutoscaleBaseSize=new System.Drawing.Size(6,14);
this.ClientSize=new System.Drawing.Size(336,251);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle=System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox=false;
this.Name="Form1";
this.Text="Visual C#基本绘图方法";
this.ResumeLayout(false);
this.g=Graphics.FromHwnd(this.Handle);
//从指定的句柄中初始化Graphics实例
this.rc=new Rectangle(10,10,250,150);
//初始化Rectangle结构
}

private void button1_Click(object sender, EventArgs e)
{
Pen pn = new Pen(Color.Blue, 2);
//创建一个画笔
pn.Color = Color.Red;
//定义色彩
g.DrawEllipse(pn,rc);
}

private void button2_Click(object sender, EventArgs e)
{
LinearGradientBrush br = new LinearGradientBrush(rc,Color.Blue,Color.Black,LinearGradientMode.BackwardDiagonal);
//定义一个刷子
g.FillEllipse(br,rc);
//用定义的刷子填充指定区域
}

private void button3_Click(object sender, EventArgs e)
{
Font ft = new Font("宋体", 14);
//定义一个字体
SolidBrush br = new SolidBrush(Color.Yellow);
//定义一个刷子
g.DrawString("Hello World", ft, br, 50, 50);
//在程序窗体的(50,,50)区域,用给定的刷子,给定的字体及大小,绘制文本
}
}
}

巴索罗缪库玛的主页 巴索罗缪库玛 | 初学一级 | 园豆:48
提问于:2012-01-25 09:45
< >
分享
最佳答案
1

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace paint1
{
public partial class Form1 : Form
{
private Graphics g;
//创建Graphics实例
private Rectangle rc;
//定义Rectangle全局变量

Button button1=new Button();

Button button2=new Button();

Button button3=new Button();
public Form1()
{
InitializeComponent();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(36, 182);
this.button1.Name = "Button1";
this.button1.Size = new System.Drawing.Size(75, 32);
this.button1.TabIndex = 0;
this.button1.Text = "画椭圆";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Location = new System.Drawing.Point(124, 182);
this.button2.Name = "Button2";
this.button2.Size = new System.Drawing.Size(75, 32);
this.button2.TabIndex = 1;
this.button2.Text = "填充";
this.button2.Click += new System.EventHandler(this.button2_Click);
this.button3.Location = new System.Drawing.Point(210, 184);
this.button3.Name = "Button3";
this.button3.Size = new System.Drawing.Size(75, 32);
this.button3.TabIndex = 2;
this.button3.Text = "画字";
this.button3.Click += new System.EventHandler(this.button3_Click);
//this.AutoscaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(336, 251);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Visual C#基本绘图方法";
this.ResumeLayout(false);
this.g = Graphics.FromHwnd(this.Handle);
//从指定的句柄中初始化Graphics实例
this.rc = new Rectangle(10, 10, 250, 150);
//初始化Rectangle结构
}
private void button1_Click(object sender, EventArgs e)
{
Pen pn = new Pen(Color.Blue, 2);
//创建一个画笔
pn.Color = Color.Red;
//定义色彩
g.DrawEllipse(pn, rc);
}
private void button2_Click(object sender, EventArgs e)
{
LinearGradientBrush br = new LinearGradientBrush(rc, Color.Blue, Color.Black, LinearGradientMode.BackwardDiagonal);
//定义一个刷子
g.FillEllipse(br, rc);
//用定义的刷子填充指定区域
}
private void button3_Click(object sender, EventArgs e)
{
Font ft = new Font("宋体", 14);
//定义一个字体
SolidBrush br = new SolidBrush(Color.Yellow);
//定义一个刷子
g.DrawString("Hello World", ft, br, 50, 50);
//在程序窗体的(50,,50)区域,用给定的刷子,给定的字体及大小,绘制文本
}
}
}

收获园豆:10
鸿雁@锦鲤 | 菜鸟二级 |园豆:220 | 2012-01-26 00:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册