News Ticker

Menu

Tuần 1 - Bài 1 đã edit


fBai1Edit.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Week1_Bai1
{
    public partial class fBai1Edit : Form
    {
        public fBai1Edit()
        {
            InitializeComponent();
        }

        private void fBai1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult r;
            r = MessageBox.Show("Thí chủ có muốn đóng chương trình không?", "Chú Ý!", 
                MessageBoxButtons.YesNo, 
                MessageBoxIcon.Question, 
                MessageBoxDefaultButton.Button1);
            if (r == DialogResult.No)
                e.Cancel = true;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txbName.Clear();
            txbYear.Clear();
            txbName.Focus();
        }

        private void txbName_Leave(object sender, EventArgs e)
        {
            Control ctr = (Control)sender;
            if (ctr.Text.Trim().Length == 0)
                this.errorProvider1.SetError(ctr, "Bạn đã để trống!");
            else
                this.errorProvider1.Clear();
        }

        private void txbYear_TextChanged(object sender, EventArgs e)
        {
            Control ctr = (Control)sender;
            if (ctr.Text.Length > 0 && !Char.IsDigit(ctr.Text[ctr.Text.Length - 1]))
                this.errorProvider1.SetError(ctr, "Đây không phải giá trị số");
            else
                this.errorProvider1.Clear();
        }

        private void btnShow_Click(object sender, EventArgs e)
        {

            try
            {
                int age = DateTime.Now.Year - Convert.ToInt32(txbYear.Text);
                string s = txbName.Text;
                if (s == "")
                    s = "Vô danh tiểu tốt!";
                else
                    s = txbName.Text;
                MessageBox.Show("Bạn tên là: " + s + "\n\nTuổi: " + age.ToString(), "Thông tin của bạn!");
            }
            catch
            {
                if (txbName.Text.Length != 0 && txbYear.Text.Length == 0)
                {
                    MessageBox.Show("Bạn tên là: " + txbName.Text + "\n\nTuổi: 0", "Thông tin của bạn!");
                }
                else if(txbName.Text.Length == 0 && txbYear.Text.Length == 0)
                    MessageBox.Show("Bạn chưa nhập gì cả!",  "THÔNG BÁO!", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                    
            }

        }
    }
}
Link: Project

Share This:

Post Tags:

Welcome To Task Marks

I'm Task Marks. Tôi là chủ trang web này, trang này tôi dùng để chia sẽ tài liệu và những thứ linh tinh khác. Cảm ơn mọi người đã ghé thăm trang web của chúng tôi.Nếu có thắt mắt xin vui lòng liên hệ
Mail: devnguhoc@gmail.com

No Comment to " Tuần 1 - Bài 1 đã edit "

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM