标题:请指教!谢谢!
只看楼主
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
 问题点数:0 回复次数:4 
请指教!谢谢!

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace GDI
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public int a,b,MoveX,MoveY;
public bool flag=false;
private System.Windows.Forms.Button button1;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(flag ==true)
{
Graphics graphics=this.CreateGraphics ();
graphics.Clear (Color.Yellow );
Pen red=new Pen (Color.Red ,3);
graphics.DrawLine (red,a,b,MoveX,MoveY);

}

}

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
a=e.X;
b=e.Y ;

}

private void button1_Click(object sender, System.EventArgs e)
{
flag =true;

}

private void button1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
MoveX=e.X;
MoveY=e.Y ;
}
}
}
我的想法是让鼠标在窗体是画一条线,用a,b记录起点坐标,movex,movey记录重点坐标,点击按扭画出图形,坐标都能记录下来,就是画不出图形,请帮忙!

搜索更多相关主题的帖子: 指教 
2007-06-29 16:48
jockey
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:977
专家分:52
注 册:2005-12-4
得分:0 
private void button1_Click(object sender, System.EventArgs e)
{
flag =true;
Form1_Paint(null,null); //把这句话加上
}


2007-06-29 17:06
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 
谢谢!我试一下再说

真的想象风一样去流浪!
2007-06-29 17:31
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 
谢谢了,画是能画出来,但新的问题又来了。我明明是从右上角到左下角的直线,怎么都是从左上角到右下角的了,帮我看哈是不是那个鼠标坐标有问题?

真的想象风一样去流浪!
2007-06-29 17:38
随风云
Rank: 1
等 级:新手上路
威 望:1
帖 子:263
专家分:0
注 册:2007-6-28
得分:0 
搞定了,达到了预想的目标。还不错,谢谢你的帮忙哈    !

真的想象风一样去流浪!
2007-06-29 18:25



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-151382-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.960485 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved