WinForms Controls v25.1
AI 驅動的語義搜索
我們的 WinForms 數據網格、GridLookUpEdit 和 SearchLookUpEdit 控件具有增強的搜索體驗,使用戶能夠更快/更準確地在大型數據集中查找相關數據。與基于關鍵字的標準搜索不同,語義搜索利用自然語言處理 (NLP) 來分析超出精確關鍵字匹配的搜索查詢。
語義搜索使用嵌入生成器將文本轉換為數字向量表示形式。向量嵌入存儲在矢量存儲(例如,數據庫、內存中集合或將向量值存儲在文件中的自定義實現)。當用戶輸入搜索查詢時,搜索引擎會計算查詢向量和存儲的數據向量之間的相似性分數,以返回最相關的結果。
啟用 AI 驅動的語義搜索后,搜索框中會顯示一個下拉按鈕。彈出菜單允許用戶指定搜索模式:
- 標準- 傳統的基于關鍵字的搜索。
- 語義- 基于向量的語義搜索,用于查找概念上相似的項目。
- 混合- 標準搜索和語義搜索的組合。
安裝 DevExpress WinForms 產品庫.
語義搜索可以在兩種模式下運行:
- Filter Mode- 僅顯示匹配的記錄。
- 搜索模式- 突出顯示相關數據行,以便更直觀地發現數據。
要在 WinForms 數據網格或數據查找控件中啟用語義搜索,您必須注冊嵌入生成器,提供向量存儲/數據庫,將我們的新連接到網格或查找控件,并配置行為設置(例如,嵌入生成器、向量存儲、向量存儲中的記錄類型、數據源鍵字段、搜索模式、 搜索準確性、最大結果數等)。SemanticSearchBehavior
文檔
?
模板套件
#WinForms 應用程序生成器
從頭開始構建模塊化/多視圖 WinForms 應用程序需要大量的設置工作 — 從選擇最佳導航模型到集成適當的 UI 組件。我們新的 Application Builder 模板可自動執行這些基礎步驟,使開發人員能夠專注于業務邏輯和用戶體驗,而不是樣板代碼。
DevExpress WinForms Application Builder 使用一個簡單的 2 步交互式向導:
步驟 1:選擇 Navigation 模型
為您的項目指定所需的導航結構:
- Accordion
- Tabbed Accordion
- Compact List
- Tabbed Window
第 2 步:選擇 DevExpress Controls
根據項目要求選擇預配置的 DevExpress UI 控件。
根據您的選擇,模板會自動生成一個應用程序,其中包含:
- 完全配置的導航系統。
- 每個選定 UI 控件的單獨視圖。
?
#新的 'Middle-Tier Security Application' 項目模板
使用此項目模板,您可以快速構建高性能 WinForms 應用程序并將其連接到 ASP.NET Core 中間層服務器。此模板基于功能齊全的例應用程序,專為對由 .NET 8+ 提供支持的安全/可擴展解決方案感興趣的用戶而設計。
如您所料,該模板旨在最大限度地降低設置復雜性。借助它,您可以:
- 使用 EF Core 為應用程序業務實體和安全策略構建數據模型。
- 使用 DevExpress ASP.NET Core Middle-Tier Security Server 將 Windows Forms .NET 8 客戶端應用程序連接到后端。
- 定義訪問權限并激活 .NET 8 WinForms 應用程序的身份驗證/授權。
- 根據用戶特定的訪問權限自定義 UI/UX。
- 創建登錄表單以對用戶進行身份驗證。
- 創建編輯表單以修改和發布數據 (CRUD)。
?
?
文檔???示例 (GitHub)
?
#新的 DevExpress 項目模板
模板工具包 v25.1 允許您將以下 DevExpress 支持的 UI 元素/控件添加到您的 .NET 8+ WinForms 項目中:
DevExpress 表單:
- Foem?(XtraForm)
- DirectX Form
- Fluent Design Form
- Modular Form
- Ribbon Form
- Splash Screen
- Tabbed MDI Form
- Toolbar Form
- Wait Form
- Wizard Form
DevExpress 用戶控件:
- User Control
- Modular User Control
其他模板:
- Dashboard
- Custom Data Editor
- Custom Data Grid
?
可及性
#基于助記詞的子菜單導航
在 v25.1 中,我們增強了基于工具欄的傳統用戶界面的鍵盤輔助功能。用戶可以在具有相同助記詞的子菜單項之間循環(用 in captions 表示)。當子菜單中的多個項目具有相同的助記詞時,重復的按鍵會按順序瀏覽它們。該功能會自動啟用,不需要其他配置。&
- C#
barItemSaveAs.Caption = "Save &As";
barItemSaveAll.Caption = "Save &All";
?
#Accordion 快捷方式
折疊面板項現在支持鍵盤快捷鍵。使用快捷鍵屬性指定預定義或自定義鍵盤快捷鍵。此增強功能提高了輔助功能,特別是對于具有復雜導航結構的應用程序。
- C#
accordionControlElement1.ShortcutKey = new DevExpress.XtraBars.BarShortcut(Keys.J);
?
#BarItem - 支持 AutomationId
該屬性是區分自動測試和輔助功能 (a11y) 工具中的 UI 元素的唯一標識符,現在可用于對象。此屬性會自動設置為條形項目的 。AutomationId
BarItem
Name
?
JSON 序列化
DevExpress WinForms UI 控件現在支持基于 JSON 的布局序列化 - XML 的替代方案,用于簡化與現代 Web 和 AI 服務的集成。在 v25.1 中,new 和 methods 允許您以 JSON 格式保存和恢復控件布局。SaveLayoutToJson(Stream)
RestoreLayoutFromJson(Stream)
- C#
string filePath = "gridlayout.json";
void Form1_Load(object sender, EventArgs e) {if (File.Exists(filePath)) {using (var jsonStream = File.OpenRead(filePath))gridView1.RestoreLayoutFromJson(jsonStream);}
}void Form1_FormClosing(object sender, FormClosingEventArgs e) {using (var jsonStream = File.OpenWrite(filePath))gridView1.SaveLayoutToJson(jsonStream);
}
JSON 序列化可用于面向 .NET 8+ 和 .NET Framework 4.6.2+ 的項目。
?
圓角蒙皮面板
現在在 Visual Studio 工具箱中提供
我們圓角皮膚面板控件完全集成到 Visual Studio 設計器中,并且可以在設計時直接從 Toolbox 添加到表單中。
與標準面板不同,每當使用 WXI 皮膚時,我們的 RoundedSkinPanel 都會自動渲染各個 UI 元素(GridControl、TreeList、RichEditControl 等)周圍的圓角和填充。對于其他 DevExpress 皮膚,RoundedSkinPanel 會回退到標準的矩形邊框,而無需額外的填充。
文檔
?
?
- C#
// Create a TreeList.
TreeList treeList = new TreeList() { Dock = DockStyle.Fill };
// Create a RoundedSkinPanel and set it to fill the form.
roundedSkinPanel = new RoundedSkinPanel() { Dock = DockStyle.Fill };
// Add the TreeList to the panel.
roundedSkinPanel.Controls.Add(treeList);
// Add the panel to the form.
this.Controls.Add(roundedSkinPanel);
重要
RoundedSkinPanel 旨在承載單個 UI 控件。如果您嘗試添加多個,則在設計時將顯示警告。對于復雜的布局/UI 要求,只需嵌套多個控件即可。RoundedSkinPanel
?
受 Outlook 啟發的側邊導航
我們向 WinForms RibbonForm 添加了新屬性,以復制 Microsoft Outlook for Windows 的側邊導航布局。
這導航控制property 將導航控件指定為側邊導航元素(如 AccordionControl、NavigationPane 或 ToolboxControl)。這NavigationControlLayoutMode屬性將側邊導航與表單的標題對齊。對齊選項包括:
-
StretchToFormTitle
-
StretchToTop
- C#
using DevExpress.XtraBars.Ribbon;public partial class Form1 : RibbonForm {public Form1() {InitializeComponent();this.NavigationControl = accordionControl1;this.NavigationControlLayoutMode = RibbonFormNavigationControlLayoutMode.StretchToFormTitle;}
}
我們還更新了 WinFormsOutlook Inspired 應用程序演示:
安裝 DevExpress WinForms 產品庫.
?
條件格式
#表達式編輯器對自定義格式條件的支持
在 v25.1 中,用戶可以通過自定義表達式創建高級條件格式規則(將新的FilterEditorAllowCustomExpressions屬性激活 Conditional Formatting Rule Editor 中的 Expression Editor)。激活后,用戶可以定義復雜的邏輯(例如[創建日期] > AddDays(LocalDateTimeToday(), -3)) (如您所料,在構建依賴于計算值、函數或高級比較的格式設置規則時,此功能/功能提供了更大的靈活性)。
?
?
可用于以下 DevExpress WinForms UI 組件:
- Data Grid
- Pivot Grid
- TreeList (樹列表)
- Vertical Grid
?
#新過濾器
您現在可以根據應用的條件格式規則篩選數據。
用戶可以從以下位置應用這些篩選器:
- Excel 樣式的過濾器菜單
- Column Header Menu
- Filter Editor
文檔
安裝 DevExpress WinForms 產品庫.
?
基于網格的組件
#立即發布更改(使用 DevExpress 就地數據編輯器時)
我們的新選項讓您可以更好地控制 DevExpress 就地編輯器將值發布到底層數據源的方式/時間。InplaceModeImmediatePostChanges
啟用后,以下就地編輯器會立即將更新的值發布到數據源(無需轉移焦點):
- CheckEdit
- ToggleSwitch
- RadioGroup
- TrackBarControl
- RatingControl
- PopupBaseEdit?descendants
?
您還可以將該屬性設置為并使用InplaceModeImmediatePostChanges
WindowsFormsSettings.InplaceEditorUpdateMode屬性來全局控制更新行為:DefaultBoolean.Default
- Immediate(立即的)- 修改后立即發布編輯值。
- Postponed(推遲)- 當單元格失去焦點時發布編輯值。
文檔
?
#調整觸摸板上的水平滾動
DevExpress WinForms 基于網格的控件(如 GridControl、TreeList、Gantt Control 和 VGridControl)支持使用觸摸板平滑滾動。但是,某些用戶在 Windows 設備上使用觸摸板時可能會遇到倒置的水平滾動行為。
v25.1 引入了一個新的InvertHorizontalScrolling (反轉水平滾動)全局選項,當使用觸摸板或傾斜輪(具有 4 向滾動的鼠標或支持側向傾斜的軌跡球)時,該選項在我們的 WinForms 基于網格的控件中反轉當前的水平滾動方向。
在應用程序啟動時啟用該屬性(在
Program.cs) 反轉水平滾動方向。向右滑動手勢和鼠標水平滾輪移動將內容向左滾動。InvertHorizontalScrolling
- C#
static void Main() {Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);WindowsFormsSettings.InvertHorizontalScrolling = DevExpress.Utils.DefaultBoolean.True;Application.Run(new Form1());
}
?
#ItemsView - 數據驗證
v25.1 在 ItemsView 中包含 and 事件。ValidateRow
BeforeLeaveRow
?
數據編輯器
#步驟進度條 - UX 增強功能
我們改進了基于步驟的導航工作流的用戶體驗。在 v25.1 中,用戶可以按如下方式與項目交互:StepProgressBar
- 單擊項目以將其選中。
- 使用箭頭鍵在項目之間移動焦點。
- 壓進入或空間以選擇項目。
新的 StepProgressBar API 包括:
- StepProgressBar.AllowUserInteraction- 指定用戶是否可以與項目交互。
- StepProgressBarItem.AllowUserInteraction- 阻止用戶與特定項目交互。
- StepProgressBar.ItemClick- 當用戶單擊 StepProgressBar 中的某個項并允許您取消選擇時發生。
- C#
stepProgressBar1.AllowUserInteraction = true;
// ...
void StepProgressBar1_ItemClick(object sender, StepProgressBarItemClickEventArgs e) {if (IsDataSaved(e.Item)) return;if (XtraMessageBox.Show("You have unsaved changes. Would you like to save them?", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)e.Handled = true;
}
安裝 DevExpress WinForms 產品庫.
?
#SearchLookUpEdit - 同步查找面板文本
我們的 WinForms SearchLookUpEdit 允許用戶為彈出視圖指定查找面板文本,確保與查找過濾器文本財產。以前,修改該屬性不會更新查找面板的文本框,從而導致搜索行為不一致。此增強功能可確保查找面板顯示應用的實際過濾器。PopupView.FindFilterText
- C#
searchLookUpEdit.Properties.View.FindFilterText = "Mike";
?
#MemoEdit - 布局控件中的自動高度
我們的 WinForms MemoEdit 控件包括一個新的LayoutControlAutoHeightMode財產。此屬性指定 MemoEdit 在放置在布局控制.可用的自動高度模式包括:
?/?Default
- MemoEdit 高度保持固定,不根據內容進行調整。如果內容超過可用高度,則會顯示滾動條。None
- MemoEdit 高度會增加以適應內容,但不會在內容減少時降低。GrowOnly
- MemoEdit 高度會自動增加或減少以適應內容。GrowAndShrink
?
#CheckedListBoxControl - 自定義 SVG 校驗圖標
我們的 WinForms CheckedListBoxControl 現在支持用戶定義(自定義)SVG 校驗圖標。在 v25.1 中,您可以為選中、未選中和灰顯的項目狀態指定唯一圖標。此增強功能支持旨在匹配應用程序主題/UI 標準的自定義。
- C#
checkedListBoxControl1.CheckStyle = CheckStyles.UserDefined;
checkedListBoxControl1.ImageOptions.SvgImageChecked = svgImageCollection["checkedState"];
checkedListBoxControl1.ImageOptions.SvgImageUnchecked = svgImageCollection["uncheckedState"];
checkedListBoxControl1.ImageOptions.SvgImageSize = new System.Drawing.Size(16, 16);
?
#TokenEdit - 高級模式
v25.1 包括用于 WinForms TokenEdit 的新 API。使用這些 API,您可以自定義以下高級模式設置:
- 插入符號動畫 (
)AllowCaretAnimation
- 選擇動畫 (
)AllowSelectionAnimation
- 選區顏色自定義 (
)SelectionColor
使用TokenEdit.Properties.AdvancedModeOptions屬性以訪問高級模式設置:
- C#
// Enable Advanced Mode.
tokenEdit.Properties.UseAdvancedMode = DefaultBoolean.True;
// Enable caret animation.
tokenEdit.Properties.AdvancedModeOptions.AllowCaretAnimation = DefaultBoolean.True;
// Animate selection.
tokenEdit.Properties.AdvancedModeOptions.AllowSelectionAnimation = DefaultBoolean.True;
// Set selection color.
tokenEdit.Properties.AdvancedModeOptions.SelectionColor = Color.Yellow;
我們還實現了一個新的QueryAdvancedMode 查詢高級模式static 事件。此事件對項目中的每個 TokenEdit 控件觸發,并允許您根據自己的首選項配置高級模式設置。
- C#
using DevExpress.Utils;
using DevExpress.XtraEditors;
using System;
using System.Drawing;
using System.Windows.Forms;namespace DXApplication {internal static class Program {[STAThread]static void Main() {Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);TokenEdit.QueryAdvancedMode += TokenEdit1_QueryAdvancedMode;Application.Run(new Form1());}static void TokenEdit1_QueryAdvancedMode(object sender, TokenEdit.QueryAdvancedModeEventArgs e) {if(e.ParentForm is Form1) {// Enable Advanced Mode.e.UseAdvancedMode = DefaultBoolean.True;// Set the selection colore.Editor.Properties.AdvancedModeOptions.SelectionColor = Color.Yellow;}}}
}
?
AI 聊天控制
#文件附件
用戶現在可以將文件直接附加到他們的聊天消息中。這使 AI 能夠分析文檔內容(例如文本文件、PDF、圖像)并提供更多上下文感知響應。
啟用該屬性以允許用戶附加文件,并根據您的項目要求(最大文件大小、允許的文件類型/擴展名、用戶可以附加到消息的最大文件數)配置相關設置:FileUploadEnabled
- C#
aiChatControl1.FileUploadEnabled = DevExpress.Utils.DefaultBoolean.True;
?
#提示建議
為了幫助用戶入門或探索新的可能性,DevExpress AI Chat Control 可以顯示提示建議。
使用該方法提供智能建議:SetPromptSuggestions
- C#
using DevExpress.AIIntegration.Blazor.Chat.WebView;aiChatControl1.SetPromptSuggestions(new List<PromptSuggestion>(){new PromptSuggestion(title: "Birthday Wish",text: "A warm and cheerful birthday greeting message.",prompt: "Write a heartfelt birthday message for a close friend."),new PromptSuggestion("Thank You Note","A polite thank you note to express gratitude.","Compose a short thank you note to a colleague who helped with a project.")
});
?
#停止響應
用戶現在只需單擊一下即可中斷冗長的 AI 響應。
?
Accordion(手風琴)
#徽章和提示
我們將 WinForms Accordion Control 與 Adorner UI 管理器集成在一起,以幫助顯示徽章/提示并突出顯示特定的 Accordion UI 元素。
文檔
- C#
using System.Drawing;
using DevExpress.Utils.VisualEffects;
// ...
Badge badgeInbox;
public Form1() {InitializeComponent();badgeInbox = new Badge();// Assign the badge to the 'Inbox' accordion item.badgeInbox.TargetElement = accordionItemInbox;// Specify badge text.badgeInbox.Properties.Text = "17";// Specify badge location and offset.badgeInbox.Properties.Location = ContentAlignment.TopLeft;badgeInbox.Properties.Offset = new Point(85, 6);// Customize badge appearance.badgeInbox.Appearance.BackColor = Color.Gray;badgeInbox.Appearance.BorderColor = Color.Gray;badgeInbox.Appearance.ForeColor = Color.White;badgeInbox.Appearance.Font = new Font("Tahoma", 8.25F, FontStyle.Bold);// Add the badge to the AdornerUIManager.adornerUIManager1.Elements.Add(badgeInbox);
}
安裝 DevExpress WinForms 產品庫.
?
Map Control(地圖控件)
#Azure Maps - 新演示
以下演示已更新為使用新的 Azure Maps 數據提供程序。我們鼓勵您檢查我們的實施,以簡化您向 Azure Maps 的過渡:
- Map Elements
- Gpx Data Adapter
- Sales Dashboard
- Clustering
- Map Editor
- Photo Gallery
- Items Moving
- Vector Item Data Source
- Bubble Charts
- Coordinate Systems
- Geo Shape Image
安裝 DevExpress WinForms 產品庫.
?
Ribbon and Bars
#BarToggleSwitchItem - 切換開關寬度
在 v25.1 中,您可以指定切換開關欄項寬度。使用EditorToThumbWidthRatio屬性來設置項相對于 Thumb 寬度的總寬度。
Visual Studio 2010、Office 2013 和其他具有類似視覺樣式的外觀將縮略圖渲染為矩形。為了支持這些皮膚,我們添加了ThumbWidth (拇指寬度)財產。在這些外觀中,切換開關編輯器的總寬度計算為 和 屬性值的乘積。ThumbWidth
EditorToThumbWidthRatio
?
#手柄欄項右鍵單擊
WinForms Bar Manager 和 Ribbon Control 現在支持對 Bar 項進行右鍵單擊處理。新活動包括:
?????
- RibbonControl.ItemRightClick
- BarManager.ItemRightClick
- BarItem.ItemRightClick
我們還引入了一個新的 event 參數,允許您識別按下的鼠標按鈕。e.MouseButton
?
#Ribbon - Disable Double-Click Minimization
現在,您可以通過雙擊來最小化 DevExpress WinForms 功能區。此行為由允許 MinimizeRibbonOnDoubleClick財產。將此屬性設置為假以禁用雙擊最小化。
?
#Maximize/Minimize Ribbon
新的 API 包括:
- 最大化功能區 (RibbonPage)- 展開最小化的功能區。
- RibbonControl.AllowMinimizeRibbonOnDoubleClick- 指定用戶是否可以通過雙擊頁眉來最小化功能區。
?
#識別條形項目和條形鏈接
新的 API 包括:
- BarManager.GetItemAt(點)- 在指定的屏幕坐標處標識 bar 項。
- BarManager.GetLinkAt(點)- 標識指定屏幕坐標處的 BarItemLink。
- C#
barManager.ItemClick += (sender, e) => {BarItem item = barManager.GetItemAt(Cursor.Position);BarItemLink itemLink = barManager.GetLinkAt(Cursor.Position);Debug.WriteLine(item.Caption);Debug.WriteLine(itemLink.Caption);
};
?
PDF 查看器
#AI 驅動的行為
您現在可以在 DevExpress 中使用 AI 驅動的 Summarize、Translate 和 Ask AI 功能WinForms PDF 查看器.您可以使用 PDF 查看器的上下文菜單訪問所需的 AI作。
WinForms PDF Viewer AI 驅動的行為與我們 WinForms 產品線中的其他 AI 擴展具有相同的先決條件,并利用相同的集成機制。
有關其他信息,請參閱以下幫助主題:適用于 WinForms 的 DevExpress AI 驅動的擴展.
安裝 DevExpress WinForms 產品庫.
?
#保存時保留壓縮的對象流
我們的新壓縮引擎保留了 PDF 對象流的原始(壓縮)狀態。
?
#PDF 修訂 API
v25.1 包含用于創建和管理 PDF 密文注釋的新 API。這項新功能允許您從文檔中隱藏或刪除敏感或私人內容,并在編輯區域添加彩色文本疊加。
修訂過程包括兩個步驟:
- 在 PDF 頁面區域中創建具有所需外觀的密文批注(如果您希望隱藏內容但為其他用戶保留內容,則很有用)。
- 使用批注清除內容,并使用指定的外觀設置應用疊加。在這種情況下,所有隱藏的內容都將被刪除。
注意
密文支持可通過 PDF Facade API (DevExpress.Pdf.PdfDocument立面類)。此類在程序集中定義。將此程序集添加到項目中,或安裝DevExpress.Docs.v25.1.dll
DevExpress.Document.Processor從脫機包源獲取 NuGet 包以使用成員。PdfDocumentFacade
您需要DevExpress Office 文件 API 訂閱或DevExpress 通用訂閱在生產代碼中使用此類。
在代碼中創建和應用密文注釋
要創建密文注釋,請執行以下步驟:
- 使用PdfViewerControl.GetDocumentFacadeextension 方法獲取DevExpress.Pdf.PdfDocument立面實例。
- 從PdfDocumentFacade.Pages收集。
- 調用PdfPageFacade.AddRedactAnnotation方法。此方法返回PdfRedactAnnotationFacade對象,并允許您修改密文批注的以下外觀設置:背景顏色、疊加文本、文本字體設置(字體名稱、顏色、大小和樣式)、文本重復和對齊方式。
我們的新 API 允許您應用以下注釋:
- 單個修訂注釋:PdfRedactAnnotationFacade.應用
- 特定頁面的所有密文注釋:PdfPageFacade.ApplyRedact注釋
- 整個文檔中的所有密文注釋:PdfDocumentFacade.ApplyRedact注釋
您還可以使用DevExpress.Pdf.PdfClearContentOptions以指定在應用密文時要刪除的內容類型(文本、圖形、圖像或批注)。
- C#
pdfViewer.LoadDocument("Demo.pdf");
//...
PdfDocumentFacade documentFacade = pdfViewer.GetDocumentFacade();
PdfRectangle pageCropBox = pdfViewer.GetPageInfo(0).CropBox;
PdfRectangle redactBounds =new PdfRectangle(0, pageCropBox.Height-50, 200, pageCropBox.Height);// Add a redaction annotation at the top left corner of the first document page.
PdfRedactAnnotationFacade redactAnnotation =documentFacade.Pages[0].AddRedactAnnotation(redactBounds);
redactAnnotation.Author = "Jane Doe";
// Setup redaction annotation appearance
redactAnnotation.FillColor = new PdfRGBColor(0, 0, 0);
redactAnnotation.FontColor = new PdfRGBColor(1, 1, 1);
redactAnnotation.FontName = "Calibri";
redactAnnotation.FontSize = 0; // enables font auto-size
redactAnnotation.OverlayText = "Classified";
redactAnnotation.TextJustification = PdfTextJustification.Centered;
redactAnnotation.RepeatText = false;// Apply the redaction annotation.
redactAnnotation.Apply();
以下示例在 PDF 文檔中選擇一個區域(使用我們的 PDF 查看器時),并將密文批注應用于此區域:
適用于 WinForms 的 PDF 查看器 - 使用查看器坐標添加密文注釋?
電子表格控制
#OLE 對象
這DevExpress WinForms 電子表格控件現在支持 OLE 對象。OLE(對象鏈接和嵌入)允許您鏈接外部文件并將數據(電子表格、PDF、郵件消息、演示文稿等)嵌入到 Excel 文檔中。
使用 OLE 對象支持,您可以執行以下作:
- 創建 OLE 對象,用于存儲指向外部文件的鏈接或將這些文件中的數據嵌入到文檔中;
- 獲取 OLE 對象屬性;
- 從文檔中提取 OLE 對象數據;
- 從文檔中刪除 OLE 對象;
- 將帶有 OLE 對象圖標的文檔打印并導出為 PDF 和圖像格式;
- 加載和保存包含 OLE 對象的文檔,而不會丟失內容。
OLE 對象由接口表示。作為唯一的文檔形狀,OLE 對象從基本界面繼承所有設置。形狀設置定義 OLE 對象圖標的外觀、位置和內部對象屬性(包括名稱、圖標大小、工作表中的圖標位置、替換文本等)。OleObject
Shape
要訪問工作表中的 OLE 對象,請使用Worksheet.OleObjects收集。它們也可以通過底座獲得Worksheet.Shapes收集。OleObjectCollection.AddLinkedOleObject和OleObjectCollection.AddEmbeddedOleObject方法允許您在工作表中創建新的鏈接或嵌入的 OLE 對象。
- C#
Worksheet worksheet = spreadsheetControl.ActiveWorksheet;
CellRange oleIconRange = worksheet.Range["B4:D6"];
SpreadsheetImageSource oleIcon = SpreadsheetImageSource.FromFile("oleIcon.png");// Create linked OLE object.
OleObject oleObjectLinked = worksheet.OleObjects.AddLinkedOleObject(oleIconRange, "package.pdf", OleObjectType.Package, oleIcon);// Create embedded OLE object from byte array.
byte[] sourceData = File.ReadAllBytes("package.pdf");
OleObject oleObjectEmbedded1 = worksheet.OleObjects.AddEmbeddedOleObject(oleIconRange, sourceData, OleObjectType.Package, oleIcon);// Create embedded OLE object from file stream.
using (var stream = File.OpenRead("package.pdf")) {OleObject oleObjectEmbedded2 = worksheet.OleObjects.AddEmbeddedOleObject(oleIconRange, stream, OleObjectType.Package, oleIcon);
}
您還可以提取和分析鏈接數據和嵌入數據。使用OleObject.InsertType屬性來確定 OLE 對象類型(鏈接或嵌入)。OleObject.AsLinkedContent和OleObject.AsEmbeddedContent方法允許您根據 OLE 對象類型提取其他信息。對于鏈接對象,您可以使用OleObjectLinkedContent.FileName財產。對于嵌入對象,您可以使用OleObjectEmbeddedContent.GetRawData方法,或使用OleObjectEmbeddedContent.SaveAs方法。
- C#
Worksheet worksheet = spreadsheetControl.ActiveWorksheet
OleObject oleObject = worksheet.OleObjects[0];
if(oleObject.InsertType == OleObjectInsertType.Linked)
{OleObjectLinkedContent linkedContent = oleObject.AsLinkedContent();string linkedFileName = linkedContent.FileName;
}
if(oleObject.InsertType == OleObjectInsertType.Embedded)
{OleObjectEmbeddedContent embeddedContent = oleObject.AsEmbeddedContent();byte[] oleRawData = embeddedContent.GetRawData();if (oleObject.Type == OleObjectType.AdobeAcrobatDocument)using (FileStream stream = new FileStream("embedded_document.pdf", FileMode.Create, FileAccess.Write))embeddedContent.SaveAs(stream);
}
您還可以從電子表格中刪除 OLE 對象。使用OleObject.Delete,OleObjectCollection.Remove或OleObjectCollection.RemoveAt方法刪除單個 OLE 對象,或使用OleObjectCollection.Clear方法從工作表中刪除所有 OLE 對象。
- C#
OleObject oleObject = worksheet.OleObjects[0];// Remove the current OLE object.
oleObject.Delete();
// or
worksheet.OleObjects.Remove(oleObject);// Remove all OLE objects in the collection.
worksheet.OleObjects.Clear();
注意
OLE 對象支持僅以基于 OpenXML 的文件格式(XLSX、XLSM、XLTX 和 XLTM)提供。
文檔
如何:使用 RichEditControl API 創建可填寫的 PDF 表單
?
富文本編輯器
#從右到左 (RTL) 引擎增強功能
我們增強了從右到左文本渲染引擎(改進了段落、頁眉和頁腳、編號列表、表格和形狀中的文本順序,其中包含雙向文本,包括混合的從右到左和從左到右文本塊)。
當您通過用戶界面或代碼生成 PDF 文件、圖像或打印輸出時可用。
?
#CJK(中文、日文和韓文)文本換行
v25.1 添加了 CJK 文本換行和換行規則支持。在以前的版本中,我們的 Rich Text Editor 將拉丁文本換行規則(依賴于空格字符和標點符號)應用于中文、日語和韓語文本。
新的環繞規則可正確地在文檔段落、頁眉和頁腳、表格和形狀的單個字符之間應用換行符。使用 CJK 文本環繞規則的文檔現在可以打印/導出為具有適當文本布局的 PDF 和圖像格式。
?
#PDF 導出 - 將 Word 內容控件轉換為 PDF AcroForm 域
我們擴展了Word 文檔轉 PDF導出引擎,內置了 Word 內容控件到 PDF AcroForm 字段的轉換。
DevExpress 字處理工具會自動轉換以下內容控件類型:
- Plain Text
- Rich Text
- Picture
- Check Box
- Combo Box
- Drop-Down List
- Date Picker
注意
Building Block 和 Repeating Section 控件導出為常規文本。
由于 PDF 格式限制,從富文本內容控件生成的 PDF 文本字段使用原始富文本內容控件的第一個單詞的格式。
拆分頁面或包含復雜對象(如表格)的 RTF 內容控件將導出為常規文本。
要啟用此功能,您必須:
- 使用 DevExpress WinForms 富文本編輯器加載帶有內容控件的 Word 文件或在文檔中生成內容控件。
- 創建一個Pdf導出選項實例。
- 啟用PdfExportOptions.ExportEditingFieldsToAcroForms財產。
- 調用導出到 Pdf方法。
PdfExportOptions
您還可以使用對話框從用戶界面激活此功能。Print Preview -> PDF Export Options
- C#
using DevExpress.XtraPrinting;
using DevExpress.XtraRichEdit;richEditControl.LoadDocument("input_content_controls.docx");
PdfExportOptions options = new PdfExportOptions();
options.ExportEditingFieldsToAcroForms = true;
richEditControl.ExportToPdf("output_with_acroform.pdf", options);
?
#比較 Word 文檔
您現在可以以編程方式比較兩個 Word 文檔。我們的新擴展方法允許您執行以下作:CompareDocumentExtensions.Compare
- 識別兩個文檔版本之間的更改,并生成包含修訂版的 Word 輸出。
- 比較文檔文本和格式(包括區分大小寫)。
- 比較文檔頁眉、頁腳和文本框中的內容。
- 設置輸出修訂的作者/日期。
- 在單詞或字符級別比較內容。
- 將包含修訂的文檔作為新的 Document 實例返回以供進一步處理(或自動將輸入文檔替換為修訂后的內容)。
注意
輸入文檔不得包含文檔修訂。否則,該方法將引發異常。Compare
- C#
richEditControl.LoadDocument("FirstLook_original.docx");
Document originalDocument = richEditControl.Document;RichEditDocumentServer wordProcessor = new RichEditDocumentServer();
wordProcessor.LoadDocument("FirstLook_revised.docx");
Document revisedDocument = wordProcessor.Document;// Setup compare options, compare two documents,
// and add revisions to the RichEditControl document.
Document docWithRevisions = originalDocument.Compare(revisedDocument, new CompareDocumentOptions()
{Author = "Jane Doe",DateTime = DateTime.Now,ComparisonLevel = ComparisonLevel.Word,CompareCaseChanges = false,CompareFormatting = true,CompareHeadersAndFooters = true,CompareTextBoxes = true
}, ComparisonTargetType.Original);
注意
擴展方法在 DevExpress.Docs.v25.1.dll 程序集中定義。將此程序集添加到項目中,或安裝CompareDocumentExtensions.Compare
DevExpress.Document.ProcessorNuGet Package 以使用我們的方法。CompareDocumentExtensions.Compare
重要
您需要一個活躍的DevExpress Office 文件 API 訂閱或DevExpress 通用訂閱在生產代碼中使用此類。
?
XtraMessageBox
#顯示在 Windows 任務欄和自定義開始位置
借助新功能,您可以:
- 在 Windows 任務欄中顯示 DevExpress 消息框,確保用戶可以輕松訪問它。
- 定義 Message Box 在屏幕上的起始位置。
- C#
void messageButton_Click(object sender, EventArgs e) {XtraMessageBoxArgs args = new XtraMessageBoxArgs() {Caption = "Tip",Text = "Hello DevExpress!",Buttons = new DialogResult[] { DialogResult.OK },};args.ImageOptions.SvgImage = svgImageCollection1["info"];args.ImageOptions.SvgImageSize = new Size(32, 32);args.Showing += Args_Showing;XtraMessageBox.Show(args);
}
void Args_Showing(object sender, XtraMessageShowingArgs e) {// Get the screen working area.Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;// Calculate bottom-right position.int x = workingArea.Right - e.MessageBoxForm.Width;int y = workingArea.Bottom - e.MessageBoxForm.Height;// Define message box start position.e.MessageBoxForm.StartPosition = FormStartPosition.Manual;e.MessageBoxForm.Location = new Point(x, y);// Display the message box in the Windows taskbar.e.MessageBoxForm.ShowInTaskbar = true;
}
?