Set Label's ImageList : Label « GUI « VB.Net Tutorial






Set Label's ImageList
imports System
imports System.Drawing
imports System.Windows.Forms

public class ImageLists : inherits Form

  dim imgList as ImageList = new ImageList()
    dim lbl as Label 
    dim lnk as LinkLabel
    dim btn as Button
    dim nmbrUpDown as NumericUpDown

  public sub New()
       Size = new Size(300,300)

    dim img as Image
    dim i as integer

    dim arFiles as string() = {"1.ico","2.ico","3.ico","4.ico"}

    for i = 0 to arFiles.Length - 1
      img = Image.FromFile(arFiles(i))
      imgList.Images.Add(img)
    next

    imgList.ImageSize = new Size(32, 32)

    img = Image.FromFile("5.ico")
    imgList.Images(imgList.Images.Count - 1) = img

       lbl = new Label()
       lbl.Parent = me
       lbl.Text = "Label"
       lbl.Location = new Point(0,0)
       lbl.Size = new Size (200,20)
       lbl.BorderStyle = BorderStyle.Fixed3D
    lbl.ImageList = imgList
    lbl.ImageIndex = 0
    lbl.ImageAlign = ContentAlignment.MiddleRight

    '  Create numeric updown to select the image
    nmbrUpDown = new NumericUpDown()
    nmbrUpDown.Parent = me
    nmbrUpDown.Location = new Point(0, 60)
    nmbrUpDown.Value = 0
    nmbrUpDown.Minimum = 0
    nmbrUpDown.Maximum = imgList.Images.Count - 1
    nmbrUpDown.Width = 50
    nmbrUpDown.ReadOnly = true
    AddHandler nmbrUpDown.ValueChanged,AddressOf nmbrUpDown_ValueChanged
    end sub

    public shared sub Main() 
      Application.Run(new ImageLists())
    end sub

    private sub nmbrUpDown_ValueChanged(ByVal sender as object,ByVal e as EventArgs)
      dim n as NumericUpDown  = CType(sender, NumericUpDown)
    lbl.ImageIndex = CType(n.Value, Integer)
    end sub
end class








14.2.Label
14.2.1.Label TextAlignLabel TextAlign
14.2.2.Change Label text and width in Button actionChange Label text and width in Button action
14.2.3.Change Label fontChange Label font
14.2.4.Use Color dialog to set the Label foreground colorUse Color dialog to set the Label foreground color
14.2.5.Label mouse click eventLabel mouse click event
14.2.6.Add image to LabelAdd image to Label
14.2.7.Set Label's ImageListSet Label's ImageList
14.2.8.Multiline LabelMultiline Label