Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using classes on windows forms

Using classes on windows forms

Scheduled Pinned Locked Moved C#
csharpwinformslearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mamphekgo
    wrote on last edited by
    #1

    Hi.i am still learning C# so i am trying to create a simple class for greeting message so i want to display this message on a label on form.please send me a sample and explanation.

    L R 2 Replies Last reply
    0
    • M Mamphekgo

      Hi.i am still learning C# so i am trying to create a simple class for greeting message so i want to display this message on a label on form.please send me a sample and explanation.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      using System;
      using System.Windows.Forms;

      namespace TestForm
      {
      public class Form1 : System.Windows.Forms.Form
      {
      // Defining a label
      private System.Windows.Forms.Label label1;
      private System.ComponentModel.Container components = null;

      	public Form1()
      	{
      		this.SuspendLayout();
      		
      		// Create an instance of a label
      		this.label1 = new System.Windows.Forms.Label();
      		this.label1.Location = new System.Drawing.Point(24, 24);
      		this.label1.Name = "label1";
      		this.label1.Size = new System.Drawing.Size(72, 16);
      		this.label1.TabIndex = 0;
      		this.label1.Text = "Hello World";
      		this.Controls.Add(this.label1);
      
      		// Set all property that you need for your form
      		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      		this.ClientSize = new System.Drawing.Size(120, 61);
      		this.Name = "Form1";
      		this.Text = "Form1";
      		this.ResumeLayout(false);
      	}
      
      	\[STAThread\]
      	static void Main() 
      	{
      		// Run the Form1
      		Application.Run(new Form1());
      	}
      }
      

      }

      1 Reply Last reply
      0
      • M Mamphekgo

        Hi.i am still learning C# so i am trying to create a simple class for greeting message so i want to display this message on a label on form.please send me a sample and explanation.

        R Offline
        R Offline
        Robert Rohde
        wrote on last edited by
        #3

        Not sure what you mean... Probably this?

        MessageBox.Show("Welcome!");

        There are some overloads to change the title, icon, buttons etc. as well.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups