Add image to Label : Label « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » Label 
23.7.2.Add image to 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(2500);
    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;
  }
}
23.7.Label
23.7.1.Label Text ChangeLabel Text Change
23.7.2.Add image to LabelAdd image to Label
23.7.3.Add Image in an ImageList to a LabelAdd Image in an ImageList to a Label
23.7.4.Generic event for a LabelGeneric event for a Label
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.