Advertisement
WindowsTV

Month Integer from textbox

Sep 29th, 2015
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Globalization;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12.  
  13. namespace Chase_Projec
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             int textBoxData;
  25.             bool isTextNumeric = int.TryParse(textBox1.Text, out textBoxData);
  26.             if (isTextNumeric)
  27.             {
  28.                  if (textBoxData <= 12)
  29.                 {
  30.                     var dateInfo = CultureInfo.CurrentCulture.DateTimeFormat;
  31.                     string monthName = dateInfo.GetMonthName(textBoxData);
  32.                     label2.Text = "Output: " + monthName;
  33.                 }
  34.                  else
  35.                  {
  36.                      MessageBox.Show("Not a valid month.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  37.                  }
  38.             }
  39.             else
  40.             {
  41.                 MessageBox.Show("Not a valid month.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  42.             }
  43.  
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement