原創(chuàng)|使用教程|編輯:龔雪|2022-11-16 10:13:37.813|閱讀 204 次
概述:本文將介紹如何使用DevExpress WinForm控件在應(yīng)用程序啟動(dòng)時(shí)執(zhí)行操作,歡迎下載最新版組件產(chǎn)品體驗(yàn)~
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
DevExpress WinForm擁有180+組件和UI庫(kù),能為Windows Forms平臺(tái)創(chuàng)建具有影響力的業(yè)務(wù)解決方案。DevExpress WinForm能完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序,無(wú)論是Office風(fēng)格的界面,還是分析處理大批量的業(yè)務(wù)數(shù)據(jù),它都能輕松勝任!
在打開(kāi)主應(yīng)用程序表單之前,開(kāi)發(fā)人員可能需要在代碼中執(zhí)行某些操作。例如要啟用DirectX硬件加速,開(kāi)發(fā)人員需要在創(chuàng)建應(yīng)用程序表單之前調(diào)用WindowsFormsSettings.ForceDirectXPaint方法。
本文將為大家演示在使用C#和Visual Basic開(kāi)發(fā)項(xiàng)目時(shí),可以將應(yīng)用程序初始化代碼放置在何處。如果您是一個(gè)Visual Basic開(kāi)發(fā)人員,可以根據(jù)需求選擇下面列出方法當(dāng)中的一種。
對(duì)于C#項(xiàng)目,在Solution Explorer中找到Program.cs文件,該文件包含void Main()過(guò)程,開(kāi)發(fā)人員可以在Application.Run方法調(diào)用之前在其中添加自定義代碼。
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()); } } }
使用這種方法,開(kāi)發(fā)人員可以創(chuàng)建一個(gè)Main函數(shù)并將其設(shè)置為應(yīng)用程序的入口點(diǎn)。
1. 在Solution Explorer中右鍵單擊您的項(xiàng)目,然后在上下文菜單中選擇Properties。
2. 取消選中Enable application framework,然后在Application選項(xiàng)卡中將Startup object設(shè)置為Sub Main。
3. 切換到主窗體的代碼編輯器,手動(dòng)將以下Shared Sub Main過(guò)程添加到窗體類中:
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方法調(diào)用之前插入要執(zhí)行的代碼。
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
通過(guò)這種方法,您可以訂閱應(yīng)用程序的Startup事件來(lái)執(zhí)行自定義操作。
1. 在Solution Explorer中右鍵單擊您的項(xiàng)目,然后在上下文菜單中選擇Properties。
2. 在Application選項(xiàng)卡中單擊View Application Events按鈕。
3. 訂閱打開(kāi)的ApplicationEvents.vb文件中的Startup事件。
4. 在生成的Startup事件處理程序中插入要執(zhí)行的代碼。
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技術(shù)交流群6:600715373 歡迎一起進(jìn)群討論
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)