跳過到頁腳內容
.NET幫助

NativeUI C#(對於開發者的運行原理)

NativeUI 是 Grand Theft Auto (GTA) modding 社群中 C# 開發人員不可或缺的框架。 它簡化了簡易、無障礙的嵌套式功能表系統和自訂橫幅的建立,以其友善的使用方式和對各種螢幕解析度的適應性,成為 GTA modders 的最愛。 NativeUI MOD 旨在製作快速、類似 Rockstar 的選單,呼應 GTA 遊戲中嵌套選單的風格與反應能力。 在本教程中,我們將瞭解什麼是 NativeUI,以及如何將 IronPDF 與之整合。

NativeUI 的基本原理

NativeUI 擅長於輕鬆建立嵌套式選單,這對於想要建立複雜介面的修改者來說是一大福音,因為他們不需要為事件回呼和項目描述編寫複雜的程式碼。 它還能適應各種螢幕解析度,確保選單在不同的顯示器上都具有視覺吸引力。 NativeUI 的優勢之一是它的無痛嵌套功能表系統,讓開發人員可以毫不費力地建立複雜的功能表結構,並搭配自訂的教學按鈕。 對於初學者來說,NativeUI 在其 wiki 上的說明文件是很有價值的資源,可提供選單建立的逐步指導。

在 Visual Studio 中設定 NativeUI

在 Visual Studio 中的初始設定包括下載 NativeUI 函式庫,並將 .dll 檔案併入您的 mod 專案中。 NativeUI 函式庫是一個已發佈的套件,可透過常用的 C# 套件庫取得,因此可輕鬆地將其整合至您的專案中。 安裝方式簡單直接。 設定 NativeUI 時,請確保您的開發環境與 NativeUI 函式庫擁有相容的版本,以獲得最佳效能。

NativeUI C# (How It Works For Developers):圖 1 - NativeUI

建立您的第一個選單

使用 NativeUI 創建您的第一個選單是令人振奮的一步。這個函式庫的設計迎合了易用性的需求,讓您可以輕鬆地加入項目說明、簡單的按鈕,甚至是自訂的橫幅。 對於剛開始的人,建議先從基本的腳本開始,當您對這個框架越來越熟悉時,再逐漸增加更複雜的功能。 以下是一個簡單的範例,用自己的材質來建立一個基本的選單:

using System;
using System.Windows.Forms;
using NativeUI;

public class YourFirstMenu : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;

    public YourFirstMenu()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("NativeUI", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddMenuItems(mainMenu);
        _menuPool.RefreshIndex();

        // Subscribe to event handlers for updating and input control
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }

    private void AddMenuItems(UIMenu menu)
    {
        var item1 = new UIMenuItem("Item 1", "Description for Item 1");
        menu.AddItem(item1);

        // Set up an event for when an item is selected
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == item1)
            {
                // Do something when Item 1 is selected
            }
        };
    }

    private void OnTick(object sender, EventArgs e)
    {
        // Process the pool to handle drawing and interactions
        _menuPool.ProcessMenus();
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        // Toggle the visibility of the menu with F5 key
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen())
            mainMenu.Visible = !mainMenu.Visible;
    }
}
using System;
using System.Windows.Forms;
using NativeUI;

public class YourFirstMenu : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;

    public YourFirstMenu()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("NativeUI", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddMenuItems(mainMenu);
        _menuPool.RefreshIndex();

        // Subscribe to event handlers for updating and input control
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }

    private void AddMenuItems(UIMenu menu)
    {
        var item1 = new UIMenuItem("Item 1", "Description for Item 1");
        menu.AddItem(item1);

        // Set up an event for when an item is selected
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == item1)
            {
                // Do something when Item 1 is selected
            }
        };
    }

    private void OnTick(object sender, EventArgs e)
    {
        // Process the pool to handle drawing and interactions
        _menuPool.ProcessMenus();
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        // Toggle the visibility of the menu with F5 key
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen())
            mainMenu.Visible = !mainMenu.Visible;
    }
}
Imports System
Imports System.Windows.Forms
Imports NativeUI

