Question

In C# Create a windows application which accepts the month number and displays the month name in a label. show the steps...

In C# Create a windows application which accepts the month number and displays the month name in a label. show the steps to follow in visual studio.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "MonthsApplication".This application contains a form with name "Form1.cs".Below are the files associated with form1.

1.Form1.cs[Design]

X Months Application Enter Month Number: Display Month Name

2.Form1.Designer.cs

namespace MonthsApplication
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtMonthNumber = new System.Windows.Forms.TextBox();
this.btnMonthName = new System.Windows.Forms.Button();
this.lblMonthName = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtMonthNumber);
this.groupBox1.Location = new System.Drawing.Point(24, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(249, 86);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Enter Month Number :";
//
// txtMonthNumber
//
this.txtMonthNumber.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.txtMonthNumber.Location = new System.Drawing.Point(21, 31);
this.txtMonthNumber.Multiline = true;
this.txtMonthNumber.Name = "txtMonthNumber";
this.txtMonthNumber.Size = new System.Drawing.Size(207, 29);
this.txtMonthNumber.TabIndex = 0;
//
// btnMonthName
//
this.btnMonthName.Location = new System.Drawing.Point(75, 116);
this.btnMonthName.Name = "btnMonthName";
this.btnMonthName.Size = new System.Drawing.Size(117, 29);
this.btnMonthName.TabIndex = 1;
this.btnMonthName.Text = "&Display Month Name";
this.btnMonthName.UseVisualStyleBackColor = true;
this.btnMonthName.Click += new System.EventHandler(this.btnMonthName_Click);
//
// lblMonthName
//
this.lblMonthName.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblMonthName.Location = new System.Drawing.Point(12, 162);
this.lblMonthName.Name = "lblMonthName";
this.lblMonthName.Size = new System.Drawing.Size(261, 54);
this.lblMonthName.TabIndex = 2;
this.lblMonthName.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(285, 225);
this.Controls.Add(this.btnMonthName);
this.Controls.Add(this.lblMonthName);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Months Application";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtMonthNumber;
private System.Windows.Forms.Button btnMonthName;
private System.Windows.Forms.Label lblMonthName;
}
}

3.Form1.cs

//namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//application namespace
namespace MonthsApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Month name button
private void btnMonthName_Click(object sender, EventArgs e)
{
//taking month number entered by user
int monthNumber;
if(int.TryParse(txtMonthNumber.Text,out monthNumber))
{
//display month name on the label
lblMonthName.Text= CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(monthNumber);
}
else
{
//display invalid message
lblMonthName.Text = "Enter valid number from 1 to 12";
  
}

}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :

X Months Application Enter Month Number: Display Month Name

Screen 2:Screen when invalid number is entered

Months Application Enter Month Number: asdf Display Month Name Enter valid number X

Screen 3:Screen showing month name

Months Application Enter Month Number: 6 Display Month Name June X

Screen 4:Screen showing month name

int month umsc Months Application Enter Month Number e C 11 Display Month Name November X

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
In C# Create a windows application which accepts the month number and displays the month name in a label. show the steps...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT