모방 vs WPF 보기 좋 은 진도 구현
나중에 시 도 를 해서 데 모 를 써 봤 는데 효과 가 좋았어 요.또 tif 파일 을 전문 적 으로 녹음 해 효 과 를 볼 수 있 도록 했다.잔말 말고 먼저 효 과 를 보 여 주세요.
효과
A.VS 2012 설치 인터페이스 그림;
B.개인 시도 데모 효과 도:
2.실현 설명
1.MUI 관련 코드 또는 dll 파일 을 다운로드 합 니 다.
2.프로젝트 에서 이 dll 을 도입 하고 자원 파일 을 도입 합 니 다.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
<ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
3.진행 표시 줄 이 필요 한 페이지 에 컨트롤 을 추가 합 니 다(사실은 WPF 컨트롤 입 니 다.MUI 가 스타일 을 확 장 했 을 뿐 입 니 다).
<Label Margin="280,169,0,0" Style="{StaticResource BackGroundContentText}" x:Name="lblMainState" HorizontalAlignment="Left" VerticalAlignment="Top"> :</Label>
<ProgressBar Margin="280,200,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Width="500" Minimum="0" x:Name="ProgressControlRealValue" Maximum="1" Value="0.1" Height="16" IsIndeterminate="False"/>
<Label Margin="280,212,0,0" Style="{StaticResource BackGroundContentText}" x:Name="lblProcess" HorizontalAlignment="Left" VerticalAlignment="Top"> ...</Label>
<ProgressBar Margin="280,250,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Minimum="0" x:Name="ProgressControl" Width="500" Maximum="2" Height="16" IsIndeterminate="True" />
4.배경 이 실현 되 고 상황 에 따라 진도 문자 와 진도 항목 의 값 을 업데이트 해 야 하기 때 문 입 니 다.그래서 여기 서 비동기 BackgroundWorker 를 사 용 했 습 니 다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Monitor.Class
{
/// <summary>
///
/// </summary>
public class CWorker
{
/// <summary>
///
/// </summary>
private BackgroundWorker backgroundWorker;
/// <summary>
///
/// </summary>
public Action BackgroundWork { get; set; }
/// <summary>
///
/// </summary>
public event EventHandler<BackgroundWorkerEventArgs> BackgroundWorkerCompleted;
private BackgroundWorkerEventArgs _eventArgs;//
/// <summary>
///
/// </summary>
public CWorker()
{
_eventArgs = new BackgroundWorkerEventArgs();
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
}
/// <summary>
///
/// </summary>
public void BegionWork()
{
if (backgroundWorker.IsBusy)
return;
backgroundWorker.RunWorkerAsync();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (BackgroundWork != null)
{
try
{
BackgroundWork();
}
catch (Exception ex)
{
_eventArgs.BackGroundException = ex;
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (this.BackgroundWorkerCompleted != null)
{
this.BackgroundWorkerCompleted(null, _eventArgs);
}
}
}
/// <summary>
///
/// </summary>
public class BackgroundWorkerEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
public Exception BackGroundException { get; set; }
}
}
namespace Monitor
{
/// <summary>
/// Splash.xaml
/// </summary>
public partial class Splash : Window
{
MainWindow m_MainWindow = null;//
CWorker m_Work = null;//
public Splash()
{
InitializeComponent();
m_MainWindow = new MainWindow();//
m_Work = new CWorker();
m_Work.BackgroundWork = this.ProcessDo;
m_Work.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(m_Work_BackgroundWorkerCompleted);
}
/// <summary>
///
/// </summary>
public void ProcessDo()
{
m_MainWindow.InitData(this);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
m_Work.BegionWork();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void m_Work_BackgroundWorkerCompleted(object sender, BackgroundWorkerEventArgs e)
{
m_MainWindow.Show();
this.Close();
}
/// <summary>
///
/// </summary>
/// <param name="text"></param>
private delegate void SetProcessLabelDelegate(string text, double processValue);
public void SetProcessValue(string text, double processValue)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(DispatcherPriority.Send, new SetProcessLabelDelegate(SetProcessValue), text, processValue);
return;
}
this.lblProcess.Content = text;
this.ProgressControlRealValue.Value = processValue;
}
}
}
이상 에서 말 한 것 이 바로 본문의 전체 내용 이 니 여러분 들 이 좋아 하 시 기 를 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
사전 프로세서 ID#error의 목적은 무엇입니까?컴파일 결과: 컴파일 실패 1>-----생성이 시작됨: 프로젝트:test, 설정:Debug Win32-----1>main.cpp 1>e:\program\test\test\main.cpp(84):fatal error ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.