Public Class YourFirstMenu
	Inherits Script

	Private _menuPool As MenuPool
	Private mainMenu As UIMenu

	Public Sub New()
		_menuPool = New MenuPool()
		mainMenu = New UIMenu("NativeUI", "SELECT AN OPTION")
		_menuPool.Add(mainMenu)
		AddMenuItems(mainMenu)
		_menuPool.RefreshIndex()

		' Subscribe to event handlers for updating and input control
		AddHandler Me.Tick, AddressOf OnTick
		AddHandler Me.KeyDown, AddressOf OnKeyDown
	End Sub

	Private Sub AddMenuItems(ByVal menu As UIMenu)
		Dim item1 = New UIMenuItem("Item 1", "Description for Item 1")
		menu.AddItem(item1)

		' Set up an event for when an item is selected
		AddHandler menu.OnItemSelect, Sub(sender, item, index)
			If item = item1 Then
				' Do something when Item 1 is selected
			End If
		End Sub
	End Sub

	Private Sub OnTick(ByVal sender As Object, ByVal e As EventArgs)
		' Process the pool to handle drawing and interactions
		_menuPool.ProcessMenus()
	End Sub

	Private Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
		' Toggle the visibility of the menu with F5 key
		If e.KeyCode = Keys.F5 AndAlso Not _menuPool.IsAnyMenuOpen() Then
			mainMenu.Visible = Not mainMenu.Visible
		End If
	End Sub
End Class
$vbLabelText   $csharpLabel

這個腳本設定了一個有一個選項的基本選單,並處理其選擇。 NativeUI 利用基於事件的回呼,這表示選單中的動作會觸發特定事件,使您的 UI 具備互動性和回應性。

增強使用者互動

NativeUI 的一個關鍵方面是它能夠創建既實用又人性化的選單。 該函式庫支援滑鼠控制。 除了滑鼠控制之外,NativeUI 還擁有全面的控制器支援,可確保使用遊戲控制器輕鬆瀏覽功能表。 您可以透過新增自訂教學按鈕,引導使用者完成功能表選項,進一步加強使用者互動。

自訂選單

NativeUI 允許高度客製化。 您可以使用自己的紋理和客製化橫幅來裝飾您的選單,讓它們擁有獨一無二的外觀,脫穎而出。 加入這些個人化的元素不僅能讓您的選單更具視覺吸引力,也能為使用者創造更身歷其境的體驗。

private void CustomizeMenu(UIMenu menu)
{
    // Set a custom banner texture for the menu
    menu.SetBannerType("texture.png");

    // Change the color of a specific menu item to red
    menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0));
}
private void CustomizeMenu(UIMenu menu)
{
    // Set a custom banner texture for the menu
    menu.SetBannerType("texture.png");

    // Change the color of a specific menu item to red
    menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0));
}
Private Sub CustomizeMenu(ByVal menu As UIMenu)
	' Set a custom banner texture for the menu
	menu.SetBannerType("texture.png")

	' Change the color of a specific menu item to red
	menu.ChangeItemColour("Item 1", System.Drawing.Color.FromArgb(255, 0, 0))
End Sub
$vbLabelText   $csharpLabel

IronPDF:C# PDF 函式庫

NativeUI C# (How It Works For Developers):圖 2 - IronPDF

IronPDF 是 .NET 中用於處理 PDF 檔案的綜合資料庫。 它可讓開發人員建立新的 PDF、編輯現有的 PDF,以及將 HTML 轉換為 PDF,使其成為任何需要處理 PDF 文件的 C# 應用程式必備的函式庫。

在 NativeUI 應用程式中實作 IronPDF。

在 C# 專案中整合 IronPDF 與 NativeUI,需要將 IronPDF 套件新增至 Visual Studio 專案中。 這可以透過 Visual Studio 中的 NuGet Package Manager 輕鬆完成。 設定完成後,您就可以在使用 NativeUI 建立的 UI 元件旁邊使用 IronPDF 的功能。

