另外再赠送一个100分的问题,也是另我头痛了两个月呀,只好用其它方法取而代之
http://community.csdn.net/Expert/topic/3198/3198298.xml?temp=.3265955

解决方案 »

  1.   

    顶你一下,GDI+我也就会画点简单的统计线表
      

  2.   

    是否这样?
    新建一个WinForm项目 把所有代码 换成下面的代码试试看!using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Drawing.Drawing2D;namespace 作图2
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    private Graphics gp;
    private Point startP;
    private Point endP;
    private float[] dot1,dot2;
    private System.Timers.Timer timer1;
    private bool ft;
    private bool dispBJ;
    private bool down; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    gp=this.CreateGraphics();
    dot1 =new float [] {2,3,3,3,2,3};
    dot2= new float [] {3,3,2,2,3,3};
    ft=true;
    dispBJ=false;
    down =false;
    //
    // 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()
    {
    this.timer1 = new System.Timers.Timer();
    ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
    // 
    // timer1
    // 
    this.timer1.Enabled = true;
    this.timer1.Interval = 200;
    this.timer1.SynchronizingObject = this;
    this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(826, 493);
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
    this.Load += new System.EventHandler(this.Form1_Load);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit(); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
             startP.X=e.X;
         startP.Y=e.Y;
         dispBJ=false;
     gp.Clear(this.BackColor);
         down =true;
    } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    endP.X=e.X;
    endP.Y=e.Y;
    dispBJ=true;
    down =false;
    } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
    if (!dispBJ) return ;
    Pen pp= new Pen(Color.Red,1);
    if (ft)
    {
    ft=false;
    pp.DashPattern=dot1;

    }
    else
    {
    pp.DashPattern=dot2;
    ft=true;

    }
    pp.DashStyle=DashStyle.Custom;
    gp.Clear(this.BackColor);
    gp.DrawRectangle(pp,startP.X,startP.Y,endP.X-startP.X ,endP.Y-startP.Y  );
    } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if (down)
    {
    endP.X=e.X;
    endP.Y=e.Y;
    dispBJ=true;
    }
    } private void Form1_SizeChanged(object sender, System.EventArgs e)
    {
    gp.Dispose();
    gp=this.CreateGraphics();
    }
    }
    }
      

  3.   

    aQ44(阿Q叔叔) ,我试了你的代码,效果挺好的,但就是它会把背景图清除,而且会让人感觉机器非常缓慢
      

  4.   

    我们也在模仿QQ里面的抓图。
    功能基本上都实现了。
    如果有背景图片,就是如你所说的画矩形有点慢,而且鼠标移动快时,也有点闪。
    如果没有背景图片,速度效果跟QQ上抓图不相上下。
    但是完全可以画出来。而且没有用API。
    如果有好的画法,乐意与你共享。
    如果你有什么好的方法,乐意与我们共享吗?
    期待好的回音……
      

  5.   

    要加背景为改一下就可以。。
    我在我的及其上运行不觉得慢(p4 2.0)
    蚂蚁线,我是用timer控制可能慢,你可以用 其他方法控制(如线程,我没有试过,只是想法),这里只是达到一个效果,性能你自己优化!using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Drawing.Drawing2D;namespace 作图2
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    private Graphics gp;
    private Point startP;
    private Point endP;
    private float[] dot1,dot2;
    private System.Timers.Timer timer1;
    private bool ft;
    private bool dispBJ;
    private System.Diagnostics.Process process1;
    private System.Windows.Forms.PictureBox pictureBox1;
    private bool down; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent();
    //gp=this.CreateGraphics();
    gp=pictureBox1.CreateGraphics();

    dot1 =new float [] {2,3,3,3,2,3};
    dot2= new float [] {3,3,2,2,3,3};
    ft=true;
    dispBJ=false;
    down =false;
    //
    // 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()
    {
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
    this.timer1 = new System.Timers.Timer();
    this.process1 = new System.Diagnostics.Process();
    this.pictureBox1 = new System.Windows.Forms.PictureBox();
    ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
    this.SuspendLayout();
    // 
    // timer1
    // 
    this.timer1.Enabled = true;
    this.timer1.Interval = 200;
    this.timer1.SynchronizingObject = this;
    this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
    // 
    // process1
    // 
    this.process1.SynchronizingObject = this;
    // 
    // pictureBox1
    // 
    this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
    this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
    this.pictureBox1.Location = new System.Drawing.Point(0, 0);
    this.pictureBox1.Name = "pictureBox1";
    this.pictureBox1.Size = new System.Drawing.Size(826, 493);
    this.pictureBox1.TabIndex = 0;
    this.pictureBox1.TabStop = false;
    this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
    this.ClientSize = new System.Drawing.Size(826, 493);
    this.Controls.Add(this.pictureBox1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown);
    this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
    this.Load += new System.EventHandler(this.Form1_Load);
    this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp);
    this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
    ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    } private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
             startP.X=e.X;
         startP.Y=e.Y;
         dispBJ=false;
     pictureBox1.Refresh();
         
         
         down =true;
    } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    endP.X=e.X;
    endP.Y=e.Y;
    dispBJ=true;
    down =false;
    } private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
    if (!dispBJ) return ;
    Pen pp= new Pen(Color.Red,1);
    if (ft)
    {
    ft=false;
    pp.DashPattern=dot1;

    }
    else
    {
    pp.DashPattern=dot2;
    ft=true;

    }
    pp.DashStyle=DashStyle.Custom;
    pictureBox1.Refresh();




    gp.DrawRectangle(pp,startP.X,startP.Y,endP.X-startP.X ,endP.Y-startP.Y  );
    } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if (down)
    {
    endP.X=e.X;
    endP.Y=e.Y;
    dispBJ=true;
    }
    } private void Form1_SizeChanged(object sender, System.EventArgs e)
    {
    gp.Dispose();
    //gp=this.CreateGraphics();
    gp=pictureBox1.CreateGraphics();
    }
    }
    }
      

  6.   

    看看这些代码,是用GDI+画的
    public class RubberBandForm : System.Windows.Forms.Form
    { private System.Drawing.Graphics drawingSurface;
            private System.Drawing.Pen erasePen ;
    private System.Drawing.Pen drawPen;
    private System.Drawing.Point ptsStart = new Point();
    private System.Drawing.Point ptsPrevious = new Point(); /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public RubberBandForm()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); drawingSurface = this.CreateGraphics();
    // Pen to erase a previous line
    erasePen = new System.Drawing.Pen(this.BackColor);
    // Pen to draw a new line
    drawPen = new System.Drawing.Pen(Color.Blue); } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } protected override void OnMouseDown(MouseEventArgs e) {
    if(e.Button == MouseButtons.Left) {
    // Store the starting point for your rubber-band line.
    this.ptsStart = new Point(e.X, e.Y);
    // Store the previous end point for your rubber-band line.
    this.ptsPrevious = this.ptsStart;
    }
    base.OnMouseDown(e);
    } protected override void OnMouseMove(MouseEventArgs e) {
    // Check if the left mouse button is pressed.
    if( e.Button == MouseButtons.Left) {
    // Declare a local variable for the current end point of your rubber-band line.
    System.Drawing.Point ptsCurrent = new Point();
    // Store the current end point of your rubber-band line.
    ptsCurrent.X = e.X;
    ptsCurrent.Y = e.Y;
    // Draw your actual rubber-band lines.
    drawingSurface.DrawLine(erasePen, ptsStart.X, ptsStart.Y, ptsPrevious.X, ptsPrevious.Y);
    drawingSurface.DrawLine(drawPen, ptsStart.X, ptsStart.Y, ptsCurrent.X, ptsCurrent.Y);
    // Store the current end point for the next call to OnMouseMove.
    ptsPrevious = ptsCurrent;
    }
    base.OnMouseMove(e);
    }