C#实践开发_Winform 系列三:飘动窗体

飘动窗体文章目录飘动窗体前言一、结果呈现1. 界面设计2. 运行结果呈现二、源码1.Form.cs2.Form.Designer.cs三、总结前言C#实践开发_Winform 系列第三篇:飘动窗体,掌握l定时器控件使用。一、结果呈现1. 界面设计 窗体界面设计:四个Timer定时器控件(设定Interval值为100,即每隔0.1秒触发事件timer_Tick()),四个label标签(显示功能)。![在这里插入图片描述](https://img-blog.csdnimg.cn
摘要由CSDN通过智能技术生成

飘动窗体



前言

C#实践开发_Winform 系列第三篇:飘动窗体,掌握l定时器控件使用。

一、结果呈现

1. 界面设计

窗体界面设计:四个Timer定时器控件(设定Interval值为100,即每隔0.1秒触发事件timer_Tick()),四个label标签(显示功能)。

在这里插入图片描述

2. 运行结果呈现

在这里插入图片描述

二、源码

1.Form.cs

代码如下(示例):

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

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

        private void Form2_Load(object sender, EventArgs e)
        {
   
            Point p = new Point(0, 240);	//设定窗体初始位置
            this.DesktopLocation = p;
            timer1.Enabled = true;
        }

        private void timer1_Trick(object sender, System.EventArgs e)
        {
   
            Point p = new Point(this.DesktopLocation.X + 1, this.DesktopLocation.Y + 1);
            this.DesktopLocation = p;
            if (p.X == 470 && p.Y == 710)
            {
   
                timer1.Enabled = false;
                timer2.Enabled = true;
                timer3.Enabled = false;
                timer4.Enabled = false;

                label1.Visible = false;
                label2.Visible = true;
                label3.Visible = false;
                label4.Visible = false;
            }
        }

        private void timer2_Trick(object sender, System.EventArgs e)
        {
   
            Point p = new Point(this.DesktopLocation.X + 1, this.DesktopLocation.Y - 1);
            this.DesktopLocation = p;
            if (p.X == 940 && p.Y == 240)
            {
   
                timer1.Enabled = false;
                timer2.Enabled = false;
                timer3.Enabled = true;
                timer4.Enabled = false;

                label1.Visible = false;
                label2.Visible = false;
                label3.Visible = true;
                label4.Visible = false;
            }
        }
        private void timer3_Trick(object sender, System.EventArgs e)
        {
   
            Point p = new Point(this.DesktopLocation.X -1, this.DesktopLocation.Y - 1);
            this
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值