考慮一個應用程式,您需要根據 NativeUI 介面的使用者輸入來產生報告。 以下是如何使用 IronPDF 實現這一目標:

using IronPdf;
using NativeUI;
using System;

public class ReportGenerator : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;

    public ReportGenerator()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("Report Generator", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddPdfGenerationOption(mainMenu);
        _menuPool.RefreshIndex();

        // Subscribe to event handlers for updating and input control
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }

    private void AddPdfGenerationOption(UIMenu menu)
    {
        var generateReportItem = new UIMenuItem("Generate Report", "Create a PDF report");
        menu.AddItem(generateReportItem);

        // Set up an event for when an item is selected
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == generateReportItem)
            {
                CreatePdfReport();
            }
        };
    }

    private void CreatePdfReport()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>");
        pdf.SaveAs("Report.pdf");

        // Notification to the user that the PDF report has been generated
        Console.WriteLine("PDF report generated and saved as Report.pdf");
    }

    private void OnTick(object sender, EventArgs e)
    {
        // Process the pool to handle drawing and interactions
        _menuPool.ProcessMenus();
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        // Toggle the visibility of the menu with F5 key
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen())
            mainMenu.Visible = !mainMenu.Visible;
    }
}
using IronPdf;
using NativeUI;
using System;

public class ReportGenerator : Script
{
    private MenuPool _menuPool;
    private UIMenu mainMenu;

    public ReportGenerator()
    {
        _menuPool = new MenuPool();
        mainMenu = new UIMenu("Report Generator", "SELECT AN OPTION");
        _menuPool.Add(mainMenu);
        AddPdfGenerationOption(mainMenu);
        _menuPool.RefreshIndex();

        // Subscribe to event handlers for updating and input control
        Tick += OnTick;
        KeyDown += OnKeyDown;
    }

    private void AddPdfGenerationOption(UIMenu menu)
    {
        var generateReportItem = new UIMenuItem("Generate Report", "Create a PDF report");
        menu.AddItem(generateReportItem);

        // Set up an event for when an item is selected
        menu.OnItemSelect += (sender, item, index) =>
        {
            if (item == generateReportItem)
            {
                CreatePdfReport();
            }
        };
    }

    private void CreatePdfReport()
    {
        var renderer = new ChromePdfRenderer();
        var pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>");
        pdf.SaveAs("Report.pdf");

        // Notification to the user that the PDF report has been generated
        Console.WriteLine("PDF report generated and saved as Report.pdf");
    }

    private void OnTick(object sender, EventArgs e)
    {
        // Process the pool to handle drawing and interactions
        _menuPool.ProcessMenus();
    }

    private void OnKeyDown(object sender, KeyEventArgs e)
    {
        // Toggle the visibility of the menu with F5 key
        if (e.KeyCode == Keys.F5 && !_menuPool.IsAnyMenuOpen())
            mainMenu.Visible = !mainMenu.Visible;
    }
}
Imports IronPdf
Imports NativeUI
Imports System

Public Class ReportGenerator
	Inherits Script

	Private _menuPool As MenuPool
	Private mainMenu As UIMenu

	Public Sub New()
		_menuPool = New MenuPool()
		mainMenu = New UIMenu("Report Generator", "SELECT AN OPTION")
		_menuPool.Add(mainMenu)
		AddPdfGenerationOption(mainMenu)
		_menuPool.RefreshIndex()

		' Subscribe to event handlers for updating and input control
		AddHandler Me.Tick, AddressOf OnTick
		AddHandler Me.KeyDown, AddressOf OnKeyDown
	End Sub

	Private Sub AddPdfGenerationOption(ByVal menu As UIMenu)
		Dim generateReportItem = New UIMenuItem("Generate Report", "Create a PDF report")
		menu.AddItem(generateReportItem)

		' Set up an event for when an item is selected
		AddHandler menu.OnItemSelect, Sub(sender, item, index)
			If item = generateReportItem Then
				CreatePdfReport()
			End If
		End Sub
	End Sub

	Private Sub CreatePdfReport()
		Dim renderer = New ChromePdfRenderer()
		Dim pdf = renderer.RenderHtmlAsPdf("<h1>Report</h1><p>Report details...</p>")
		pdf.SaveAs("Report.pdf")

		' Notification to the user that the PDF report has been generated
		Console.WriteLine("PDF report generated and saved as Report.pdf")
	End Sub

	Private Sub OnTick(ByVal sender As Object, ByVal e As EventArgs)
		' Process the pool to handle drawing and interactions
		_menuPool.ProcessMenus()
	End Sub

	Private Sub OnKeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
		' Toggle the visibility of the menu with F5 key
		If e.KeyCode = Keys.F5 AndAlso Not _menuPool.IsAnyMenuOpen() Then
			mainMenu.Visible = Not mainMenu.Visible
		End If
	End Sub
