您的位置:首页 > 编程语言 > C#

(转)c# winform 键盘按键控制操作移动控件,linkLabel,获取按键值,一个俄罗斯方块源码

2011-03-28 10:31 357 查看
调用start方法启动一个默认的Internet浏览器

System.Diagnostics.Process.Start("http://www.baidu.com");


Form1 按键移动控件

C#代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace man100
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public static int buChang = 5;

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
//MessageBox.Show(e.KeyValue.ToString());//用来找按键int值

//MessageBox.Show(e.KeyCode.ToString());//用来找按键英文值

if (e.KeyCode.ToString().Equals("Left"))//左
{
//MessageBox.Show("左");
//label1.Location = new Point(0,0);

int x_ZuoBiao = label1.Location.X;
int y_ZuoBiao = label1.Location.Y;

if (label1.Location.X < 15)
{
label1.Location = new Point(x_ZuoBiao, y_ZuoBiao);
return;
}

label1.Location = new Point(x_ZuoBiao - buChang, y_ZuoBiao);
}
else if (e.KeyCode.ToString().Equals("Up"))//上
{
//MessageBox.Show("上");
int x_ZuoBiao = label1.Location.X;
int y_ZuoBiao = label1.Location.Y;

if (label1.Location.Y < 15)
{
label1.Location = new Point(x_ZuoBiao, y_ZuoBiao);
return;
}

label1.Location = new Point(x_ZuoBiao, y_ZuoBiao - buChang);
}
else if (e.KeyCode.ToString().Equals("Right"))//右
{
//MessageBox.Show("右");
int x_ZuoBiao = label1.Location.X;
int y_ZuoBiao = label1.Location.Y;

if (label1.Location.X > 265)
{
label1.Location = new Point(x_ZuoBiao, y_ZuoBiao);
return;
}

label1.Location = new Point(x_ZuoBiao + buChang, y_ZuoBiao);
}
else if (e.KeyCode.ToString().Equals("Down"))//下
{
//MessageBox.Show("下");
int x_ZuoBiao = label1.Location.X;
int y_ZuoBiao = label1.Location.Y;

if (label1.Location.Y > 395)//超出界限就不动
{
label1.Location = new Point(x_ZuoBiao, y_ZuoBiao);
return;
}

label1.Location = new Point(x_ZuoBiao, y_ZuoBiao + buChang);
}
}
}
}


Form2
linkLabel用法
C#代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace man100
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();

this.linkLabel1.Text = "黑色头发 百度 Google Yahoo";
this.linkLabel1.Links.Add(0, 4, "http://www.heisetoufa.javaeye.com");//第一个参数设置下划线从哪里开始,第二个参数设置下划线占几个长度
this.linkLabel1.Links.Add(5, 2, "http://www.baidu.com");
this.linkLabel1.Links.Add(8, 6, "http://www.google.com");
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.linkLabel1.Links[linkLabel1.Links.IndexOf(e.Link)].Visited = true;
string target = e.Link.LinkData as string;
if (target != null && target.StartsWith("http://"))
{
System.Diagnostics.Process.Start(target);
}
else
{
MessageBox.Show("Item clicked: " + target);
}
}

}
}


转自黑色头发:http://heisetoufa.javaeye.com/blog/348167
源码下载:
man100.rar (34.7 KB)

c#俄罗斯方块源码.rar (168 KB)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