Using classes on windows forms
C#
3
Posts
3
Posters
0
Views
1
Watching
-
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.
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()); } }
}
-
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.
Not sure what you mean... Probably this?
MessageBox.Show("Welcome!");
There are some overloads to change the title, icon, buttons etc. as well.