橡皮区矩形 CRectTracker C# 实现

王朝vc·作者佚名  2006-01-17
宽屏版  字体: |||超大  

橡皮区矩形 CRectTracker C# 实现

作者:fanjunxing

下载源代码

本文要求读者熟悉 C#

开发环境: Visual Studio .NET 2003 Windows

2000

测试环境:Windows 2000

更新记录:2004.4.7 第一次更新

使用许可:代码是否免费使用

功能介绍:

在MFC中CRectTracker是一个很有用的类,可最近学习C#时,发现没有,于是就从MFC转换了一个供大家享用。

使用该类比较简单,几乎和 MFC中 的 CRectTracker 一样,在MDI中:

public class CReportDoc

{...

public CRectTracker m_tracker=null;

public CReportDoc(MainWindow mainWin)

{ ...

m_tracker=new CRectTracker();

m_tracker.m_rect.X = 10;

m_tracker.m_rect.Y = 10;

m_tracker.m_rect.Width = 91;

m_tracker.m_rect.Height = 91;

...

}

...

}

相应的在VIEW类里面

public class CReportView : System.Windows.Forms.Form

{

...

private void InitializeComponent()

{

...

this.MouseDown +=

new System.Windows.Forms.MouseEventHandler(this.CReportView_MouseDown);

this.Paint +=

new System.Windows.Forms.PaintEventHandler(this.PaintHandler);

// 因为C#中不支持OnSetCursor所以只好用MouseMove替代了,

// 各位兄台还有更好的方法,请告之

this.MouseMove+=new MouseEventHandler(CReportView_MouseMove);

}

private void PaintHandler(Object sender, PaintEventArgs e)

{

Graphics gs=e.Graphics;

//其余的画图代码

myDoc.m_tracker.OnDraw(gs);

}

private void CReportView_MouseDown(object sender,

MouseEventArgs e)

{

if(e.Button==MouseButtons .Left)

{

Rectangle rectSave=new Rectangle();

Point pt=new Point(e.X,e.Y);

myDoc.m_tracker.GetTrueRect(ref rectSave);

if (myDoc.m_tracker.HitTest(pt)

结束。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有