End Class
$vbLabelText   $csharpLabel

結論

NativeUI C# (How It Works For Developers):圖 3 - 授權

IronPDF 與 NativeUI 在 C# 應用程式中的整合是一個強大的組合,可大幅提升功能和使用者體驗。 無論是用於製作商業報表、教育工具或全面的資料表單,這個組合都能為開發人員提供一個強大的平台,以建立複雜且高品質的應用程式。 若能發揮創意並經過深思熟慮後加以實作,此整合的潛在應用將是廣大且多元的。

開始使用 IronPDF 的 免費試用版,發掘它的全部潛力。 當您準備好購買時,許可證起價僅為 $999 - 對於如此強大的功能而言,價格非常低廉!

常見問題解答

如何在 C# 中創建遊戲模組的嵌套菜單系統?

NativeUI 是一個框架,簡化了遊戲模組中嵌套菜單系統的創建,特別是在《俠盜獵車手》社群內。開發者可以在無需複雜代碼的情況下構建複雜介面,確保與各種屏幕解析度的兼容性。

如何在 C# 中整合 PDF 庫與菜單系統?

您可以透過在 Visual Studio 中使用 NuGet 套件管理器安裝 IronPDF,將其與像 NativeUI 這樣的 C# 菜單系統整合。此整合允許您根據從菜單介面收集的用戶輸入生成和操作 PDF。

NativeUI 在 C# 應用中的可用自訂選項有哪些?

NativeUI 為 C# 應用提供了廣泛的自訂選項,包括菜單的自訂紋理和橫幅。這些功能使開發者能創建在視覺上獨特的菜單,提升用戶體驗。

在 Visual Studio 中設置 NativeUI 的流程是什麼?

要在 Visual Studio 中設置 NativeUI,請下載 NativeUI 庫並將 .dll 文件添加到您的專案中。確保您的開發環境與該庫兼容,以確保最佳性能。庫的文檔提供了詳細的設置說明。

NativeUI 為模組使用者的互動提供了哪些優勢?

NativeUI 通過提供鼠標和控制器輸入支援來增強用戶的互動性,使菜單易於導航。它還允許開發者包含自訂的說明按鈕,能有效地引導用戶通過各種菜單選項。

基於事件的回調如何增強 C# 開發中的菜單互動?

NativeUI 中的事件驅動回調允許開發者通過根據用戶操作觸發特定事件來創建響應和互動的菜單。此功能簡化了菜單互動的管理,並顯著改善了用戶體驗。

有哪些資源可用於學習如何在 C# 中使用 NativeUI?

開發人員可以訪問 NativeUI GitHub 維基,提供了全面的資源和文檔。這些資源提供了逐步指南,幫助您使用 C# 應用中的 NativeUI 框架創建和自訂菜單。

如何從 C# 菜單系統生成 PDF 報告?

您可以透過將 IronPDF 整合到 NativeUI 應用中,從 C# 菜單系統生成 PDF 報告。一旦集成,您可以使用 IronPDF 基於通過菜單介面收集的用戶輸入創建報告。

Jacob Mellor, Team Iron 首席技術官
首席技術官

Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。

Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。

他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我