• 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#

    1. using DevExpress.XtraEditors;
    2. using System;
    3. using System.Windows.Forms;
    4. namespace WindowsFormsApplication1 {
    5. static class Program {
    6. ///
    7. /// The main entry point for the application.
    8. ///
    9. [STAThread]
    10. static void Main() {
    11. //Add your code here
    12. WindowsFormsSettings.ForceDirectXPaint();
    13. WindowsFormsSettings.EnableFormSkins();
    14. Application.EnableVisualStyles();
    15. Application.SetCompatibleTextRenderingDefault(false);
    16. Application.Run(new Form1());
    17. }
    18. }
    19. }

    Visual Basic示例 - 方法1

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

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

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

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

    VB.NET

    1. Public Class Form1
    2. Shared Sub Main()
    3. Application.EnableVisualStyles()
    4. Application.SetCompatibleTextRenderingDefault(False)
    5. Application.Run(New Form1) 'Specify the startup form
    6. End Sub
    7. End Class

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

    VB.NET

    1. Public Class Form1
    2. Shared Sub Main()
    3. 'Add your code here
    4. DevExpress.XtraEditors.WindowsFormsSettings.ForceDirectXPaint()
    5. DevExpress.XtraEditors.WindowsFormsSettings.EnableFormSkins()
    6. Application.EnableVisualStyles()
    7. Application.SetCompatibleTextRenderingDefault(False)
    8. Application.Run(New Form1) 'Specify the startup form
    9. End Sub
    10. End Class

    Visual Basic示例 - 方法2

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

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

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

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

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

    VB.NET

    1. Imports DevExpress.XtraEditors
    2. Imports Microsoft.VisualBasic.ApplicationServices
    3. Namespace My
    4. ' The following events are available for MyApplication:
    5. ' Startup: Raised when the application starts, before the startup form is created.
    6. ' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
    7. ' UnhandledException: Raised if the application encounters an unhandled exception.
    8. ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
    9. ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    10. Partial Friend Class MyApplication
    11. Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
    12. 'Add your code here
    13. WindowsFormsSettings.ForceDirectXPaint()
    14. WindowsFormsSettings.EnableFormSkins()
    15. End Sub
    16. End Class
    17. End Namespace

  • 相关阅读:
    唯众中职人工智能专业解决方案
    mongoDB 优化(1)索引
    C++ 非泛型,自定义类str_的迭代。
    身份证照片怎么弄成200k以内?三个方法轻松搞定!
    Docker安装Rabbitmq并挂载宿主机数据目录
    webSocket基于面向对象二次封装
    ai语音机器人工作的原理流程电销机器人部署
    数据结构与算法C语言版学习笔记(1)-绪论
    测试/开发程序员面试该如何谈薪资待遇呢?突破这个坎......
    【Mysql实现递归树查询】
  • 原文地址:https://blog.csdn.net/AABBbaby/article/details/127898456