LoadFromFile(Value: String; [Transparent: IGxColor = Null]);
Value. The parameter determines the string that specifies path to the file to be loaded to the component.
Transparent. This parameter determines the color to be used as transparent.
The LoadFromFile method loads an image in the component from the file, the path and name of which are passed by the Value parameter.
Executing the example requires a form with a button named Button1, a button named Button2, the TreeList component named TreeList1 with added element, the ImageList component named ImageList1, the FileOpenDialog component named FileOpenDialog1. Add links to the Drawing, Forms system assemblies. The file system should include an image with the images as a horizontal line: C:\temp\1.bmp.
Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Node: ITreeListNode;
Begin
ImageList1.LoadFromFile("C:\temp\1.bmp", GxColor.FromName("White"));
TreeList1.Images := ImageList1;
Node := TreeList1.Nodes.FirstNode;
Node.ImageIndex := 1;
Text := ImageList1.Count.ToString;
End Sub Button1OnClick;
Sub Button2OnClick(Sender: Object; Args: IMouseEventArgs);
Var
Node: ITreeListNode;
Begin
If FileOpenDialog1.Execute Then
ImageList1.LoadFromFile(FileOpenDialog1.FileName, GxColor.FromName("White"));
TreeList1.Images := ImageList1;
Node := TreeList1.Nodes.FirstNode;
Node.ImageIndex := 1;
Text := ImageList1.Count.ToString;
End If;
End Sub Button2OnClick;
Clicking the Button1 button in the TreeList component displays the second icon of the specified image and displays the number of icons in the form name. Clicking the Button2 button displays a dialog box to open an image, after that the second icon of the image and the number of icons in the form name are displayed in the TreeList component.
Executing the example requires a form with a button named Button1, a button named Button2, the TreeListNet component named treeListNet1 with added element, the ImageListNet component named imageListNet1, the OpenFileDialog component named openFileDialog1. Add links to the Drawing, Forms, Forms.Net system assemblies. The file system should include an image with the images as a horizontal line: C:\temp\1.bmp.
Imports Prognoz.Platform.Forms.Net;
Imports Prognoz.Platform.Interop.Forms;
Imports Prognoz.Platform.Interop.Drawing;
Sub LoadImageList(ilNet: Prognoz.Platform.Forms.Net.ImageListNet; fileName, clrName: string);
Var
ImageList: IImageList;
Clr: GxColor;
Begin
ImageList := (ilNet.Component As IImageList);
Clr := New GxColorClassClass().FromName(clrName);
ImageList.LoadFromFile(fileName, clr);
Text := ImageList.Count.ToString();
End Sub;
Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
Begin
LoadImageList(ImageListNet1, "C:\temp\1.bmp", "White");
TreeListNet1.CtrlBox.Images := imageListNet1.Component As Prognoz.Platform.Interop.Forms.ImageList;
TreeListNet1.ForeNodes.FirstNode.ImageIndex := 1;
End Sub;
Private Sub button2_Click(sender: System.Object; e: System.EventArgs);
Begin
If openFileDialog1.ShowDialog(self) = DialogResult.OK Then
LoadImageList(ImageListNet1, openFileDialog1.FileName, "White");
TreeListNet1.CtrlBox.Images := imageListNet1.Component As Prognoz.Platform.Interop.Forms.ImageList;
TreeListNet1.ForeNodes.FirstNode.ImageIndex := 1;
End If;
End Sub;
The result of the Fore.NET example execution matches with that in the Fore example.
See also: