下面的示例演示了如何为 Field List(字段列表) 元素提供自定义图像。
要完成此任务,需要创建一个继承自 FieldListService 基本类的自定义 Field List(字段列表) 服务,并重写 FieldListService.GetColumnImageIndex 方法。 然后,为了激活此自定义服务,需要把它的实例指派到 FieldListService.Instance 静态属性。
C# | 复制代码 |
---|
(Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraReports.UserDesigner;
namespace FieldListCustomIcons {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
FieldListService.Instance = new CustomFieldListService();
}
private void button1_Click(object sender, EventArgs e) {
new XtraReport1().ShowDesignerDialog();
}
}
}
|
C# | 复制代码 |
---|
(CustomFieldListService.cs)
using System.Drawing;
using System.ComponentModel;
using DevExpress.Utils;
using DevExpress.XtraReports.UserDesigner;
namespace FieldListCustomIcons {
class CustomFieldListService : FieldListService {
int categoryNameIndex;
public override int GetColumnImageIndex(PropertyDescriptor property,
string dataMember, bool isList) {
if (dataMember.Contains("CategoryName")) {
return categoryNameIndex;
}
return base.GetColumnImageIndex(property, dataMember, isList);
}
public override DevExpress.Utils.ImageCollection CreateImageCollection() {
ImageCollection result = base.CreateImageCollection();
Image image =
ResourceImageHelper.CreateBitmapFromResources("FieldListCustomIcons.DataPickerImage.png",
typeof(CustomFieldListService).Assembly);
result.AddImage(image);
categoryNameIndex = result.Images.Count - 1;
return result;
}
}
}
|
Visual Basic | 复制代码 |
---|
(CustomFieldListService.vb)
Imports Microsoft.VisualBasic
Imports System.Drawing
Imports System.ComponentModel
Imports DevExpress.Utils
Imports DevExpress.XtraReports.UserDesigner
Namespace FieldListCustomIcons
Friend Class CustomFieldListService
Inherits FieldListService
Private categoryNameIndex As Integer
Public Overrides Function GetColumnImageIndex(ByVal [property] As PropertyDescriptor, ByVal dataMember As String, ByVal isList As Boolean) As Integer
If dataMember.Contains("CategoryName") Then
Return categoryNameIndex
End If
Return MyBase.GetColumnImageIndex([property], dataMember, isList)
End Function
Public Overrides Function CreateImageCollection() As DevExpress.Utils.ImageCollection
Dim result As ImageCollection = MyBase.CreateImageCollection()
Dim image As Image = ResourceImageHelper.CreateBitmapFromResources("FieldListCustomIcons.DataPickerImage.png", GetType(CustomFieldListService).Assembly)
result.AddImage(image)
categoryNameIndex = result.Images.Count - 1
Return result
End Function
End Class
End Namespace
|
Visual Basic | 复制代码 |
---|
(Form1.vb)
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraReports.UserDesigner
Namespace FieldListCustomIcons
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
FieldListService.Instance = New CustomFieldListService()
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
CType(New XtraReport1(), XtraReport1).ShowDesignerDialog()
End Sub
End Class
End Namespace
|
在下面的插图中显示了结果。
参阅