编程教程
你的位置: 中国个人站长站 -- 网络编程 -- ASP教程 -- 教程正文 c#写的,供学习WinForms的鼠标事件和使用GDI+
推荐位

c#写的,供学习WinForms的鼠标事件和使用GDI+

中国个人站长站 ASP教程 点击数: 更新时间:2007-7-30 8:15:12
前几天没事,写了一个小程序,可以用于学习C#。

程序使用了VS.NET环境编译,你的机器只要安装了.NET Framework SDK就可以运行。

源码和执行文件可以下载

http://www.wh-adv.com/download/five.zip

你不想下载也可读一下源码(图片资源等需要下载)。

namespace Leimom.FiveChess

{

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.WinForms;

using System.Data;

/// <summary>

/// Summary description for Form1.

/// </summary>

public class FiveForm : System.WinForms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components;

private System.WinForms.ImageList imageListbw;

//define the hot Rectangle

private Rectangle[] pointSquares;

//chess information

private int[] chessTable;

private int nextTurn;

private const int bTurn = 1;

private const int wTurn = 2;

private Stack chessIndex;

public FiveForm()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

chessIndex = new Stack();

nextTurn = bTurn;

chessTable = new int[225];

pointSquares = new Rectangle[225];

Size size = new Size(18,18);

int x = 0;

int y = 0;

for(int i = 0;i < 225;i++)

{

x = i%15;

y = i/15;

pointSquares[i].Size = size;

pointSquares[i].Offset(9+x*20,6+y*20);

chessTable[i] = 0;

}

}


protected override void OnPaint(PaintEventArgs e)

{

//you may paint

Graphics g = e.Graphics;

}

protected override void OnMouseDown(System.WinForms.MouseEventArgs e)

{

switch( e.Button )

{

//take left button down

case MouseButtons.Left:

OnLButtonDown(new Point(e.X,e.Y));

break;

//take right button down

case MouseButtons.Right:

OnRButtonDown(new Point(e.X,e.Y));

break;

}

base.OnMouseDown(e);

}

private void OnLButtonDown(Point p)

{

int nPos = GetRectID(p);

//click hot Rectangle witch have no c

[1] [2] [3] [4] 下一页

教程录入:swh    责任编辑:swh 
个人站长站与你风雨同舟!
本站所提供的资源均来源于互联网,如有侵权行为,请与本站管理员联系,我们会第一时间删除!
·如果您发现《c#写的,供学习WinForms的鼠标事件和使用GDI+》文章有错误,也请通知我们修改!
联系邮箱chinageren#126.com,谢谢支持!
站内搜索:
广告服务 | 友情链接 | 联系我们 | 免责声明 | 用户留言 | 网站导航
版权所有:中国个人站长站 2007-2008 未经授权禁止复制或建立镜像 客服QQ号:112731235
copyright © 2007-2008 www.ChinaGeRen.com online services. all rights reserved. 苏ICP备05000059号