(转)c# winform 键盘按键控制操作移动控件,linkLabel,获取按键值,一个俄罗斯方块源码
2011-03-28 10:31
357 查看
调用start方法启动一个默认的Internet浏览器
Form1 按键移动控件
C#代码
Form2
linkLabel用法
C#代码
转自黑色头发:http://heisetoufa.javaeye.com/blog/348167
源码下载:
man100.rar (34.7 KB)
c#俄罗斯方块源码.rar (168 KB)
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)
相关文章推荐
- c# 键盘控制控件的移动
- C# 在一个winform中控制另一个winform中的控件
- Java.awt.Robot 控制鼠标移动、键盘按键等输入操作
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- C# 在一个winform中控制另一个winform中的控件
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- 一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)
- winform学习之-----关于按键操作的一些小知识(如何获取焦点所在的当前控件)20160623
- c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
- Android ListView 中子控件无法获取焦点的解决方法(主要针对键盘操作)
- c#有关winform的两个代码片段(多线程操作窗体控件与窗体淡入淡出效果)
- c#+Winform实现自定义的“复制、粘贴”右键快捷菜单,多个控件共享使用一个右键菜单
- C# winform datagridview中如何实现鼠标右键点击一行数据出现一个带有删除的菜单,并能执行删除操作?
- js获取键盘时间或禁止按键操作
- C#使用Xamarin开发可移植移动应用终章(11.获取设备信息与常用组件,开源一个可开发模版.)
- [Winform]通过钩子监控键盘操作和鼠标移动
- C# 下面的代码示例演示如何结束异步操作以获取请求的流,然后开始一个请求以获取响应。....
- Unity3D获取当前键盘按键及Unity3D鼠标、键盘的基本操作