开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 5364|回复: 0

表单控件 - 动态更新添加到初始表单的自定义控件

[复制链接]

0

精华

8

贡献

1768

赞扬

特约版主

帖子
583
软币
4524
在线时间
275 小时
注册时间
2019-2-21
发表于 2021-2-26 09:32:05 | 显示全部楼层 |阅读模式

点击获取DevExpress完整版下载

在此示例中,自定义进度栏控件被添加到启动屏幕。 该示例显示如何通过从启动画面管理器发送命令来动态更新此进度栏控件。启动画面由启动画面管理器在单独的线程中显示,可以通过命令机制执行与启动画面的交互。 您通过SplashScreenManager.SendCommand方法发送命令,并通过覆盖SplashScreen.ProcessCommand方法来处理此命令。 在该示例中,自定义命令被发送到启动画面,以推进启动画面的进度条控件的进度。

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

SplashScreen1.cs

[CSS] 纯文本查看 复制代码
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

[CSS] 纯文本查看 复制代码
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

[Visual Basic] 纯文本查看 复制代码
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

[Visual Basic] 纯文本查看 复制代码
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


上DevExpress中文网,获取第一手最新产品资讯!

DevExpress技术交流群3:700924826      欢迎一起进群讨论


回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-11-21 21:29

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表