从C#中的一个点开始增长 [英] Growing line from a point in C#

查看:61
本文介绍了从C#中的一个点开始增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧


我真的陷入了编写一段代码的困境。我想创建一个带有按钮的表单。当点击按钮时,从表格的某个点(200,200)开始说明的一条线应该向上增长。

我编写的代码

命名空间ConsoleApplication1 < br $>
{

class Program:Form

{

int x = 202;

int y = 202;

public Program()

{

this.Size = new Size(400,400);

this.BackColor = Color.Wheat;

this.StartPosition = FormStartPosition.CenterScreen;

按钮b1 =新按钮();

this.Controls.Add(b1);

b1.Click + = new EventHandler(b1_Click);



}

protected override void OnPaint(PaintEventArgs e)

{

Graphics g = e.Graphics;

Brush brush = new SolidBrush( Color.Black);

钢笔=新笔(刷子,4);

g.DrawLine(笔,200,200,200,201);



}

protected void b1_Click(object sender,EventArgs e)

{


x = 200;

y = 20;


}


按钮不起作用!任何建议??

谢谢你在高级

解决方案

这里有一些逻辑/编码错误。

让我们点击你的按钮开始:

展开 | 选择 | Wrap | 行号



这里有许多逻辑/编码的falicies。


让我们从你的按钮点击开始:



我也试过线程,你想看看代码吗?


class Program:Form

{

int x1 = 202;

int y1 = 202;


int y2;

private Thread animationThread ;


公共计划()

{

this.Size = new Size(400,400);

this.BackColor = Color.Wheat;

this.StartPosition = FormStartPosition.CenterScreen;

按钮b1 =新按钮();

this.Controls.Add(b1);

b1.Click + = new EventHandler(b1_Click);

animationThread = new Thread(new ThreadStart(growingLine));


}

protected override void OnPaint(PaintEventArgs e)

{

Graphics g = e。图形;

刷刷=新的SolidBrush(Color.Black);

钢笔=新钢笔(刷子,4);

g。 DrawLine(笔,200,200,x1,y2);



}

protected void b1_Click(object sender,EventArgs e)

{


animationThread.Start();

}


public void growingLine()

{

y1 = y2;

y2 ++;

Invalidate();

Thread.Sleep(40);

}


< blockquote>对不起,我正在使用相关信息编辑我的帖子,请向上滚动并查看。


Hi every one

I have really got stuck in writting a piece of code.I suppose to create a form with a button on it. when ever button is clicked, a line which is stated from a certain point of the form(200,200) should grow upward.
its the code i have written
namespace ConsoleApplication1
{
class Program :Form
{
int x=202;
int y=202;
public Program()
{
this.Size = new Size(400, 400);
this.BackColor = Color.Wheat;
this.StartPosition = FormStartPosition.CenterScreen;
Button b1 = new Button();
this.Controls.Add(b1);
b1.Click+=new EventHandler(b1_Click);


}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(brush, 4);
g.DrawLine(pen, 200, 200, 200, 201);


}
protected void b1_Click(object sender, EventArgs e)
{

x = 200;
y = 20;

}


button doesn''t work! any suggestions??
thank u in advanced

解决方案

There are a few logical/coding errors here.

Lets start with your button click:

Expand|Select|Wrap|Line Numbers


There are many logical/coding falicies here.

Lets start with your button click:

I tried threads as well, do u wantto take a look at the code?

class Program :Form
{
int x1=202;
int y1=202;

int y2;
private Thread animationThread;

public Program()
{
this.Size = new Size(400, 400);
this.BackColor = Color.Wheat;
this.StartPosition = FormStartPosition.CenterScreen;
Button b1 = new Button();
this.Controls.Add(b1);
b1.Click+=new EventHandler(b1_Click);
animationThread = new Thread(new ThreadStart(growingLine));

}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush brush = new SolidBrush(Color.Black);
Pen pen = new Pen(brush, 4);
g.DrawLine(pen, 200, 200, x1, y2);


}
protected void b1_Click(object sender, EventArgs e)
{

animationThread.Start();
}

public void growingLine()
{
y1 = y2;
y2++;
Invalidate();
Thread.Sleep(40);
}


Sorry, I was in the middle of editing my post with the relevant information, please scroll up and have a look.


这篇关于从C#中的一个点开始增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