0
点赞
收藏
分享

微信扫一扫

一键PDF水印添加工具

booksmg2014 2024-05-04 阅读 19
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;
举报

相关推荐

0 条评论