namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/* ---------- Random Part ---------- */
private void btRandom_Click(object sender, EventArgs e)
{
int rndm = MyRandom();
if (rndm > 5)
{
this.BackColor = Color.Aquamarine;
}
else
{
this.BackColor = Color.BurlyWood;
}
}
private int MyRandom() // สร้างฟังก์ชันสุ่มตัวเลขระหว่าง 0 ถึง 9
{
Random rndObj = new Random();
int i = rndObj.Next(10);
MessageBox.Show("ค่าที่สุ่มได้คือ : " + i.ToString(), "ฟังก์ชัน MyRandom");
return i;
}
/* ---------- Password Part ---------- */
private void btDefine_Click(object sender, EventArgs e)
{
if (CheckValidPassword(textPass.Text) == true)
{
MessageBox.Show("รหัสผ่านของท่านคือ : " + textPass.Text, "กำหนดรหัสผ่านสำเร็จ");
}
}
private bool CheckValidPassword(string pswd) // สร้างฟังก์ชันตรวจสอบรหัสผ่าน
{
if (pswd.Length < 4)
{
MessageBox.Show("คุณกำหนดรหัสผ่านสั้นเกินไป", "รหัสผ่านต้องมากกว่า 4 ตัวอักษร");
return false;
}
else if ((pswd == "1234") || (pswd == "abcd") || (pswd == "1111"))
{
MessageBox.Show("รหัสผ่านเดาง่ายเกินไป", "ผิดพลาด");
return false;
}
else return true;
}
/* ---------- Draw Matrix Part ---------- */
private void btDrawMtx_Click(object sender, EventArgs e)
{
int X = (int)nudX.Value;
int Y = (int)nudY.Value;
DrawMatrix(X, Y);
}
private void DrawMatrix(int XVal, int YVal) // สร้างฟังก์ชันวาดเมทริกซ์ จากพารามิเตอร์ที่กำหนด
{
string strOut = "";
for (int j = 1; j <= YVal; j++)
{
for (int i = 1; i <= XVal; i++)
{
strOut += i.ToString() + " ";
}
strOut += "\r\n";
}
textDisplay.Text = strOut;
}
/* ---------- Clear Part ---------- */
private void btClear_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("คุณต้องการเคลียร์ค่าในคอนโทรลหรือไม่", "Clear", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
ClearAll();
}
}
private void ClearAll() // สร้างฟังก์ชันสำหรับเคลียร์ค่าให้คอนโทรลต่างๆ
{
this.BackColor = SystemColors.Control;
textPass.Clear();
nudX.Value = nudX.Minimum;
nudY.Value = nudY.Minimum;
textDisplay.Clear();
MessageBox.Show("เคลียร์เรียบร้อยแล้วครับผม!", "Clear");
}
}
}
Sign up here with your email
ConversionConversion EmoticonEmoticon