翻譯|使用教程|編輯:龔雪|2024-05-22 10:24:21.167|閱讀 92 次
概述:本文將為大家介紹如何使用DevExpress報表組件時實現按條件顯示頁面水印,歡迎下載相關組件體驗!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
DevExpress WinForms擁有180+組件和UI庫,能為Windows Forms平臺創建具有影響力的業務解決方案。DevExpress WinForms能完美構建流暢、美觀且易于使用的應用程序,無論是Office風格的界面,還是分析處理大批量的業務數據,它都能輕松勝任!
在這篇文章中,我們將概述使用DevExpress WinForms HTML/CSS引擎/模板時重要的注意事項。如果您是DevExpress的新手或正在考慮使用我們的WinForms UI庫來開發即將到來的項目,并且尚未了解DevExpress WinForms HTML/CSS功能的潛力,請先花點時間查看以下在線內容:
在上文中()我們主要為大家介紹了如何使用HTML/CSS,本文將繼續介紹使用HTML/CSS的一些場景,請繼續關注我們哦~
DevExpress技術交流群10:532598169 歡迎一起進群討論
以下使用場景需要具備DevExpress WinForms UI控件和HTML/CSS的高級知識。
HTML/CSS模板允許您創建完全自定義的數據表單,如果DevExpress WinForms LayoutControl不能達到您的預期效果,那么我們建議使用HTML/CSS模板。使用HTML/CSS從頭開始構建布局可能很耗時,特別是對于具有多個字段的復雜表單。DevExpress的LayoutControl在構建時考慮了可訪問性,這包括適當的標簽、鍵盤導航支持以及與屏幕閱讀器的兼容性等特性。
并非所有的DevExpress WinForms UI控件都支持鼠標事件(出于性能原因),這個限制并不妨礙交互UI元素在DevExpress控件中顯示。盡管如此,它確實需要編寫更復雜的代碼:
DxHtmlPainterContext ctx = new DxHtmlPainterContext(); HtmlTemplate htmlTemplate = new HtmlTemplate( Loader.Load("ListBoxEmptyForeground.html"), Loader.Load("ListBoxEmptyForeground.css")); listControl.CustomDrawEmptyForeground += (s, e) => { e.DrawHtml(htmlTemplate, ctx); }; // Handles UI feedback (hover/cursor). listControl.MouseMove += (s, e) => { if(listControl.ItemCount == 0) { ctx.OnMouseMove(e); listControl.Cursor = ctx.GetCursor(e.Location); listControl.Invalidate(); } else listControl.Cursor = Cursors.Default; }; // Handles Click within the btnAdd element. var items = Enumerable.Range(1, 10) .Select(n => string.Format("Item #{0:d2}", n)) .ToArray(); listControl.MouseDown += (s, e) => { if(listControl.ItemCount == 0 && e.Button == MouseButtons.Left) { var clickInfo = ctx.CalcHitInfo(e.Location); if(clickInfo != null && clickInfo.HasId("btnAdd")) listControl.Items.AddRange(items); } };
與靜態模板不同,數據感知模板呈現需要編寫更多代碼(特別是需要從不同的源檢索數據時)。下面的示例在Grid單元格中繪制銷售徽章,折扣大小是從不同的數據源獲得的。
using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; using DevExpress.XtraGrid.Views.Base; using System.Collections.Generic; namespace DXApplication { public partial class Form1 : XtraForm { Dictionary<string, double> discounts = new Dictionary<string, double>() { { "A", 0.3 }, { "B", 0.45 }, { "C", 0.2 } }; public Form1() { InitializeComponent(); gridControl1.DataSource = new List<Product>() { new Product(){ Category = "A", Name = "AA", Price = 159.99}, new Product(){ Category = "A", Name = "AB", Price = 159.99}, new Product(){ Category = "B", Name = "BA", Price = 49.99}, new Product(){ Category = "B", Name = "BB", Price = 89.99}, new Product(){ Category = "C", Name = "CA", Price = 799.99}, }; gridView1.CustomDrawCell += GridView1_CustomDrawCell; } void GridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e) { e.DefaultDraw(); e.Handled = true; GridView view = sender as GridView; string category = view.GetRowCellValue(e.RowHandle, view.Columns["Category"]) as string; if (e.Column.FieldName == "Price" && discounts.ContainsKey(category)){ e.DrawHtml(htmlTemplateSaleBadge, args => { args.SetFieldValue("Discount", discounts[category].ToString("p0")); }); } } } public class Product { public string Name { get; set; } public string Category { get; set; } public double Price { get; set; } } }
DevExpress WinForms HtmlContentControl是使用HTML-CSS標記構建WinForms UI的“表面”,WinForms HtmlContentPopup是它的彈出菜單版本。這些組件從HTML/CSS代碼生成一個WinForms界面,并允許您設計定制的WinForms UI控件。使用DevExpress組件和HTML/CSS創建自定義UI控件是一項高級技術,需要深入了解UI開發的兩種技術/細微差別。
數據源可能包括存儲項目集合的數據字段:列表、數組、數據集等。<dx-collection>標簽是一個唯一的DevExpress元素,它允許您為需要可視化的項指定集合屬性(以及必須應用于這些項的模板)。使用自定義標記(如<dx-collection>)會對HTML模板施加特定的要求,以實現適當的功能。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都網