自由是冠军

制作软件,并以此获得自由!

橡皮筋

橡皮筋

参见:GDI+编程10个基本技巧”

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;


using System.Runtime.InteropServices;


namespace GDIPlus

{

/// <summary>

/// Form5 µÄժҪ˵Ã÷¡£

/// </summary>

public class Form5 : System.Windows.Forms.Form

{

/// <summary>

/// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£

/// </summary>

private System.ComponentModel.Container components = null;


public Form5()

{

//

// 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()

{

//

// Form5

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Name = "Form5";

this.Text = "Form5";

this.Load += new System.EventHandler(this.Form5_Load);


}

#endregion


private void Form5_Load(object sender, System.EventArgs e)

{

}


[DllImport("gdi32.dll")]

private static extern bool SetROP2(IntPtr hdc, int nDrawMode);


[DllImport("gdi32.dll")]

private static extern bool Rectangle(IntPtr hdc, int x1, int y1, int x2, int y2);


private int m_StartX, m_StartY;

private int m_EndX, m_EndY;

private int m_Step = 0;


protected override void OnMouseDown(MouseEventArgs e)

{

Graphics g = this.CreateGraphics();

IntPtr hdc = g.GetHdc();

m_Step += 1;

SetROP2(hdc, 10);


if(m_Step == 1)

{

this.m_StartX = e.X;

this.m_StartY = e.Y;

this.m_EndX = e.X;

this.m_EndY = e.Y;

}

else if(this.m_Step == 2)

{

Rectangle(hdc, this.m_StartX, this.m_StartY, e.X, e.Y);

Rectangle(hdc, this.m_StartX, this.m_StartY, e.X, e.Y);


this.m_Step = 0;

}


g.ReleaseHdc(hdc);


//base.OnMouseDown (e);

}


protected override void OnMouseMove(MouseEventArgs e)

{

Graphics g = this.CreateGraphics();

int prex, prey;


if(this.m_Step == 1)

{

IntPtr hdc = g.GetHdc();

prex = this.m_EndX;

prey = this.m_EndY;

SetROP2(hdc, 10);

Rectangle(hdc, this.m_StartX, this.m_StartY, prex, prey);

Rectangle(hdc, this.m_StartX, this.m_StartY, e.X, e.Y);

this.m_EndX = e.X;

this.m_EndY = e.Y;

g.ReleaseHdc(hdc);

}


//base.OnMouseMove (e);

}


protected override void OnPaint(PaintEventArgs e)

{

Graphics g = e.Graphics;

g.FillRectangle(Brushes.White, this.ClientRectangle);


//base.OnPaint (e);

}


}

}

参见:GDI+编程10个基本技巧”







阅读更多
个人分类: .net编程全景
上一篇(改进)UserControl的单击事件对鼠标左右键都有效,怎样使之像按钮控件那样只对鼠标左键敏感?
下一篇使用NUnit进行浮点数测试准则
想对作者说点什么? 我来说一句

用tc实现橡皮筋直线

2008年10月09日 2KB 下载

MFC橡皮筋画线程序设计

2012年10月22日 83KB 下载

QT4 橡皮筋线的绘制

2010年07月15日 5.32MB 下载

C#橡皮筋技术画矩形和线

2017年08月10日 67KB 下载

OPENGL橡皮筋矩形和折线

2010年11月22日 431KB 下载

没有更多推荐了,返回首页

关闭
关闭