WPF —— 跑马灯

标签页面

    <Label Width="800" Height="80" Background="Black" VerticalAlignment="Top">
        
    </Label>
    <Label Width="360" Height="40"
    HorizontalAlignment="Left" VerticalAlignment="Top"
    Content="我叫奕泽你记住,天悦小学我最帅!!!" Foreground="Red" FontSize="20"
    Margin="-360,20,0,0"
    Name="l1"
>
    </Label>

    <Button  Width="200" Height="40" Content="点击移动label"  
     Click="Button_Click"
   >
    </Button>

代码界面

定时器函数 bject? sender ;
如果object有的话才去取这个数据,如果这个数据为null 就不取

 double step = 2; // 每次移动的步距
 private void Timer_Tick(object? sender, EventArgs e)
 {
     //if (this.l1.Margin.Left > 800 )
     //{
     //    step = -1;
     //}
     //if(this.l1.Margin.Left < -200)
     //{
     //    step = 1;
     //}

     if (this.l1.Margin.Left > 800 || this.l1.Margin.Left < -360)
     {
         step = -step;
     }
     //修改lable的外边距
     //Thickness 设置外边距的
     //this.l1.Margin.Right 有外边距,
     this.l1.Margin = new Thickness(this.l1.Margin.Left + step,
         this.l1.Margin.Top, this.l1.Margin.Right, this.l1.Margin.Bottom);
 }

点击开始移动label 开启定时器

private void Button_Click(object sender, RoutedEventArgs e)
{
    timer.Start(); // 开启定时器
}

 

timer.Interval = TimeSpan.FromMilliseconds(10); //500ms
timer.Tick += Timer_Tick;

相关推荐

  1. WPF —— 跑马

    2024-05-03 08:26:05       11 阅读
  2. vue跑马

    2024-05-03 08:26:05       35 阅读
  3. 03_led_horse_run_v1 跑马

    2024-05-03 08:26:05       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-03 08:26:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-03 08:26:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-03 08:26:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-03 08:26:05       20 阅读

热门阅读

  1. C语言双向链表快速入门教程

    2024-05-03 08:26:05       14 阅读
  2. 【Godot4.2】EasyTreeData通用解析

    2024-05-03 08:26:05       8 阅读
  3. 数组作为参数和返回值

    2024-05-03 08:26:05       8 阅读
  4. 旅行商问题matlab实现

    2024-05-03 08:26:05       11 阅读
  5. 通讯录(基于单链表)

    2024-05-03 08:26:05       12 阅读
  6. 【toos】工具篇

    2024-05-03 08:26:05       12 阅读
  7. Linux下JVM相关指令详解及案例介绍

    2024-05-03 08:26:05       14 阅读
  8. k8s&&如何写yaml文件

    2024-05-03 08:26:05       9 阅读
  9. 人大金仓数据库的数据分析的方法和工具

    2024-05-03 08:26:05       12 阅读
  10. [HDLBits] Sim/circuit10

    2024-05-03 08:26:05       12 阅读