Add image to Label : Label : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Label »

 

Add image to Label








    
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;
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Label