首页 > 其他分享 >WPF locate discreted points via periodically and set transparency via the alpha,the first parameter

WPF locate discreted points via periodically and set transparency via the alpha,the first parameter

时间:2024-08-05 19:49:27浏览次数:6  
标签:locate via Windows System set localtedElp new using elp

//xaml
<Window x:Class="WpfApp229.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp229"
        mc:Ignorable="d" WindowState="Maximized"
        Title="MainWindow" Height="450" Width="800">
    <Canvas x:Name="cvs" />
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp229
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        List<Point> elpPoints { get; set; }
        int idx = 0;
        int len = 0;
        Ellipse localtedElp { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += MainWindow_Loaded;

        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            DrawEllipses();
            len = elpPoints.Count;
            localtedElp = new Ellipse();
            localtedElp.Width = 50;
            localtedElp.Height = 50;
            localtedElp.Fill = new SolidColorBrush(Color.FromArgb(128,255,0,0));
            if(!cvs.Children.Contains(localtedElp))
            {
                cvs.Children.Add(localtedElp);
            }
            PeriodicallyLocate();
        }

        private void PeriodicallyLocate()
        {
            Thread.Sleep(1000);
            System.Timers.Timer tmr = new System.Timers.Timer();
            tmr.Elapsed += Tmr_Elapsed;
            tmr.Interval = 1000;
            tmr.Start();
        } 

        private void Tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (idx++ < len-1)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    var x = elpPoints[idx].X;
                    var y = elpPoints[idx].Y;
                    Canvas.SetLeft(localtedElp, x-10);
                    Canvas.SetTop(localtedElp, y-10);
                })); 
            }

        }

        private void DrawEllipses()
        {
            int width = (int)this.ActualWidth - 15;
            int height = (int)this.ActualHeight - 15;
            elpPoints = new List<Point>();
            Random rnd = new Random();
            for (int i = 0; i < 500; i++)
            {
                Ellipse elp = new Ellipse();
                elp.Width = 30;
                elp.Height = 30;
                elp.Fill = new SolidColorBrush(Colors.Blue);
                double x = rnd.Next(0, width);
                double y = rnd.Next(0, height);
                Canvas.SetLeft(elp, x);
                Canvas.SetTop(elp, y);
                cvs.Children.Add(elp);
                elpPoints.Add(new Point(x, y));
            }
        }
    }
}

  

 

 

 

 

标签:locate,via,Windows,System,set,localtedElp,new,using,elp
From: https://www.cnblogs.com/Fred1987/p/18343939

相关文章

  • 【数据结构】Map和Set
    目录1.前言2.搜索树2.1概念2.2操作-查找2.3操作-插入2.4操作-删除2.5性能分析3.搜索3.1概念及场景3.2模型3.3Map的使用3.3.1关于Map的说明3.3.2关于Map.Entry的说明,>3.3.3Map的常用方法说明3.3.4TreeMap的使用3.4Set的使用3.4.1Set的说明3.4.2Set的常......
  • python 元类:在调用“__set_name__”方法后编辑命名空间?
    假设我们用元类定义一个类。在类主体中,分配了对象,这些对象实现__set_name__以在类的数据结构中注册自身。是否可以在运行方法之后编辑命名空间?比如,分离填充的数据结构,将其分成两部分,然后在新属性下添加部分?__set_name__问题在于,在元类中调用之......
  • 模拟实现 memset --浅谈C语言
    memset()描述C库函数void*memset(void*str,intc,size_tn)用于将一段内存区域设置为指定的值。memset()函数将指定的值c复制到str所指向的内存区域的前n个字节中,这可以用于将内存块清零或设置为特定值。在一些情况下,需要快速初始化大块内存为零或者特定值,memse......
  • [ARC118C] Coprime Set 题解
    题目传送门(洛谷)题目传送门(atcoder)Step1理解题意输入一个数nnn要求你构造一个长度为n......
  • Android R Settings关于屏保/PowerManagerService欺骗系统不让其进入休眠状态
    //屏保设置界面./packages/apps/Settings/src/com/android/settings/dream/DreamSettings.java//和PowerManagerService建立联系./frameworks/base/packages/SettingsLib/src/com/android/settingslib/dream/DreamBackend.java//系统时钟屏保继承了DreamService./package......
  • C++进阶 map和set
    目录关联式容器键值对set的介绍set的使用set的模板参数列表set的构造set的迭代器set的容量set修改操作 multiset的介绍multiset的使用map的介绍map的使用map的模板参数说明map的构造map的迭代器map的容量与元素访问map中元素的修改 multimap的介绍关联......
  • 【已解决】戴尔 Inspiron 5457 和 5557 启动报错:Invalid configuration information -
    场景我使用的是戴尔15-5557的笔记本电脑,在某次开机的时候系统提示:Invalidconfigurationinformation-pleaserunSETUPprogram.虽然的点击Continue可以正常进入系统,但是每次开机都要来上这么一下真的很烦人,于是想着解决一下。试错过程1.BIOS调整刚开始以为是自己BIOS......
  • 有没有办法阻止 setUp() 为 python 测试用例中的每个测试方法启动浏览器?
    我正在练习编写Web自动化测试用例,并且编写了一些函数来测试登录、在用户主页中查找我的用户名以及测试GitHub的注销功能。然而,我通过经验和阅读了解到setUp()是在每个测试方法之前启动的,而我的问题是在每个测试方法之前它都会打开一个新的浏览器。我希望我的所有测......
  • 字符集和字符编码(Charset & Encoding)
    编码历史字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题。因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理。最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以,一个字节能表示的最大的整数就是255(二进制11111111=十进制255),如......
  • Python,Geopandas报错,AttributeError: The geopandas.dataset has been deprecated and
    Python版本3.9,Geopandas版本1.0.1问题描述:这是执行的代码,importpandasaspdimportgeopandasimportmatplotlib.pyplotaspltworld=geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))world.plot()plt.show()这是报错信息,Traceback(mo......