已阅读5页,还剩37页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
MiniMusic播放器 注 课件和视频版权归作者所有 未经许可不准上传 传播 商用 作者 吴鹏 邮箱 422457601 电话正版视频 接下来我将用认真 严谨 诚恳 专业的态度和大家一起学习这个播放器的制作 将带领大家从无到有 完整的编写一个酷酷的播放器 手写每一行代码 讲述每一个关键技术 现在很多书籍内容很多 做出来的东西却粗制滥造 结尾的都会加一句 进一步需要读者自己完善 有时候我就在想有没有一本写完整的书 真是一堆垃圾 这个酷酷的播放器是开源网上的代码演变而来 然后我尽了所有知道的知识去完善它 希望能给学习C 朋友 带来帮助 介绍 第一节窗体设计 1 无边框窗体2 无边框窗体拖动3 无边框阴影效果4 自定义最小化按钮 最大化按钮5 窗体换皮肤6 窗体透明度调节7 鼠标停留提示功能8 窗体淡入淡出效果 1 1 无边框窗体 1 点击窗体 属性 外观 FormBorderStyle None2 设置任务栏图标属性 窗口样式 Icon3 背景图片属性 外观 BackgroundImage4 背景图拉伸填充属性 外观 BackgroundImageLayout stretch 效果图 2 无边框窗体拖动 1 调用系统API函数首先引入 usingSystem Runtime InteropServices 2 调用user32 dll两个库函数1 ReleaseCapture 2 SendMessage IntPtrhwdn intwMsg intmParam intlParam 3 在窗体MouseDown中调用两个函数事件 鼠标 MouseDown 代码实现 region无边框拖动publicconstintWM NCLBUTTONDOWN 0 xA1 publicconstintHTCAPTION 0 x02 DllImport user32 dll publicstaticexternboolReleaseCapture DllImport user32 dll publicstaticexternboolSendMessage IntPtrhwdn intwMsg intmParam intlParam privatevoidForm1 MouseDown objectsender MouseEventArgse ReleaseCapture 向Windows发送拖动信息SendMessage this Handle WM NCLBUTTONDOWN HTCAPTION 0 endregion 3 窗体阴影效果 1 调用系统API函数首先引入 usingSystem Runtime InteropServices 2 调用user32 dll两个库函数1 SetClassLong IntPtrhwnd intnIndex intdwNewLong 2 GetClassLong IntPtrhwnd intnIndex 3 在窗体初始化函数InitializeComponent 后调用SetClassLong this Handle GCL STYLE GetClassLong this Handle GCL STYLE CS DropSHADOW 代码实现 region窗体阴影效果constintCS DropSHADOW 0 x20000 constintGCL STYLE 26 声明Win32API DllImport user32 dll publicstaticexternintSetClassLong IntPtrhwnd intnIndex intdwNewLong DllImport user32 dll publicstaticexternintGetClassLong IntPtrhwnd intnIndex endregionpublicForm1 InitializeComponent API函数加载 实现窗体边框阴影效果SetClassLong this Handle GCL STYLE GetClassLong this Handle GCL STYLE CS DropSHADOW 效果图 4 自定义关闭 最小化按钮 1 拖入两个Label 2 响应Label的 事件 操作 Click事件 鼠标 MouseLeave事件 鼠标 MouseMove3 设置属性的 属性 外观 ForeColor While属性 外观 BackColor Transparent属性 外观 Name Closes 代码实现 region关闭按钮实现privatevoidClose Click objectsender EventArgse Application Exit privatevoidClose MouseLeave objectsender EventArgse Closes ForeColor Color White privatevoidClose MouseMove objectsender MouseEventArgse Closes ForeColor Color Black endregion 效果图 用同样的方法实现最小化 皮肤按钮 1 拖入两个Label 2 响应Label的 事件 操作 Click事件 鼠标 MouseLeave事件 鼠标 MouseMove3 设置属性的 属性 外观 ForeColor While属性 外观 BackColor Transparent属性 外观 Name Skin Small Skin代码实现 region关闭按钮实现privatevoidSkin MouseLeave objectsender EventArgse Skin ForeColor Color White privatevoidSkin MouseMove objectsender MouseEventArgse Skin ForeColor Color Black endregion Small代码实现 region关闭按钮实现privatevoidSmall Click objectsender EventArgse this WindowState FormWindowState Minimized privatevoidSmall MouseLeave objectsender EventArgse Small ForeColor Color White privatevoidSmall MouseMove objectsender MouseEventArgse Small ForeColor Color Black endregion 效果图 5 窗体换肤 1 拖入1个panel 6个picturebox 2 响应Skin的 事件 操作 Click3 设置panel属性的 属性 外观 BackColor Transparent属性 设计 Name pskin属性 行为 Visible False3 设置6个pictureboxd属性的 属性 外观 BackColor Transparent属性 外观 BorderStyle FixedSingle属性 外观 Image 属性 行为 SizeMode StretchImage SkinClick代码实现 region关闭按钮实现privatevoidSkin Click objectsender EventArgse if skins false pskin Visible true pskin为panel的Namepskin可见skins true else pskin Visible false pskin不可见skins false endregion 设计效果图 运行效果图 5 窗体系统换肤功能实现 1 换肤实际就是将自定义图片赋给窗体的 属性 外观 BackgroundImage2 响应pskin中前5个picturebox的click事件 事件 操作 Click3 资源中在代码中调用 Properties Resources XXX4 picturebox6自定义图片载入后面介绍 Picturebox1 picturebox2 3 4 5相同 代码实现 region关闭按钮实现privatevoidpictureBox1 Click objectsender EventArgse this BackgroundImage Properties Resources 0 privatevoidpictureBox2 Click objectsender EventArgse this BackgroundImage Properties Resources 4 endregion 系统皮肤效果图 窗体自定义图片换肤功能实现 1 响应pskin中第6个picturebox的click事件 事件 操作 Click2 创建文件夹需引入 usingSystem IO 3 以文件格式载入图片 Image FromFile stringpath 3 实现原理 1 创建Background文件夹保存自定义皮肤图片2 弹出文件选择对话框OpenFileDialog3 将选中图片拷贝到Background文件夹4 载入图片赋值给窗体BackgroundImage属性 自定义图片换肤代码实现1 privatevoidpictureBox6 Click objectsender EventArgse if Directory Exists Background false 不存在Background文件夹 Directory CreateDirectory Background OpenFileDialogof1 newOpenFileDialog of1 InitialDirectory C of1 Filter png png jpg jpg bmp bmp of1 RestoreDirectory true of1 FilterIndex 1 if of1 ShowDialog DialogResult OK picfile of1 FileName picName of1 SafeFileName try File Copy picfile string Format Background 0 picName catch Exception this BackgroundImage Image FromFile string Format Background 0 picName 自定义图片换肤代码实现2 else OpenFileDialogof newOpenFileDialog of InitialDirectory c of Filter png png jpg jpg bmp bmp of RestoreDirectory true of FilterIndex 1 if of ShowDialog DialogResult OK picfile of FileName picName of SafeFileName try File Copy picfile string Format Background 0 picName catch Exception this BackgroundImage Image FromFile string Format Background 0 picName 自定义皮肤效果图 6 窗体透明度调节 受不了自带滑动条呆板的样子这里我们将自定义一个进度条原理 进度条由两个panel空间 一个当做容器panel1 一个当做可变填充块panel2 响应两个panel的鼠标按下事件 获取点击x坐标 根据x大小设定panel2大小达到滑块的效果 两个panel的click都要响应 虽然panel2在panel1内 但鼠标点击panel1时panel2的点击事件是不响应的当鼠标进入控件改变鼠标样式为 手势 Panel1背景色设为透明 panel2背景设为白色 属性 外观 ForeColor Transparent White6 响应消息 1 事件 鼠标 MouseDown2 事件 鼠标 MouseEnter 鼠标变为手势3 事件 鼠标 MouseLeave 鼠标恢复默认7 不透明属性Form Opacity取值0 1超过1当做等于1 panel1 panel2 Panel1 用作容器容器 接收点击事件 Panel2 用作填充块 接收点击事件 填充panel1 Panel1 panel2接收到鼠标点击事件 根据被点击的位置的X坐标来设定Panel2的长度 达到填充的效果 自定义进度条图解原理 容器panel1代码实现 privatevoidpanel1 MouseDown objectsender MouseEventArgse panel2 Size newSize e Location X 5 this Opacity double e Location X 100 privatevoidpanel1 MouseEnter objectsender EventArgse this Cursor System Windows Forms Cursors Hand privatevoidpanel1 MouseLeave objectsender EventArgse this Cursor System Windows Forms Cursors Default 容器panel2代码实现 privatevoidpanel2 MouseDown objectsender MouseEventArgse panel2 Size newSize e Location X 5 this Opacity double e Location X 100 privatevoidpanel2 MouseEnter objectsender EventArgse this Cursor System Windows Forms Cursors Hand privatevoidpanel2 MouseLeave objectsender EventArgse this Cursor System Windows Forms Cursors Default 透明度调节效果图 往窗体拖入一个toolTip控件属相中将多了一个 杂项 在需要提示的控件填写要显示的文字 CLOSES控件 属性 杂项 toolTip1上的toolTip 关闭其他控件同样 7 鼠标停留提示功能 停留效果图 1 连接动态库的AnimateWindow 函数2 响应主窗体的Load Closing事件 事件 行为 FormClosing事件 行为 Load3 在两个事件中调用AnimateWindow 函数就OK了 7 窗体淡入淡出效果 1 原型 AnimateWindow HWNDhwnd DWORDdwTime DWORDdwFlags 2 参数说明 hwnd 窗体句柄dwTime 效果事件dwFlags 效果类型 AnimateWindow说明 AW BLEND 0 x00080000 褪色效果AW CENTER 0 x00
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年甘肃定西陇西县招募文化人才专项服务志愿者17人笔试备考题库及答案解析
- 2026上半年四川事业单位统考眉山市考试招聘328人考试备考题库及答案解析
- 化产车间安全生产隐患排查制度培训
- 2026重庆綦江区綦城人力资源管理有限公司招聘公益性岗位人员2人考试备考试题及答案解析
- 2026年深海稀土资源勘探与开发潜力分析
- XX公司消防演练方案
- 2026四川甘孜州雅江县考调公务员18人笔试模拟试题及答案解析
- 沟槽降水专项施工方案
- 2026四川长虹电子控股集团有限公司招聘税务主管岗位1人考试参考题库及答案解析
- 2026年项目边界识别与基准线情景确定的方法与案例
- 出口海运工厂集装箱货物绑扎加固指南
- 学前儿童家庭与社区教育(学前教育专业)PPT全套完整教学课件
- 电动机检修作业指导书
- TS30测量机器人Geocom中文说明书
- 化工厂监控系统解决方案
- GB/T 3565.1-2022自行车安全要求第1部分:术语和定义
- GB/T 3452.4-2020液压气动用O形橡胶密封圈第4部分:抗挤压环(挡环)
- GB/T 15382-2021气瓶阀通用技术要求
- 公共管理核心与前沿课件
- 磁粉检测技术(ii级)学习培训模板课件
- 新员工跟进转正面谈记录表
评论
0/150
提交评论