AABBbaby

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

UI控件DevExpress WinForm新手指南——如何在应用启动时执行操作

DevExpress WinForm拥有180+组件和UI库,能为Windows Forms平台创建具有影响力的业务解决方案。DevExpress WinForm能完美构建流畅、美观且易于使用的应用程序,无论是Office风格的界面,还是分析处理大批量的业务数据,它都能轻松胜任!

在打开主应用程序表单之前,开发人员可能需要在代码中执行某些操作。例如要启用DirectX硬件加速,开发人员需要在创建应用程序表单之前调用WindowsFormsSettings.ForceDirectXPaint方法。

本文将为大家演示在使用C#和Visual Basic开发项目时,可以将应用程序初始化代码放置在何处。如果您是一个Visual Basic开发人员,可以根据需求选择下面列出方法当中的一种。

获取DevExpress 最新版下载

C#示例

对于C#项目,在Solution Explorer中找到Program.cs文件,该文件包含void Main()过程,开发人员可以在Application.Run方法调用之前在其中添加自定义代码。

C#

using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1 {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
//Add your code here
WindowsFormsSettings.ForceDirectXPaint();
WindowsFormsSettings.EnableFormSkins();

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Visual Basic示例 - 方法1

使用这种方法,开发人员可以创建一个Main函数并将其设置为应用程序的入口点。

1. 在Solution Explorer中右键单击您的项目,然后在上下文菜单中选择Properties。

2. 取消选中Enable application framework,然后在Application选项卡中将Startup object设置为Sub Main。

界面控件DevExpress WinForm新手指南——如何在应用启动时执行操作

3. 切换到主窗体的代码编辑器,手动将以下Shared Sub Main过程添加到窗体类中:

VB.NET

Public Class Form1
Shared Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1) 'Specify the startup form
End Sub
End Class

4. 在Application.Run方法调用之前插入要执行的代码。

VB.NET

Public Class Form1
Shared Sub Main()
'Add your code here
DevExpress.XtraEditors.WindowsFormsSettings.ForceDirectXPaint()
DevExpress.XtraEditors.WindowsFormsSettings.EnableFormSkins()

Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New Form1) 'Specify the startup form
End Sub
End Class
Visual Basic示例 - 方法2

通过这种方法,您可以订阅应用程序的Startup事件来执行自定义操作。

1. 在Solution Explorer中右键单击您的项目,然后在上下文菜单中选择Properties。

2. 在Application选项卡中单击View Application Events按钮。

界面控件DevExpress WinForm新手指南——如何在应用启动时执行操作

3. 订阅打开的ApplicationEvents.vb文件中的Startup事件。

界面控件DevExpress WinForm新手指南——如何在应用启动时执行操作

4. 在生成的Startup事件处理程序中插入要执行的代码。

VB.NET

Imports DevExpress.XtraEditors
Imports Microsoft.VisualBasic.ApplicationServices

Namespace My
' The following events are available for MyApplication:
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
'Add your code here
WindowsFormsSettings.ForceDirectXPaint()
WindowsFormsSettings.EnableFormSkins()
End Sub
End Class
End Namespace

DevExpress技术交流群6:600715373      欢迎一起进群讨论

更多DevExpress线上公开课、中文教程资讯请上中文网获取

posted on   AABBbaby  阅读(147)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2021-11-17 资源分享|DevExpress v21.2帮助文档下载(CHM版)
2020-11-17 如何使用自动生成的序列创建3D图表?DevExpress WPF有妙招(Part 3)
2017-11-17 【DevExpress v17.2新功能预告】增强ASP.NET TreeList
点击右上角即可分享
微信分享提示