0% found this document useful (0 votes)
4 views

labtask

The document contains code for a simple Counter App using Windows Forms in C#. It includes a button to increment a count displayed on a label, with the initial count set to zero. The app is structured with event handlers for button clicks to update the count accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

labtask

The document contains code for a simple Counter App using Windows Forms in C#. It includes a button to increment a count displayed on a label, with the initial count set to zero. The app is structured with event handlers for button clicks to update the count accordingly.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CODE :

namespace CounterApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.btnCount = new System.Windows.Forms.Button();
this.lblCount = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnCount
//
this.btnCount.Location = new System.Drawing.Point(100, 50);
this.btnCount.Name = "btnCount";
this.btnCount.Size = new System.Drawing.Size(100, 30);
this.btnCount.TabIndex = 0;
this.btnCount.Text = "Count";
this.btnCount.UseVisualStyleBackColor = true;
this.btnCount.Click += new System.EventHandler(this.btnCount_Click);
//
// lblCount
//
this.lblCount.AutoSize = true;
this.lblCount.Location = new System.Drawing.Point(100, 100);
this.lblCount.Name = "lblCount";
this.lblCount.Size = new System.Drawing.Size(13, 13);
this.lblCount.TabIndex = 1;
this.lblCount.Text = "0"; // Initial count
//
// Form1
//
this.ClientSize = new System.Drawing.Size(300, 200);
this.Controls.Add(this.lblCount);
this.Controls.Add(this.btnCount);
this.Name = "Form1";
this.Text = "Counter App";
this.ResumeLayout(false);
this.PerformLayout();
}

private void Form1_Load(object sender, EventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void btnCount_Click(object sender, EventArgs e)


{// Declare and initialize the counter variable inside the button click event
int count = int.Parse(lblCount.Text); // Get the current count from the label
count++; // Increment the counter
lblCount.Text = count.ToString(); // Update the label to show the current count
}
}
}

SCREENSHOT :

CODE :

You might also like