• <menu id="w2i4a"></menu>
  • logo DevExpress WinForm中文手冊

    文檔首頁>>DevExpress WinForm中文手冊>>如何動態(tài)更新添加到Splash表單的自定義控件

    如何動態(tài)更新添加到Splash表單的自定義控件


    立即下載DevExpress WinForms

    在這個例子中,一個自定義的進度條控件被添加到啟動界面,該示例展示了如何通過從啟動界面管理器發(fā)送命令來動態(tài)更新此進度條控件。啟動界面由啟動界面管理器在單獨的線程中顯示,與啟動界面的交互可以通過命令機制執(zhí)行,您通過SplashScreenManager.SendCommand方法發(fā)送命令,并通過覆蓋SplashScreen.ProcessCommand方法來處理此命令。 在該示例中,自定義命令被發(fā)送到啟動界面來推進啟動界面的進度條控件的進度。

    注意:完整的示例項目位于https://github.com/DevExpress-Examples/how-to-interact-with-a-splash-screen-by-sending-commands-e3576

    SplashScreen1.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using DevExpress.XtraSplashScreen;
    
    namespace SplashScreen_ProcessCommand {
    public partial class SplashScreen1 : SplashScreen {
    public SplashScreen1() {
    InitializeComponent();
    }
    
    #region Overrides
    
    public override void ProcessCommand(Enum cmd, object arg) {
    base.ProcessCommand(cmd, arg);
    SplashScreenCommand command = (SplashScreenCommand)cmd;
    if (command == SplashScreenCommand.SetProgress) {
    int pos = (int)arg;
    progressBarControl1.Position = pos;
    }
    }
    
    #endregion
    
    public enum SplashScreenCommand {
    SetProgress,
    Command2,
    Command3
    }
    }
    }

    Form1.cs:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using DevExpress.XtraSplashScreen;
    using System.Threading;
    
    namespace SplashScreen_ProcessCommand {
    public partial class Form1 : Form {
    public Form1() {
    InitializeComponent();
    }
    
    private void btnShowSplashScreen_Click(object sender, EventArgs e) {
    // Open a Splash Screen
    SplashScreenManager.ShowForm(this, typeof(SplashScreen1), true, true, false);
    
    // The splash screen will be opened in a separate thread. To interact with it, use the SendCommand method.
    for (int i = 1; i <= 100; i++) {
    SplashScreenManager.Default.SendCommand(SplashScreen1.SplashScreenCommand.SetProgress, i);
    //To process commands, override the SplashScreen.ProcessCommand method.
    Thread.Sleep(25);
    }
    
    // Close the Splash Screen.
    SplashScreenManager.CloseForm(false);
    }
    }
    }

    Form1.vb:

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Linq
    Imports System.Text
    Imports System.Windows.Forms
    Imports DevExpress.XtraSplashScreen
    Imports System.Threading
    
    Namespace SplashScreen_ProcessCommand
    Partial Public Class Form1
    Inherits Form
    Public Sub New()
    InitializeComponent()
    End Sub
    
    Private Sub btnShowSplashScreen_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnShowSplashScreen.Click
    ' Open a Splash Screen
    SplashScreenManager.ShowForm(Me, GetType(SplashScreen1), True, True, False)
    
    ' The splash screen will be opened in a separate thread. To interact with it, use the SendCommand method.
    For i As Integer = 1 To 100
    SplashScreenManager.Default.SendCommand(SplashScreen1.SplashScreenCommand.SetProgress, i)
    'To process commands, override the SplashScreen.ProcessCommand method.
    Thread.Sleep(25)
    Next i
    
    ' Close the Splash Screen.
    SplashScreenManager.CloseForm(False)
    End Sub
    End Class
    End Namespace

    SplashScreen1.vb

    Imports Microsoft.VisualBasic
    Imports System
    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports DevExpress.XtraSplashScreen
    
    Namespace SplashScreen_ProcessCommand
    Partial Public Class SplashScreen1
    Inherits SplashScreen
    Public Sub New()
    InitializeComponent()
    End Sub
    
    #Region "Overrides"
    
    Public Overrides Sub ProcessCommand(ByVal cmd As System.Enum, ByVal arg As Object)
    MyBase.ProcessCommand(cmd, arg)
    Dim command As SplashScreenCommand = CType(cmd, SplashScreenCommand)
    If command = SplashScreenCommand.SetProgress Then
    Dim pos As Integer = CInt(Fix(arg))
    progressBarControl1.Position = pos
    End If
    End Sub
    
    #End Region
    
    Public Enum SplashScreenCommand
    SetProgress
    Command2
    Command3
    End Enum
    End Class
    End Namespace
    掃碼咨詢


    添加微信 立即咨詢

    電話咨詢

    客服熱線
    023-68661681

    TOP
    三级成人熟女影院,欧美午夜成人精品视频,亚洲国产成人乱色在线观看,色中色成人论坛 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();