实例介绍
【实例简介】
可以按时叫你吃饭可以控制在桌面上行走等等等等。。。。。。。。。。。。
【实例截图】
【核心代码】
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Media; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using SpeechLib; using System.Threading; namespace 不做单身狗__桌面宠物 { public partial class cw : Form { private string a; bool run = false,bf=false ; SoundPlayer zl; Form1 f = new Form1(); public cw(string str) { InitializeComponent(); this.a = str; TransparencyKey = BackColor; pictureBox1.Focus(); }//构造函数 private void cw_Load(object sender, EventArgs e)//加载宠物 { zheng(); ts.Start(); } #region 宠物动作 public void qian() { if (run == false) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.GetExecutingAssembly(); zl = new SoundPlayer(Properties.Resources.走路); zl.PlayLooping();//循环播放 if (a == "男1") { pictureBox1.Image = Properties.Resources.男1前; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2前; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3前; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1前; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2前; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3前; } run = true; } //pictureBox1.Top = pictureBox1.Top -1; panel1.Top = panel1.Top -1; } public void hou() { if (run == false) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.GetExecutingAssembly(); zl = new SoundPlayer(Properties.Resources.走路); zl.PlayLooping();//循环播放 bf = true; if (a == "男1") { pictureBox1.Image = Properties.Resources.男1后; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2后; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3后; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1后; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2后; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3后; } run = true; } //pictureBox1.Top = pictureBox1.Top 1; panel1.Top =panel1 .Top 1; } public void zuo() { if (run == false) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.GetExecutingAssembly(); zl = new SoundPlayer(Properties.Resources.走路); zl.PlayLooping();//循环播放 bf = true; if (a == "男1") { pictureBox1.Image = Properties.Resources.男1左; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2左; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3左; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1左; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2左; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3左; } run = true; } //pictureBox1.Left = pictureBox1.Left - 1; panel1.Left = panel1.Left - 1; } public void you() { if (run == false) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.GetExecutingAssembly(); zl = new SoundPlayer(Properties.Resources.走路); zl.PlayLooping();//循环播放 bf = true; if (a == "男1") { pictureBox1.Image = Properties.Resources.男1右; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2右; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3右; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1右; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2右; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3右; } run = true; } //pictureBox1.Left = pictureBox1.Left 1; panel1.Left = panel1.Left 1; } public void zheng() { if (a == "男1") { pictureBox1.Image = Properties.Resources.男1正; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2正; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3正; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1正; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2正; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3正; } } public void fa() { if (run == false) { System.Reflection.Assembly assembly; assembly = System.Reflection.Assembly.GetExecutingAssembly(); zl = new SoundPlayer(Properties.Resources.Q); zl.PlayLooping();//循环播放 bf = true; if (a == "男1") { pictureBox1.Image = Properties.Resources.男1法; } if (a == "男2") { pictureBox1.Image = Properties.Resources.男2法; } if (a == "男3") { pictureBox1.Image = Properties.Resources.男3法; } if (a == "女1") { pictureBox1.Image = Properties.Resources.女1法; } if (a == "女2") { pictureBox1.Image = Properties.Resources.女2法; } if (a == "女3") { pictureBox1.Image = Properties.Resources.女3法; } run = true; } } #endregion #region 拖动宠物 //是否正在拖拽 bool isDrag = false; //鼠标按下坐标(control控件的相对坐标) Point mouseDownPoint = Point.Empty; //将被拖动的控件 private Control control; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { isDrag = true; control = panel1; //pictureBox1; if (e.Button == MouseButtons.Left) { mouseDownPoint = panel1.Location; } } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (isDrag) { Point mousePos = new Point(control.Location.X, control.Location.Y); mousePos.Offset(e.X, e.Y); mousePos.X -= this.control.Width / 7; mousePos.Y -= this.control.Height / 7; control.Location = mousePos; } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (isDrag) { isDrag = false; } } #endregion private void cw_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)//执行动作 { if (e.KeyValue == 87) { qian(); } if (e.KeyValue == 83) { hou (); } if (e.KeyValue == 65) { zuo (); } if (e.KeyValue == 68) { you (); } if (e.KeyValue == 81) { fa (); } if (e.KeyValue == 27) {Application.Exit();ts.Abort(); } } private void cw_KeyUp(object sender, KeyEventArgs e)//结束动作 { zheng(); if (bf == true) { zl.Stop();} run = false ; } Thread ts = new Thread(Function.Ts);//按时提示功能 private void pictureBox1_DoubleClick(object sender, EventArgs e)//对话 { SpVoice voice = new SpVoice(); voice.Voice = voice.GetVoices(string.Empty, string.Empty).Item(0); voice.Speak("亲爱的,好期待和您讲话啊!再耐心等等吧!等我爸爸给我这个功能!", SpeechVoiceSpeakFlags.SVSFDefault); } } }
标签: 桌面宠物
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)
支持(0) 盖楼(回复)