| List for WinForms Tutorials > Tutorial 14 Displaying Bitmaps |
In this tutorial, you will learn how to use Style objects to display arbitrary bitmaps within list cells. In addition to font, color, and alignment settings, Style objects support both background and foreground pictures. Background pictures can be centered, tiled, or stretched to fill the entire cell. Foreground pictures can be positioned relative to the cell text, and can also be displayed using a transparent color.
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
' Get the image directory.
Dim dir As String
dir = Environment.CurrentDirectory
dir = dir.Substring(0, dir.LastIndexOf("\"))
dir = dir & "\Flags"
Me.TextBox1.Text = dir
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
// Get the image directory.
string dir;
dir = Environment.CurrentDirectory;
dir = dir.Substring(0, dir.LastIndexOf("\"));
dir = dir + "\Flags";
this.TextBox1.Text = dir;
|
|
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
' Add the title.
Me.C1List1.AddItemTitles("File Name; Picture")
' Extend the second column width.
Me.C1List1.ExtendRightColumn = True
' Enlarge the row height.
Me.C1List1.ItemHeight = 50
' Add the items for the list.
Dim dir, str, fileName As String
dir = Me.TextBox1.Text.Trim()
Dim strCol As String()
strCol = System.IO.Directory.GetFiles(dir, "*.bmp")
For Each str In strCol
fileName = str.Substring(str.LastIndexOf("\") + 1)
Me.C1List1.AddItem(fileName & ";")
Next str
' Fire the FecthCellStyle event.
Me.C1List1.Splits(0).DisplayColumns(1).FetchStyle = True
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
// Add the title.
this.c1List1.AddItemTitles("File Name; Picture");
// Extend the second column width.
this.c1List1.ExtendRightColumn = true;
// Enlarge the row height.
this.c1List1.ItemHeight = 50;
// Add the items for the list.
string dir, str, fileName;
dir = this.TextBox1.Text.Trim();
string[] strCol;
strCol = System.IO.Directory.GetFiles(dir, "*.bmp");
foreach ( str in strCol)
{
fileName = str.Substring(str.LastIndexOf("\") + 1);
this.c1List1.AddItem(fileName + ";");
}
// Fire the FecthCellStyle event.
this.c1List1.Splits[0].DisplayColumns[1].FetchStyle = true;
|
|
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub C1List1_FetchCellStyle(ByVal sender As Object, ByVal e As C1.Win.C1List.FetchCellStyleEventArgs) Handles C1List1.FetchCellStyle
If e.Col = 1 Then
' Get the image name.
Dim file As String
file = Me.C1List1.Splits(0).DisplayColumns(0).DataColumn.CellText(e.Row)
file = Me.TextBox1.Text.Trim() & "\" & file
e.CellStyle.ForeGroundPicturePosition = C1.Win.C1List.ForeGroundPicturePositionEnum.PictureOnly
e.CellStyle.ForegroundImage = Image.FromFile(file)
End If
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void C1List1_FetchCellStyle( object sender, C1.Win.C1List.FetchCellStyleEventArgs e)
{
if ( e.Col == 1 )
{
// Get the image name.
string file;
file = this.c1List1.Splits[0].DisplayColumns[0].DataColumn.CellText(e.Row);
file = this.TextBox1.Text.Trim() + "\" + file;
e.CellStyle.ForeGroundPicturePosition = C1.Win.C1List.ForeGroundPicturePositionEnum.PictureOnly;
e.CellStyle.ForegroundImage = Image.FromFile(file);
}
}
|
|

For more information, see Applying Pictures to List Elements.
This concludes the tutorial.