Label.Image : Label « System.Windows.Forms « C# / C Sharp by API






Label.Image

 

using System;        
using System.Drawing;
using System.Windows.Forms;

public class LabelImageAdding : Form
{
  Label lblEcho;
  TextBox txt;

  public LabelImageAdding()
  {
    Size = new Size(300,250);

    lblEcho = new Label();
    lblEcho.Parent = this;
    lblEcho.Text = "test";
    lblEcho.Location = new Point(0,0);
    lblEcho.AutoSize = true;
    lblEcho.BorderStyle = BorderStyle.Fixed3D;
    int yDelta = lblEcho.Height + 10;
    
    Image img = Image.FromFile("YourFile.bmp");
    Label lblImage = new Label();
    lblImage.Parent = this;
    lblImage.Location = new Point(250, 0);
    lblImage.Image = img;
    lblImage.Anchor = AnchorStyles.Top | AnchorStyles.Right;
    lblImage.Size = new Size(img.Width, img.Height);

    Label lblCaption = new Label();
    lblCaption.Parent = this;
    lblCaption.Text = "&Enter Text Here:";
    lblCaption.Size = new Size(lblCaption.PreferredWidth, lblCaption.PreferredHeight);
    lblCaption.Location = new Point(0, yDelta);
    lblCaption.BorderStyle = BorderStyle.FixedSingle;

    txt = new TextBox();
    txt.Parent = this;
    txt.Size = new Size(100,23);
    txt.Location = new Point(lblCaption.Width + 5, yDelta);
    txt.TextChanged += new System.EventHandler(txt_TextChanged);

  }

  static void Main() 
  {
    Application.Run(new LabelImageAdding());
  }

  private void txt_TextChanged(object sender, EventArgs e)
  {
    lblEcho.Text = txt.Text;
  }
}

   
  








Related examples in the same category

1.Label.Background
2.Label.Click
3.Label.DataBindings
4.Label.DoDragDrop
5.Label.ImageAlign
6.Label.ImageIndex
7.Label.ImageList
8.Label.Localtion
9.Label.Margin
10.Label.MouseDown
11.Label.MouseHover
12.Label.MouseMove
13.Label.MouseUp
14.Label.Size
15.Label.Text