欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
C# 制作指示燈(經(jīng)典)

群友提問(wèn):C#中的指示燈怎么做,改變狀態(tài)有什么好的方法嗎?

制作指示燈的方法有很多中:比如:

  1. 通過(guò)GDI+繪制自定義LED指示燈控件;

  2. 調用現成的第三方控件庫;

  3. 采用label標簽,通過(guò)改變背景色實(shí)現;等等

本文就以第三種方式展開(kāi)講解

01

實(shí)現效果

02


實(shí)現代碼

前臺代碼:

添加兩個(gè)按鈕和一個(gè)標簽:

  <StackPanel>        <Border BorderBrush="Red"></Border>        <Button Name="StartBtn" Content="Start"/>        <Button Name="StopBtn" Content="Stop"/>        <Label Name="DisplayLbl" Visibility="{Binding DisplaySwitch}" FontSize="200"               HorizontalAlignment="Center" VerticalAlignment="Center"               Content="{Binding LabelText}" Foreground="{Binding ForeColor}" />    </StackPanel>

后臺代碼:

①安裝PropertyChanged.Fody,using PropertyChanged;然后在類(lèi)前面添加   [AddINotifyPropertyChangedInterface],類(lèi)中所有屬性變更后就會(huì )自動(dòng)通知界面變更;

②通過(guò)DisplaySwitch 屬性控制指示燈的顯示或者隱藏,然后通過(guò)界面的start按鈕啟動(dòng)指示燈,stop關(guān)閉指示燈;

③指示燈背景色的改變通過(guò)獨立線(xiàn)程控制,跨線(xiàn)程修改UI線(xiàn)程控件屬性使用Caliburn.Micro框架下的  Execute.OnUIThread(()=>{});實(shí)現。

using PropertyChanged;using System.Threading;using System.Windows;using System.Windows.Media;using Brush = System.Windows.Media.Brush;
namespace Caliburn.Micro.Hello{ [AddINotifyPropertyChangedInterface] public class IndicatorLightViewModel : IViewModel { public Visibility DisplaySwitch { get; set; } = Visibility.Hidden; public string LabelText { get; set; }
public Brush ForeColor { get; set; }
private Thread workTask; public IndicatorLightViewModel() { ForeColor = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } public void StartBtn() { DisplaySwitch = Visibility.Visible; LabelText = "●"; if (workTask == null || !workTask.IsAlive) { workTask = new Thread(IndicatorLightOperation);//添加線(xiàn)程 workTask.IsBackground = true; workTask.Start(); } } public void StopBtn() { if (workTask == null || workTask.IsAlive) { workTask.Abort(); } DisplaySwitch = Visibility.Hidden; }
public void IndicatorLightOperation() { while (true) { Execute.OnUIThread(()=> { if (((SolidColorBrush)ForeColor).Color.Equals(Color.FromRgb(255, 0, 0))) { ForeColor = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } else { ForeColor = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } }); Thread.Sleep(500); }
} }}

03


                         其它相關(guān):Brush顏色轉換

1、String轉換成Color
  Color color = (Color)ColorConverter.ConvertFromString(string);
2、String轉換成Brush
   BrushConverter brushConverter = new BrushConverter();   Brush brush = (Brush)brushConverter.ConvertFromString(string);
3、Color轉換成Brush    Brush brush = new SolidColorBrush(color));     4、Brush轉換成Color有兩種方法:
1)先將Brush轉成string,再轉成Color。
Color color= (Color)ColorConverter.ConvertFromString(brush.ToString());
2)將Brush轉成SolidColorBrush,再取Color。
 Color color= ((SolidColorBrush)CadColor.Background).Color;

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
c# 顏色轉換
C# 的Brush 及相關(guān)顏色的操作
wpf 修改控件Background
閑話(huà)WPF之五(XAML中的類(lèi)型轉換)
WPF中的Frozen(凍結)與線(xiàn)程及其他相關(guān)問(wèn)題
WinForm中Treeview實(shí)現根節點(diǎn)無(wú)選擇框而子節點(diǎn)存在
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久