You are on page 1of 122

Color Progress Bar with Timer

ကြ်န္ေတာ္ တိ႔ု ဒီေန႔ timer နဲ႔ Color progress Bar အေၾကာင္း ေဆြးေႏြးပါ့မယ္။ အရင္ဆံုး window
form ကိုဖြင့္လိုက္ပါ။ျပီးရင္ toolbox ကေန color progress bar ကို ေရြးရမွာ ျဖစ္ပါတယ္။ ဒါေပမယ့္ tool box
မွာ အဲေကာင္ ရွိမေနပါဘူး။ အဲေတာ့ tool ကို add ရပါမယ္။ အဲဒီ tools က Visual Studio install လုပ္စဥ္က
လည္းပါမလာပါဘူး။ https://www.dropbox.com/s/bro5naj5igzv8aj/colorprogressbar.rar ဒီလင့္မွာ
ကြ်န္ေတာ္ တင္ေပးထားပါတယ္။ ေဒါင္းလိုက္ပါ။ ျပီးရင္ Desktop ေပၚတင္ထားလိုက္ပါ။ZIP ဖိုင္ကို
ျဖည္လိုက္ပါ။ျပီးရင္ အဲေကာင္ကို add ပါမယ္။ Visual Studio tool Bar ေပၚက Tools---Choose toolbox
items--- ေအာက္ေျခနားက Browse ကိုသြားလိုက္ပါ။ျပီးရင္ desktop ေပၚက ကြ်န္ေတာ္တို႔ေဒါင္းထားတဲ့
colorprogressbar.dll ဆိုတာကို ေပးလိုက္ပါ။ျပီးရင္ .Net FrameWork component မွာ colorprogressbar
ဆိုတာကိုေရြးျပိး အမွန္ျခစ္ေပးလိုက္ပါ။ (tools add တာကို
https://www.facebook.com/771934899529239/photos/pcb.774283562627706/77428118596127
7/?type=1&theater အထက္ပါ လင့္မွာ Code ျဖင့္ Button မ်ား ဖန္တီးျခင္းဆိုတဲ့ ေခါင္းစဥ္ေအာက္မွာ
ပံုႏွင့္တကြ ရွင္းခဲ့ျပီး ျဖစ္ပါတယ္။မရွင္းတာရွိရင္ ျပန္ၾကည့္လိုက္ပါ။) အခုဆို ကြ်န္ေတာ္ တု႔ိ tool box ထဲမွာ color
progress bar ဆိုတာ ေရာက္သြားျပီ။ ရွာျပီး Form ေပၚကို 6 ခု ရေအာင္ ဆြဲတင္လိုက္ပါ။ ျပီးရင္ သူ႕ရဲ႕
properties- Back color မွာ ကိုယ္ ေျပာင္းခ်င္တဲ့ အေရာင္ေတြ ေျပာင္းလိုက္ပါ။ ျပီးရင္ Name မွာ
ေအာက္ပါအတိုင္းေပးလိုက္ပါ။

Properties -- Name---color progress bar 1--cpb1

Properties -- Name---color progress bar 2--cpb2

Properties -- Name---color progress bar 3--cpb3

Properties -- Name---color progress bar 4--cpb4

Properties -- Name---color progress bar 5--cpb5

Properties -- Name---color progress bar 6--cpb6

ေအာက္ပါ ပံု(၁) အတိုင္းရရွိလာမွာ ျဖစ္ပါတယ္။ toolbox မွာ နာရီပံုေလးနဲ႔ timer ကို Form ေပၚသို႔႕
ဆြဲတင္လိုက္။ ျပီးရင္ timer properties မွာ ေအာက္ပါ အတိုင္း ျပင္လိုက္ပါ။

Name-- timer1

Enables—True

GeneratedMember--- True
Interval---- 100

Modifiers ---- Private

ျပင္ျပီးသြားရင္ နာရီပံုေလးကို double click ေပးလိုက္ပါ။ ေအာက္ပါ code ကိုေရးျပီး run လိုက္ပါ။ ပံု(၂) အတိုင္း
ရပါလိမ့္မယ္။

private void timer1_Tick(object sender, System.EventArgs e)


{
//
// All values are reseted at the end
//
cpb1.PerformStep();
if (cpb1.Value == cpb1.Maximum)
cpb1.Value = cpb1.Minimum;

cpb2.PerformStepBack();
if (cpb2.Value == cpb2.Minimum)
cpb2.Value = cpb2.Maximum;

cpb3.Increment(1);
if (cpb3.Value == cpb3.Maximum)
cpb3.Value = cpb3.Minimum;

cpb4.Decrement(1);
if (cpb4.Value == cpb4.Minimum)
cpb4.Value = cpb4.Maximum;

cpb5.Increment(1);
if (cpb5.Value == cpb5.Maximum)
cpb5.Value = cpb5.Minimum;

cpb6.Decrement(1);
if (cpb6.Value == cpb6.Minimum)
cpb6.Value = cpb6.Maximum;
}
အခုဆို ကြ်န္ေတာ္ တို႔ timer နဲ႔ color progress bar တြဲတာ ျပီးပါျပီ။ dll file ေလး add တာ တခုဘဲ
ေျပာစရာရွျိပီး coding ပိုင္းမွာေတာ့ အေထြအထူးေျပာစရာ မရွိပါဘူး။ ဒါေပမယ့္ timer နဲ႔ progress bar ရဲ႕
properties မွာေတာ့ ေျပာစရာရွိေနပါတယ္။ Timer မွာ progress bar ရဲ႕ speed ကို interval ဆိုတဲ့
ၾကာခ်ိန္က ထိန္းခ်ဴပ္ထားပါတယ္။ interval တန္ဖိုးနဲလည္း ၾကာခ်ိန္တိုေလ၊ progressbar ေတြရဲ႕ speed
ျမန္ေလ ျဖစ္ပါတယ္။ တန္ဖိုးမ်ားရင္ ပိုၾကာျပီး progress bar ေတြရဲ႕ speed လည္း ေႏွးေလျဖစ္ပါတယ္။
ဒီေနရာမွာ timer ရဲ႕ interval ကို အတိုးအေလ်ာ့လုပ္ျပီး စမ္းၾကည့္ပါ။ progress bar ေတြရဲ႕ feature ပိုင္းနဲ႔
ပက္သက္ျပီးေတာ့လည္းသူ႕ရဲ႕ properties မွာ က တန္ဖိုးေလးေတြေျပာင္းျပီးကိုယ္တိုင္
ကလိေစခ်င္ပါတယ္။အဲဒါမွ ပိုနားလည္သြားမွာပါ။ မနက္ျဖန္မွာေတာ့ ဧည့္သည္ တေယာက္ ေမးထးတဲ့
system.thread အေၾကာင္းကို ကို ဆက္လက္ေဆြးေႏြးသြားမွာျဖစ္ပါတယ္။အားလံုးဘဲ အဆင္ေျပၾကပါေစ။

ပံု-၁
ပံု-၂

Timer

Framework မွာ timer နဲ႔ ပက္သက္ျပီး ေအာက္ပါ အတိုင္း (၃) ပိုင္းခြဲျခားႏိုင္ပါတယ္။


1. System.Timers.Timer
2. System.Windows.Forms.Timer
3. System.Threading.Timer

Form timer ကေတာ့ Form ေပၚမွာဘဲ အလုပ္လုပ္တာပါ။ က်န္တဲ့ timer ၂ ခုကေတာ့ console
မွာေရာ form မွာပါ အလုပ္လုပ္ႏိုင္ပါတယ္။

Thread နဲ႔ Timer က မတူပါဘူး တဲ့။ကြဲျပားျခားနားၾကပါတယ္လို႔ Developer ေတြက တိတိက်က်


ဆိုၾကပါတယ္။ ဒါေပမယ့္ ရိုးသားစြာ ၀န္ခံရရင္ ရွင္းျပဘို႔ ေတာ္ေတာ္ ခက္ပါတယ္။ timer နဲ႔
ပက္သက္ျပီး အေထြအထူးေျပာစရာ မရွိေပမယ့္ Thread ကေတာ့ သီးသန္႔စာအုပ္အျဖစ္ ေလ့လာစရာ
ေတာင္ ရွိေနပါတယ္။ ေနာက္ဆံုး Parallel Programming ထိေတာင္ သီအိုရီ သေဘာတရား အရ
ဆက္စပ္ေနပါတယ္။

အခု ကြ်န္ေတာ္ နားလည္သေလာက္ ေျပာျပသြားပါ့မယ္။ Timer ကို နားလည္ေအာင္ ေျပာရရင္


ကြ်န္ေတာ္ တိ႔ု နာရီေတြမွာ သံပတ္ ေပးသလိုပါဘဲ။မနက္ (၇) နာရီမွာ ထ ခ်င္တယ္ဆိုရင္ (၇) နာရီ
သံပတ္ေပးထားလိုက္။(၇) နာရီထိုးရင္ထျမည္လိမ့္မယ္။ ကိုယ္ျဖစ္ေစခ်င္တဲ့ အျဖစ္အပ်က္တခုကို
ျဖစ္လာဘိ႔ု အတြက္ အခ်ိန္ကို ၾကိဳတင္သတ္မွတ္ေပးထားရတာ။ program မွာေတာ့ တိက်တဲ့
အခ်ိန္ပိုင္း interval တခုအတြင္းမွာ အလုပ္လုပ္ေစခ်င္တဲ့ အခါမ်ိဴးေတြမွာ သံုးၾကပါတယ္။

Thread - ဆိုတာ သူကေနျပီးေတာ ေနာက္ထပ္ thread ေတြ ခြဲထုတ္ျပီး အလုပ္ေတြကို တခ်ိန္ထဲမွာဘဲ


အမ်ားၾကီး လုပ္ႏိုင္တယ္။ နည္းပညာ term နဲ႔ ေျပာရရင္ simultaneously or synchronized ျဖစ္တယ္
ေျပာရမွာေပါ့ေနာ္။ တခ်ိန္ထဲမွာ တျပိဳင္နက္ထဲ လုပ္ႏိုင္တာျဖစ္တဲ့အတြက္ Parallel ျဖစ္တယ္လို႔လဲ
ေျပာလိ႔ရ
ု တယ္။ Program တခုမွာ thread ေတြ မ်ားၾကီး ရွိေနႏို္င္ပါတယ္။ဥပမာ ကြ်န္ေတာ္ တိ႔ရ
ု ဲ႕ C#
Client program မွာဘဲ ဆိုၾကပါစို႔။ console, Windows Form, WPF အစရွိသျဖင့္ project တခု
စယူလိုက္ျပီဆိုရင္ CLR က အလိုအေလ်ာက္ ဖန္တီးေပးျပီး Operating System မွာလည္း၎ တို႔
အတြက္ ဆက္စပ္တဲ့ thread ေတြကို တျပိဳင္နက္ထဲ ဖန္တီးေပးသြားပါတယ္။ေျပာရရင္ဗ်ာ။ OS ၾကီးက
main thread, CLR က သူကေန ခဲြထုတ္လိုက္တဲ ့Thread (worker thread လိ႔ေ
ု ခၚတယ္။)။ window
Form က CLR ရဲ႕ worker thread. ကြ်န္ေတာ္ တိ႔ု window form ေပၚမွာ ဖန္တီးလိုက္တဲ့ tools ေတြက
window form ရဲ႕ worker thread ထပ္ျဖစ္ျပန္ေရာ။ ဒီျဖစ္စဥ္ကိုနမႈနာေျပာရရင္ OS က အဘိုး။
သူကေမြးလိုက္တဲ့ သားက CLR ။ CLR က ေမြးလိုက္တဲ့သားက Window form(OS ရဲ႕ ေျမး။) ။
Window form ေပၚက tools ေလးေတြက သူ႕သားသမီး(OS ရဲ႕ ျမစ္။)။ ေဆြမ်ိဴးစပ္ရတာ
ေတာ္ေတာ္ရူပ္တာဘဲေနာ္ :D

ဒီ ဥပမာ နားမလည္မွာ စုိးလိ႔ု ေနာက္ထပ္ဥပမာ တခုေပးမယ္ဗ်ာ။ ေက်ာင္းသားေတြ အမ်ားၾကီး ရွိတဲ့


စာသင္ခန္းထဲ တစ္ခန္း ဆိုၾကပါစို႔ ။ ဆရာကေန ေက်ာင္းသားေတြကို မုန္႕ဟင္းခါး ခ်က္ဘို႔
တာ၀န္ေပးလိုက္တယ္။ ေက်ာင္းသားေတြ ၾကက္သြန္ခြာတဲ့သူကခြာ၊ ထင္းခြဲသူခြဲ၊၊ေရခပ္သူခပ္၊ မုန္႔ဖက္
၀ယ္သ၀
ူ ယ္ နဲ႔ အဲဒီအလုပ္ေတြကို တာ၀န္ခြဲယူျပီးတျပိဳင္နက္ထဲလုပ္ၾကတယ္။
ရည္မွန္းခ်က္ကေတာ့တခုထဲဘဲ။ မုန္႕ဟင္းခါးခ်က္ဘို႔။(က်က္ရင္ေတာ့လ က္တ႔လ
ို ိုက္ဦးဗ်ာ။
မစားရတာၾကာျပီ :D )။

ဒီေနရာမွာ အထက္က timer နဲ႕ Thread ကို ယွဥ္ၾကည့္ဗ်ာ။ timer က တျပိဳက္နက္ထဲ


အလုပ္မလုပ္ႏိုင္ဘူး။ thread ကက် လုပ္ႏို္င္တယ္။ Timer ကို အခ်ိန္တို event ေတြ အတြက္သံုးရင္
ပိုသင့္ေလ်ာ္ျပီး၊ thread ကက် long time ေတြ အတြက္ ပိုသင့္ေလ်ာ္ပါတယ္။ နာရီသံပတ္ေပးတဲ့
ဥပမာျပန္ၾကည့္ဗ်ာ။ စားပဲြတင္နာရီ တခုမွာ တျပိဳင္နက္ထဲ အခ်ိန္ ၂ ခုကို သံပတ္ေပးလို႔မရဘူး။
ဟုတ္တယ္လား။ (အျခား တျပိဳင္ထဲ ၂ ခု ေပးလိ႔ရ
ု တဲ့ နာရီေတြက ဒီဥပမာထဲမွာအက်ဴံးမ၀င္ပါ :P) ။
သူ႕မွာ က thread လို ကူလုပ္ေပးမဲ့သူမွ မရွိတာေလ။ Timer နဲ႔ Thread ၾကား ကြဲျပားျခားနားခ်က္
ေတြကို ေအာက္က ပံု(၁) ဇယား မွာ ေဖၚျပေပးလိုက္ပါတယ္။

System.Windows.Forms System.Timers System.Threading

Timer event runs on UI thread UI or worker Worker thread


what thread? thread

Instances are thread No Yes No


safe?

Familiar/intuitive object Yes Yes No


model?

Requires Windows Yes No No


Forms?

Metronome-quality No Yes* Yes*


beat?

Timer event supports No No Yes


state object?

Initial timer event can No No Yes


be scheduled?

Class supports Yes Yes No


inheritance?

* Depending on the availability of system resources (for example, worker threads)


ေအာက္မွာ thread console program ဥပမာ ေပးလိုက္ပါတယ္။

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(WriteY); // Kick off a new thread
t.Start(); // running WriteY()

// Simultaneously, do something on the main thread.


for (int i = 0; i < 1000; i++) Console.Write("x");
Console.ReadLine();
}
static void WriteY()
{
for (int i = 0; i < 1000; i++) Console.Write("y");
}

}
}

၎ ရဲ႕ အလုပ္လုပ္ပံုကို ေအာက္က ပံု (၂) မွာ ပံု နဲ႔တကြ ရွင္းျပထားပါတယ။္ ဒီေနရာမွာ main thread
က X ျဖစ္ျပီးိ Worker thread က Y ျဖစ္ပါတယ္။ အဲဒီ ၂ ခုက တျပိဳင္တည္း အလုပ္လုပ္ျပီး application
end မွာ တျပိဳင္တည္းျပီးပါတယ္။အဲဒါကိုေသခ်ာရွင္းရွင္းလင္း နားလည္ခ်င္ရင္ အထက္ပါ program ကို
F11 ႏွိပ္ျပီး trace လိုက္ၾကည့္ပါ။Trace မလိုက္တတ္ရင္ ေနာက္အခန္းမွာ ကြ်န္ေတာ္ trace
လိုက္နည္းကို ပံုႏွင့္တကြ ေဆြးေႏြးေပးပါ့မယ္။

Timer ႏွင့္ Thread ကို Progress Bar တြင္ အသုံးျပဳျခင္း


ကြ်န္ေတာ္ Progress Bar ကို ေအာက္ပါ time ပံုစံ (၃)မ်ိဴးနဲ႔ အသံုးျပဳသြားမွာျဖစ္ပါတယ္။

(1)Timer,

(2)Thread

(3) Thread with Background worker

ကိုယ္တိုင္ Progressbar ေလး ဖန္တီးရတာ တမ်ိဴးေပ်ာ္စရာေကာင္းပါတယ္။အိုေက။


စၾကရေအာင္။ပထမဦးဆံုး Window Form တခုယူလိုက္ပါ။ျပီးရင္ toolbox က ေအာက္ပါဆိ႔က
ု ို
ယူလိုက္ပါ

1-Background worker (1)ခု

2-Button (3) ခု

3- ProgressBar(3) ခု

4- timer(1) ခု

ျပီးရင္ လိုအပ္တဲ့ properties setting ေတြျပင္မယ္။ အရင္ဆံုး Background worker ကိုျပင္မွာ


Modifier---- > public နဲ႔ က်န္တာအားလံုး true ေပးလိုက္ပါ။သူ႕ရဲ႕ နဂို default က false ေတြပါ။
အဲဒါကို true ေပးမွာ background worker က Active ျဖစ္မွာ ျဖစ္ပါတယ္။ ျပီးရင္ progressbar ေတြကို
name ေျပာင္းပါမယ္။ ေအာက္ပါအတိုင္းေျပာင္းလိုက္ပါ။

(1) Progress bar (1)-------- > bg_worker_Bar


(2) Progress bar (2)-------- > thread_pgb
(3) Progress bar(3) --------  timer_pgb
(4) ၎ တို႕ အားလံုး ရဲ႕ properties မွာ Dock------ > Top ေပးလိုက္ပါ။ေပးတဲ့ ေနရာမွာ
button (1) ကေန စျပီး အစဥ္လိုက္ပါေပးပါ။
ျပီးရင္ button ေတြရဲ႕ name နဲ႔ text ေတြကိုေျပာင္းပါမယ္။ေအာက္ပါအတိုင္းေျပာင္းေပးပါ။

(1)button 1------- > name-- btn_bgworker

Text----- > Background worker Loading

(1)button 2------- > name-- btn_thread

Text----- > ThreadLoading

(1)button 3------- > name-- timer_btn

Text----- > Timerloading

Timer-------- > interval----- > 100 ထားပါ။

အခုဆိုေအာက္ပါ ပံု(၁) အတိုင္း ရသြားပါလိမ့္မယ္။

အခု code ေတြေရးပါေတာ့မယ္။ ပထမဦးဆံုး လိုအပ္တဲ့ system ေၾကျငာရပါ့မယ္။

using System.Threading; ဆိုျပီး အေပၚဆံုးမွာ ေရးလိုက္ပါ။ System မွ Thread function ကို


ယူသံုးမယ္လို႔ ေျပာလိုက္တာပါဘဲ။ျပီးရင္ btn_bgworker button ကို double click ႏွိပ္ပါ။
ေအာက္ပါ code ကို ေရးပါ။

private void btn_bgworker_Click(object sender, EventArgs e)


{

backgroundWorker1.RunWorkerAsync();
}

ျပီးရင္ Backgroundworker 1 ရဲ႕ Event မွာ DoWork ဆိုတဲ့ ေကာင္ကို double click
ႏွိပ္ျပီးေအာက္ပါ code ေရးပါ။

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)


{
for (int i = 1; i <= 100; i++)
{

System.Threading.Thread.Sleep(100);

backgroundWorker1.ReportProgress(i);

}
}

ဆက္ျပီး Backgroundworker 1 ရဲ႕ Event မွာဘဲ ProgressChanged ကို double click


ႏွိပ္ပါ။ေအာက္ပါ code ေရးပါ။

private void backgroundWorker1_ProgressChanged(object sender,


ProgressChangedEventArgs e)
{

bg_worker_Bar.Value = e.ProgressPercentage;

this.Text = e.ProgressPercentage.ToString();
}

အခုဆို thread with background worker function ေရးလိ႔ျု ပီးပါျပီ။ Run ၾကည့္ပါ။ ျပီးရင္ ဒီ
btn_bgworker button ကို ႏွိပ္ၾကည့္ပါ။ bg_worker_Bar စျပီးအလုပ္လုပ္ေနပါျပီ။ အရင္ဆံုး
toolbar ေပၚမွာ ေပၚေနတဲ့ (51) ဆိုတဲ့ ဂဏန္းေလးကို ၾကည့္လိုက္ပါ။ အဲဒါ လက္ရွိ progress bar
ေရာက္ေနတဲ့ value ကိုျပတာပါ။သူ႕ကို အလုပ္လုပ္ေစတဲ့ code ကေတာ့ “this.Text =
e.ProgressPercentage.ToString();” ဒီcode ဘဲျဖစ္ပါတယ္။ ဟုတ္ျပီ။အဲဒီ progress bar ရဲ႕
process ျပီးတဲ့အထိ(100 ျဖစ္တဲ့အထိ) ဆက္ၾကည့္ေနလိုက္ပါ။ ျပီးရင္ အဲဒီ Button
ကိုဘဲထပ္ႏွိပ္ပါ။ ပံုမွန္အလုပ္လုပ္ေနပါေသးတယ္။ဒီ Button က ႏွိပ္တိုင္း အလုပ္လုပ္ပါတယ္။
ဘာ့ေၾကာင့္လည္းဆိုေတာ့ သူ႕ကို System.Threading.Thread
သံုးျပီးေရးထားလိ႔ပ
ု ါ။ေနာက္တခါထပ္ႏွိပ္ပါ။ ဒီတခါေတာ့ သူ႕ process ျပီးတဲ့အထိ မေစာင့္ ဘဲနဲ႔
လမ္းတ၀က္မွာတင္ ျဖတ္ျပီး Background worker loading ဆုိတ့ဲ button ကို ပံု(၃) မွာ
ျပထားတဲ့အတိုင္း ဆက္ႏွိပ္ပါ။ Error တတ္ပါျပီ။ background worker မွာ ေျပာခ်င္တာ အဲဒီ Error
အေၾကာင္းပါဘဲ။ကြ်န္ေတာ္တို႔ btn_bg_worker မွာ ေရးထားတဲ့ ဒီ
backgroundWorker1.RunWorkerAsync(); ေၾကာင့္ပါဘဲ။ဒီေနရာမွာ RunWorkerAsync ဆိုတဲ့
code ရဲ႕ အဓိပၸါယ္က asynchronous ( not synchronous)- တျပိဳင္တည္း အလုပ္မလုပ္ဘူးဆိုတဲ့
အဓိပၸါယ္ ကိုေျပာတာပါ။ အဲဒါေၾကာင့္ ပထမ တခါႏွိပ္ထားတဲ့ process မဆံုးခင္ ေနာက္တခါ
ထပ္ျပီး process လုပ္ခိုင္းေတာ့ Error တတ္တာပါ။ စမ္းၾကည့္ပါ။ျပိးရင္ ဒီစာကိုျပန္ဖတ္ပါ။ျပီးရင္
ျပန္စမ္းပါ။ ေသးေသးေလးေတာ့ နားလည္ပါလိမ့္မယ္ :D ။
ပံု-၃
အခု second button ကုိသြားမယ္။ btn_thread button ကို ၂ ခ်က္ႏွိပ္ျပီးေအာက္က code
ကိုေရးလိုက္ပါ။

private void btn_thread_Click(object sender, EventArgs e)


{
Thread backgroundThread = new Thread(
new ThreadStart(() =>
{
for (int n = 0; n < 100; n++ )
{
Thread.Sleep(50);
thread_pgb.BeginInvoke(new Action(() =>thread_pgb.Value = n));
}
MessageBox.Show("Thread completed!");
}
));
backgroundThread.Start();
}

ျပိးရင္ ပထမ button တုန္းကလိုဘဲ Run ပါ။ Button ကို တခါထဲနဲ႔ (၃)(၄) ခ်က္
ႏွိပ္ပါ။ၾကိဳက္သေလာက္ႏွိပ္။၀ါသနာပါသေလာက္ႏွိပ္ဗ်ာ။ ပထမ button တုန္းကလို Error
မတတ္ေတာ့ပါဘူး။ပံုမွန္အလုပ္လုပ္ပါတယ္။ process တခုဆံုးရင္ “Thread completed” ဆိုတ့ဲ
message ျပပါလိမ့္မယ္။ ၁၀ခါႏွိပ္ထားရင္ ၁၀ခု ျပပါလိမ့္မယ္။အဲဒီ message box လည္းျပ။ေနာက္က
progressbar လည္း ဆက္ျပီးအလုပ္လုပ္ေနဦးမွာ ျဖစ္ပါတယ္။ ဘာလိ႔လ
ု ဲဆိုေတာ့ သူက
synchronous ျဖစ္ပါတယ္။တျပိဳင္နက္ထဲနဲ႔ process လုပ္ႏိုင္ပါတယ္။ကြ်န္ေတာ္ အစမွာ ဥပမာ ျပခဲ့တ့ဲ
console program လိုပါဘဲ။ဒါေပမယ့္ သူ process လုပ္လို႔ မျပီးခင္ ကြ်န္ေတာ္ တု႔ိ window form
ၾကီးပိတ္လိုက္ရင္ေတာ့ Error တတ္ပါလိမ့္မယ္။ ဘာလို႔လည္းဆိုေတာ့ ေနာက္မွာ background
Thread က ကိုယ္ပိုင္ thread ဖန္တီးျပိး Run ေနရလို႔ျဖစ္ပါတယ္။ ပထမ thread တုန္းက
ကိုယ္တိုင္ဖန္တီးတာမဟုတ္ပါဘူး။ Background worker ကေနတဆင့္ဆြဲသံုးတာပါ။ thread
ခ်င္းတူျပီး ဘာလိ႔ု function ခ်င္း မတူရသလဲဆိုရင္ ပထမ Thread က
System.Windows.Forms.Timer ေအာက္မွာ ရွိတဲ့ thread ျဖစ္ျပီး ဒုတိယ Thread ကေတာ့
System.Threading.Timer ေအာက္မွာ ရွိတဲ့ thread ျဖစ္လ႔ဘ
ို ဲ ျဖစ္ပါတယ္။

အခု ေနာက္ဆံုး timer_btn button ကိုႏွိပ္ျပီး ေအာက္က code ကိုေရးပါ။

private void timer_btn_Click(object sender, EventArgs e)


{
this.timer1.Start();
}

ျပီးရင္ timer 1 ဆိုတဲ့ နာရီပံုေလး ကို ၂ ခ်က္ႏွိပ္ပါ။ေအာက္က code ေရးပါ

private void timer1_Tick(object sender, EventArgs e)


{
this.timer_pgb.Increment(10);
}

Run ျပီး timer_btn button ကိုႏွိပ္ပါ။ပထမတခါႏွိပ္တာဘဲ အလုပ္လုပ္ပါလိမ့္မယ္။ Increment


ေနာက္က ကြင္းထဲက တန္ဖိုးကို အတိုးအေလ့်ာလုပ္ၾကည့္ပါ။ တန္ဖိုးမ်ားေလ process speed
ျမန္ေလ ျဖစ္ပါတယ္။ ေနာက္တခါဆက္ႏွိပ္ရင္ မလုပ္ေတာ့ပါဘူး။ကြ်န္ေတာ္ အစမွာ ေပးခဲ့တဲ့
နာရီသံပတ္ေပးတဲ့ ဥပမာ ကို ျပန္စဥ္းစားၾကည့္ပါ။ အဲဒီသေဘာပါဘဲ။

အခုဆို ပံုစံ (၃) မ်ိဴးလံုးေရးလိ႔ျု ပီးသြားပါျပိ။ Run ျပီးေတာ့ Button ေတြကို ႏွိပ္လိုက္ရင္ ေအာက္ပါ ပုံ
(၄) အတိုင္း ျပပါလိမ့္မယ္။
ပံု-၄
ဒီေနရာမွာဘဲ Thread and Timer အေၾကာင္းျပီးပါျပိ။ကြ်န္ေတာ္ ထင္ပါတယ္ ။စာဖတ္သူအေနနဲ႔
ေလာေလာဆယ္ နားလည္မွာမဟုတ္ေသးပါဘူး။ကြ်န္ေတာ့္ ရွင္းျပမႈ
မလံုေလာက္တာလည္းပါပါတယ္။ေသခ်ာတာကေတာ့ တေခါက္ထဲ ဖတ္လို႔ နားမလည္ပါဘူး။ ၂
ေခါက္၊၃ ေခါက္ဖတ္ပါ။ program run လိုက္၊စာကို ဖတ္လိုက္ လုပ္ၾကည့္ရင္ေတာ့
နားလည္ပါလိမ့္မယ္။ ကိုယ္တိုင္မ်ားမ်ားသံုးၾကည့္ရင္ေတာ့ ပိုျပီး နားလည္လာပါလိမ့္မယ္။
အႏွစ္ခ်ဴပ္အေနနဲ႔ ေျပာခ်င္တာက Thread နဲ႔ timer က မတူပါဘူး။ ကိုယ္သံုးခ်င္တဲ့ Event
ေပၚလိုက္ျပီး ေရြးသံုးပါ။ ကြ်န္ေတာ့္ အျမင္ အရဆိုေတာ့ timer က သံုးရတာပိုလယ
ြ ္ေပမယ့္ time
interval အခ်ိန္တို အျဖစ္အပ်က္ေတြအတြက္ဘဲေကာင္းပါတယ္။ thread ကေတာ့ ပိုျပိး
က်ယ္က်ယ္ျပန္႕ျပန္႔သံုးႏိုင္ပါတယ္။လုပ္ငန္းၾကိး အတြက္ ပိုျပိး အသံုးတည့္ပါတယ္။ကြ်န္ေတာ့္
ေဆြးေႏြးမႈ နဲ႔ ပက္သက္ျပိးမရွင္းလင္းတာ ရွိရင္ ေမးျမန္းႏိုင္သလို၊ မွားယြင္းတာ ရွိရင္လည္း ေထာက္ျပ
ေ၀ဖန္ေပးၾကပါလို႔ ေမတၱာ ရပ္ခံပါတယ္။ timer နဲ႔ Thread ကို ပိုျပိးနားလည္သူမ်ားလည္း ထပ္ျပီး
ျဖည့္စြက္ေဆြးေႏြးေပးၾကဘို႔ ဖိတ္ေခၚပါတယ္။

Key Press Event in TextBox and Decimal to binary conveter


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

ကြ်န္ေတာ္ ယခု Text Box ရဲ႕ key press event ကို သံုးျပီး ကြ်န္ေတာ္ တိ႔ရ
ု ိုက္လိုက္တဲ့ စာလံုးေတြရဲ႕ char code
ေတြကို ေဖၚျပသြားပါ့မယ္။ key board ကေန ကြ်န္ေတာ္ တု႔ိ စာလံုးေတြ ရိုက္လိုက္တဲ့အခါ ကြန္ပ်ဴတာက
အဲဒိစာလံုးေတြကို နားမလည္ပါဘူး။ ကြန္ပ်ဴတာ နားလည္တာက machine code ကိုဘဲ နားလည္တာပါ။
အဲဒါေၾကာင့္ ကြန္ပ်ဴတာ နားလည္တဲ့ code ကိုေျပာင္းေပးရပါတယ္။ ပထမ အဆင့္က ကြ်န္ေတာ္
တိ႔ရ
ု ိုက္လိုက္တဲ့ key ေတြ။ ASCII Table (American Standard Code for Information Interchange) မွာ
key ေတြ အတြက္ တန္ဖိုးေတြ သတ္မွတ္ထားျပီးသားျဖစ္ပါတယ္။ (ASCII Table ပံုကို
https://www.facebook.com/771934899529239/photos/pcb.773176209405108/77317605273845
7/?type=1&theater ဒီလင့္မွာ ကြ်န္ေတာ္ ေဖၚျပခဲ့ျပီးသားျဖစ္ပါတယ္။) အဲဒီစာလံုးေတြက decimal
တန္ဖိုးေတြပါ။ decimal ဆိုတာ ကြ်န္ေတာ္တို႔ ပံုမွန္သံုးေနတဲ့ base 10 အေျခခံထားတဲ့ ဆယ္လီစိတ္
စနစ္ကိုေခၚတာပါ။ ဒုတိယအဆင့္အေနနဲ႔ အဲဒီ Decimal တန္ဖိုးကို binary တန္ဖိုး အျဖစ္ေျပာင္းေပးရပါတယ္။
Binary ဆိုတာ (0,1)ဘဲ ပါတဲ့ base 2 အေျခခံ ၂ လီစိတ္စနစ္ဘဲ ျဖစ္ပါတယ္။အဲဒီအခါက်မွ ကြန္ပ်ဴတာက
နားလည္တယ္လို႔ ဆိုပါတယ္။ဥပမာ တခု ရွင္းျပပါမယ္။ ကြ်န္ေတာ္ တိ႔ု ကီးဘုတ္ကေန ‘A’ လိ႕ု ရိုက္လိုက္ ရင္
ASCII table အရ A တန္ဖိုးက 65 ပါ။ အဲဒီ 65 ကိုမွ binary ေျပာင္းလိုက္ရင္ 100 000 1 ရပါတယ္။
အဲဒီအခါက်မွ ကြန္ပ်ဴတာက နားလည္ပါတယ္။ ဒီ process အတိုင္းသြားပါတယ္။ A--- > 65--- 100 000 1 ပါ။
Computer processing ကိုေျပာရရင္ေတာ့ ျပီးမွာ မဟုတ္ေတာ့ဘူး။ ကြ်န္ေတာ္လည္းအဲေလာက္ထိ မသိပါ ဘူး။
ေယဘုယ်က်က်ဘဲသိတာ။ ေလာေလာဆယ္ ကြ်န္ေတာ္ တို႔ ရိုက္လိုက္တဲ့ စာလံုးေတြရဲ႕ char value ကို
ရွာၾကရေအာင္။

Window form တခု ယူလိုက္ပါ။ အဲဒီေပၚမွာ ေအာက္ပါ tool ေတြ တည္ေဆာက္ပါ။

TextBox (1) ခု

Label box(3) ခု

Button (1) ခု

Label1.text-----> name---->lblCharCode

Text----- > ASCII

Label2.text-------> name---- >lbtext

Text------------ > ဘာမွ မေရးနဲ႔

Label3.text-------->name ---------- >lbl_bin

Text----------Binary Code is

Button 1-----------> Text---->Decimal to Binary

ဒီတခါ form ေဆာက္ရတာ ရိုးရွင္းလို႔ ပံုနဲ႔ မျပေတာ့ပါဘူး။

Code ေတြ မေရးခင္ လိုအပ္တဲ့ variable ေတြကို Global အျဖစ္ ေၾကျငာရပါ့မယ္။ ဘယ္ေနရာမွာ
ေၾကျငာရမယ္မွန္းမသိရင္ ေအာက္ဆံုးမွာ ေဖၚျပထားတဲ့ code အျပည့္အစံု ကိုၾကည့္ပါ။ အဲဒါ global variable
အျဖစ္ေၾကျငာထားတာပါဘဲ

string decimalvalue;

int binary;

int quot;

string rem="";

string bin;

ျပီးရင္ tetxtbox ရဲ႕ event ကို သြားလိုက္ပါ။ အဲဒီကေန Key_press ကို double click ႏွိပ္ျပိး ေအာက္ပါ code
ကိုေရးပါ။
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

lbtext.Text += e.KeyChar.ToString();

lblCharCode.Text = lbtext.Text + " " + "of ASCII CODE" + " is " + ((int)e.KeyChar).ToString();

lbtext.Text = " ";

textBox1.Clear();

Run လိုက္ပါ။ေအာက္ပါ ပံုအတိုင္း ျပပါလိမ့္မယ္။ အခု ကြ်န္ေတာ့္ပံုမွာ A ကိုနွိပ္ထားတာပါ။ ASCII code မွာ A
တန္ဖိုးက ၆၅ ပါ။ အျခား စာလံုးေတြလည္း ရိုက္ျပီး စမ္းၾကည့္ပါ။ အၾကီးနဲ႔ အေသး တန္ဖိုးမတူပါဘူး။ ျပီးရင္
ASCII table နဲ႔ မွန္မမွန္ တိုက္ၾကည့္ပါ တိုက္ၾကည့္ပါ.။

ျပီးရင္ ရလာတဲ့ A ရဲ႕ decimal တန္ဖိုး ကို binary ေျပာင္းမယ္။

Decimal to Binary ဆိုတဲ့ button ကို ႏွိပ္ျပိး ေအာက္ပါ code ကို ေရးပါ။

private void button1_Click(object sender, EventArgs e)

binary = int.Parse(decimalvalue);

while (binary >= 1)

quot = binary / 2;

rem += (binary % 2).ToString();

binary = quot;

bin = "";

for (int i = rem.Length - 1; i >= 0; i--)


{

bin = bin + rem[i];

lbl_bin.Text = "Binary Value of this Char is "+ bin;

rem = "";

} rem = "";

အားလံုးျပီးလို႔ Run လိုက္ရင္ A--- 65---- 100 0001 ဆိုျပီးရပါလိမ့္မယ္။ ပံုမွာ ၾကည့္ပါ။

အခုဆိုရင္ ကြ်န္ေတာ္ တိုရဲ႕ Key press in text box နဲ႔ Binary ေျပာင္းတဲ့ program ျပိးပါျပီ။ ကြ်န္ေတာ္ ဒီ
program မွာ coding ေတြကိုေတာ့ အေသးစိတ္ ရွင္းမျပေတာ့ပါဘူး။ textbox ထဲကို ရိုက္လိုက္တဲ့ key ေတြရဲ႕
char တန္ဖိုးေတြကို e.KeyChar.ToString(); ဒီ code နဲ႔ ဖမ္းတာပါ။ ရလာတဲ့ string ကို int အျဖစ္
lblCharCode.Text = lbtext.Text + " " + "of ASCII CODE" + " is " + ((int)e.KeyChar).ToString(); ဒီ
code နဲ႔ေျပာင္းျပီး lblcharcode lable ထဲကိုထည့္တာပါ။ binary ေျပာင္းတာကေတာ့ သခ်ာၤတြက္တဲ့နည္းနဲ႔
အတူတူပါဘဲ။ ၂ ေအာက္ မငယ္မခ်င္း ၂ နဲ႔ ေျပာင္းျပန္စားျပီး looping ပတ္သြားတာပါဘဲ။ အမွန္ကေတာ့
ကြ်န္ေတာ္ ဒီ အပိုင္းမွာ decimal to binary ေျပာင္းတဲ့ function ေရးဘို႔ အစီအစဥ္
မရွိပါဘူး။တကယ္ေျပာခ်င္တာ key press function ကိုပါ။looping အေၾကာင္းနားမလည္ရင္ေတာ့
ေနာက္လာမဲ့သင္ခန္းစာမွာသီးသန္႕ရွင္းေပးသြားပါ့မယ္။ အခု နားမလည္လည္း စိတ္ဓါတ္မက်ပါနဲ႔။ စာဖတ္သူ
computer process ကို အၾကမ္းဖ်ဥ္းသိေစခ်င္လို႔ ၾကံဳလို႔တခါထဲ ထည့္ေျပာလိုက္တာပါ။ ကြ်န္ေတာ္ တို႔ ရို္က္တဲ့
A ဆိုတဲ့ High level ကေန 100 0001 ဆိုျပီး computer ရဲ႕ machine code—Low level အျဖစ္
အခုလိုေျပာင္းသြားပါျပီ။ computer မွာေတာ့ သူ႕ သက္ဆိုင္ရာ compiler ေတြက ေန ေအာ္တိုေျပာင္းေအာင္
အလားတူ code ေတြ ေရးထားပါတယ္။ အခုကြ်န္ေတာ္ေျပာတာ အေပၚယံ ေလးေျပာသြားတာပါ။
ေနာက္သင္ခန္းစာမွာ Type writing game ေသးေသးေရး လို႔ အခု key press ကို ၾကိဳျပီး
ေဆြးေႏြးထားတာျဖစ္ပါတယ္။ အဲဒီ Game မွာ ကြ်န္ေတာ္ တို႔ေဆြးေႏြးခဲ့ျပီးတဲ့ timer,progress bar နဲ႔ ယခု key
press တို႔ကို သံုးသြားမွာ ျဖစ္ပါတယ္။ ေနာက္အပိုင္းက်မွ ျပန္ေတြ႕ၾကတာေပါ့ဗ်ာ

ေအာက္မွာ coding အျပည့္အစံု ေပးလိုက္ပါတယ္။

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

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 InternationalText

public partial class Form1 : Form

public Form1()

InitializeComponent();

}
string decimalvalue;

int binary;

int quot;

string rem="";

string bin;

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

lbtext.Text += e.KeyChar.ToString();

lblCharCode.Text = lbtext.Text + " " + "of ASCII CODE" + " is " + ((int)e.KeyChar).ToString();

decimalvalue = ((int)e.KeyChar).ToString();

lbtext.Text = " ";

textBox1.Clear();

private void button1_Click(object sender, EventArgs e)

binary = int.Parse(decimalvalue);

while (binary >= 1)

quot = binary / 2;

rem += (binary % 2).ToString();


binary = quot;

bin = "";

for (int i = rem.Length - 1; i >= 0; i--)

bin = bin + rem[i];

lbl_bin.Text = "Binary Value of this Char is "+ bin;

rem = "";

}
Typing master Game တခု ဖန္တီးျခင္း

နိဒါန္း

ကြ်န္ေတာ္ ဒီေန႔ Typing game ေလး တခုကို C# နဲ႔ ဖန္တီးပံုေလး ေဆြးေႏြးခ်င္ပါတယ္။ Game
ဆိုလ႕ို အထင္ေတြ BIG မသြားနဲ႔ဦးေနာ္။ ဘာမွမဟုတ္ဘူး။ တကယ့္ ေသးေသးေလး။ အရင္ ဆံုး အဲဒိ
Game ေလး ရဲ႔ အလုပ္လုပ္ပံု ကေန စေျပာမယ္ဗ်ာ။ ကဲ စၾကရေအာင္။ Game နာမည္ က Typing
Masetr Game ဆိုေတာ့ စာရိုက္တဲ့ ဂိမ္းဘဲေပါ့။ဒါေပမယ့္ ကြ်န္ေတာ္တို႔ သိထားတဲ့ Typing tutor လို
ကိုယ္ ရိုက္ခ်င္တဲ့ စာ ၾကည့္ရို္က္ ရတာမ်ိဴးမဟုတ္ဘူး။ A-Z အဂၤလိပ္ အကၡရာ ေတြကို Box တခုထဲမွာ
Random ေပၚလာမယ္။ အဲဒီ ေပၚလာတဲ့ စာလံုးေတြကို ကြ်န္ေတာ္ တိ႔က
ု key board ကေန ရိုက္ရမွာ။
ေပၚလာတဲ့ စာလံုးနဲ႔ ကြ်န္ေတာ္ တိ႔ရ
ု ိုက္လိုက္တဲ့ စာလံုးတူရင္ စာလံုးပ်က္သြားမယ္။ မတူရင္
ေနာက္တလံုး ေပၚလာမယ္။ စာလံုးက တလံုးခ်င္စီ (၈) ၾကိမ္ေပၚလာမယ္။(၈)လံုးစလံုး
အျပည့္ေပၚသြားရင္ GAME OVER ျဖစ္ျပီးကြ်န္ေတာ္ တိ႕ု ရူံးျပီ။ကြ်န္ေတာ္ တု႔ရ
ိ ိုက္လိုက္တဲ့ စာလံုး ရဲ႕
မွန္ကနု္မႈ က ကြ်န္ေတာ္ တိ႕ု ရဲ႕ score ျဖစ္တယ္။ အဲဒိ Score ကိုေတာ့ အေပၚက box မွာ ျပေပးမွာ

ျဖစ္တယ္။ဒီ Game က လ်င္ျမန္မႈ နဲ႔ တိက်မႈ ကို စမ္းသပ္တဲ့ Game ျဖစ္ပါတယ္။ ကြ်န္ေတာ္ တို႔ Game
မွာ Beginner, Intermediate, Advance ဆိုျပီး level (3) ခု ေဆာ့ႏိုင္ပါတယ္။level ျမင့္လာေလ။
စာလံုးေတြ ေပၚလာတာ ျမန္ေလ။ ျမန္ျမန္ (၈) လံုးျပည့္ေလ။ အဲဒိ စာလံုးရဲ႕ speed အတြက္ေတာ့
progress bar နဲ႔ Timer က ထိန္းခ်ဴပ္ထားျပီး။ Typing အတြက္ေတာ့ key Dow event မွာ
ေရးထားတာျဖစ္ပါတယ္။ Score ကိုေတာ့ ၊စုစုေပါင္းကိုတည္၊ အေရအတြက္ န႔ဲ စား ဆိုတဲ့ Average
တြက္တ့ဲ ပံုေသနည္းကို သံုးထားပါတယ္။ကြ်န္ေတာ္တို႔ ေရွ႕သင္ခန္းစာေတြမွာ ေဆြးေႏြးခဲ့တဲ့ timer,
progress bar, Reference variable , key press event စတာေတြကို သံုးျပီး
Gameတခုဖန္တီးထားတာပါ။

Game အတြက္ လိုအပ္ေသာ ျပင္ဆင္မႈမ်ားျပဳလုပ္ျခင္း

အခု ကြ်န္ေတာ္ တိ႕ု Form1 ကို ယူလိုက္။ Form---- >properties---> Form Bolder Style-----
>Fixed DialogBox( Form ကို ခ်ဴံလို ခ်ဲ႕လိ႔ု မရေအာင္)။ ျပီးရင္ Maximize box--- >False ေပး ။
ေနာက္ထပ္ toolbox က Menustrip ဆိုတာေလးကို ဆြဲယူလိုက္။ ျပီးရင္ အဲဒီ Menu Strip
အကြက္ေလးထဲမွာ စာေလးေတြ ေရးမယ္။ပထမ ဆံုး Type Here ဆိုတဲ့ အကြက္မွာ New Game
လိ႔ေ
ု ရးျပီး Enter ေခါက္ခ်လိုက္။အဲဒါဆို ေအာက္မွာ ေနာက္ထပ္ အကြက္ေလးတကြက္ေပၚလာမယ္။
Beginner ေရး Enter ေခါက္။ ျပီးရင္ Intermediate နဲ႔ Advance ကိုလည္း အဲဒီနည္းနဲ႔ Enter
ေခါက္ျပီး ေရး။ အဲဒါျပီးရင္ New Game ရဲ႕ ေဘးနားက အကြက္မွာ Exit ။ အဲဒီ Exit ေဘးမွာ Level
လိ႔ေ
ု ရး။ ကြ်န္ေတာ္ ပံု (၁) မွာ ျပထားတဲ့အတိုင္း ရလာပါလိမ့္မယ္။ျပီးရင္ Level ရဲ႕ properties
window မွာ name-----> level ,

font----zawgyi one--- size (12) –color ---အျပာ--ထားလိုက္။

ျပီးရင္ Toolbox က StatusStrip bar ယူလိုက္။ အဲဒီ Bar က Form ရဲ႕ ေအာက္ေျခမွာ
ကပ္ေနလိမ့္မယ္။ properties ကိုသြား။ Dock မွာ Top ေပးလိုက္။အေပၚ နား သြားကပ္လိမ့္မယ္။ အဲဒိ
Bar ရဲ႕ ဘယ္ဘက္ေထာင့္က ၾတိဂံပံု ေအာက္စိုက္ထားတာေလးကို ႏွိပ္ျပီး Statuslabel ကို ေရြးလိုက္။
အဲလို status label (၄)ခု ရေအာင္ေရြးလိုက္။ျပီးရင္ ၾတိဂံပံုေလးကို ေနာက္ဆံုးတခါ
ထပ္ေထာက္လိုက္ဥိးဒီတခါက် Progress bar ကိုေရြး။ အဲဒါဆို status label (၄) နဲ႔ progress bar
(၁) ခုရလာလိမ့္မယ္။ ေအာက္ကပံု (၂) မွာ ၾကည့္ပါ။
ပံု-၂

ပုံ(၂)မွာ correct, Miss? Total Accuracy အစရွိသျဖင့္ ေတြ႕ရလိမ့္မယ္။အဲဒီလိုျဖစ္ေအာင္ properties


မွာ ေအာက္ပါ အတိုင္းသြားျပင္မယ္။

toolstrip status label1------ > properties------ > Text--- -> Correct?

toolstrip status label1------ > properties------ > Name--- -> lblcorrect

toolstrip status label2------- > properties------ > Text----- > Miss?

toolstrip status label2------ > properties------ > Text--- -> lblmiss

toolstrip status label3------- > properties------ > Text----- > Total?

toolstrip status label3------- > properties------ > Text--- -> lbltotal

ProgressBar ---- > properties ----- > size ----- > 350,17

Progressbar ----- > name-- --- > progressbar

Progressbar ----- > name-- --- >maximum----- > 1000


ဒီတခါ ListBox တခု ကို ယူလိုက္ပါ။ ျပီးရင္ သူ႕ရဲ႕

properties---- > Dock -- Bottom

properties---- > Back Color --- > အစိမ္းေရာင္ ေျပာင္း

properties---- > Font -- size (72) ထား

properties---------- > multicolumn ----- > True(false ေပးလုိက္ရင္ စာလံုးေတြက အလ်ားလိုက္


မသြားဘဲ ေဒါင္လိုက္သြားေနပါလိမ့္မယ္။)

ေအာက္ပါ ပံု (၃) အတိုင္း ျမင္ရပါ့မယ္။

ျပ

ပံု-၃

- ျပီးရင္ tool box ကေန timer ကိုယူလိုက္ပါ။


- Timer---- > properties ---- > Enable--- > True(အေရးၾကီးပါတယ္။ false
ေပးထားရင္ အလုပ္မလုပ္ပါ။)
- Timer---- > properties ---- > Interval--- >1000

Code ေရးသားျခင္း
အခုျပင္ဆင္မႈ ပိုင္း ျပီးတဲ့အခါမွာ code ေတြစေရးၾကမယ္။ ဒီေနရာမွာ ကြ်န္ေတာ္ တိ႔ု class
အသစ္ေခၚေရးမယ္။ညာဘက္ solution Explorer Box က window Form application ေပၚကို Right
Click---- > Add---- > class (ပံုမွာ အနီနဲ႔ ၀ိုင္းျပထားတယ္။) ဆိုျပီး class တခု
ေခၚလိုက္ပါ။ေအာက္ပါပံု(၄) မွာ ၾကည့္ပါ။ Window တခုေပၚလာလိမ့္မယ္။ အဲဒီ window အေပၚယံုးက
class ဆိုတာကိုေရြး- ေအာက္က file name မွာ Stats.cs ဆိုျပီး နာမည္ေပးလိုက္ပါ။(နာမည္
ေပးခ်င္တာေပးလို႔ရေပမယ့္ ကြ်န္ေတာ္ တုိ႔ program မွာ ဒီေနရာမွာေပးခဲ့တဲ့ နာမည္ကိုဘဲ ျပန္သံုးမွာ
ျဖစ္တဲ့အတြက္ မွတ္ထားဘိ႔လ
ု ိုပါတယ္။ အခု ကြ်န္ေတာ့္ program မွာ Stats ဆိုတဲ့နာမည္ကို သုံးသြားမွာ
ျဖစ္ပါတယ္။)

ပံု-၄
Stats.cs ဆိုျပီးညာဘက္ solution explorer box မွာ class file ေလးတခု ေပၚလာပါလိမ့္မယ္။
အဲဒီေပၚကို ၂ ခ်က္ႏွိပ္ျပီး ေအာက္ပါ code အတိုင္းေရးလို္က္ပါ။

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication2
{
class Stats
{
public int Total = 0;
public int Missed = 0;
public int Correct = 0;
public int Accuracy = 0;
public void Update(bool correrctKey)
{
Total++;
if (!correrctKey)
{
Missed++;
}
else
{
Correct++;
}
Accuracy = 100 * Correct / (Missed + Correct);
}
}
}

အဲဒါျပီးရင္ timer ပံုေလးကို double click ေပးျပီး ေအာက္ပါ code ေရးပါ။

listBox1.Items.Add((Keys)rd.Next(65, 90));// စာလုံးေတြကို listbox မွာ Random ေပၚေစ


if (listBox1.Items.Count > 8)
{
listBox1.Items.Clear();
listBox1.Items.Add("GAME OVER");
timer1.Stop();
}

Form1---- > Event ----- >Key Down ကို double click ႏွိပ္ျပိး ေအာက္ပါ code ေရးပါ

Random rd = new Random();


Stats stats = new Stats();
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
// User က Keyboard မွ ရိုက္လိုက္တ့ဲ စာလံုးနဲ႔ ListBOX မွာ Random ျပတဲ့ စာလံုးတူရင္ အဲဒီစာလံုးကို ဖ်တ္
// game speed ကိုျမွင့္
// Stats.Update ဆိုတာ ကြ်န္ေတာ္ တို႔ေရးခဲတ
့ ဲ့ Class name ျဖစ္ပါတယ္။အေပၚက interval အဆင့္ ေတြ ျပီးတာနဲပ
stats ကို ေရာက္ရင္ ဖန္တီးထားတဲ့ Stats Class ဆီကုိ ခုန္ျပိး သူ႕ထဲက code ေတြကိုအလုပ္လုပ္တာပါ။

if (listBox1.Items.Contains(e.KeyCode))
{
listBox1.Items.Remove(e.KeyCode);
listBox1.Refresh();
if (timer1.Interval > 1000)
timer1.Interval -=50;
if (timer1.Interval > 800)
timer1.Interval -= 30;
if (timer1.Interval > 500)
timer1.Interval -= -20;
if (timer1.Interval > 300)
timer1.Interval -= 20;
progressbar.Value = 1500 - timer1.Interval;
stats.Update(true);
}
else
{
stats.Update(false);
}
lblcorrect.Text = "Correct :" + stats.Correct;
lblmiss.Text = "Missed:" + stats.Missed;
lbltotal.Text = "Total:" + stats.Total;
lblaccuracy.Text = "Accuracy:" + stats.Accuracy + "%";
}
ျပီးရင္ Listbox1----- > Event----- > KeyDown --- Form1_KeyDown ဆိုတာကိုေရြးပါ။ ဒါ
ေလးက အရမ္းကို မိုက္ပါတယ္။ အခုလို လုပ္လို္က္တာဟာ ဘာေျပာတာလဲ ဆိုရင္ Form1_KeyDown
မွာ လုပ္မ့အ
ဲ လုပ္ေတြအာားလံုးကို listbox key down ကေန copy ကူးလိုက္တာပါ။ listbox key down
အတြက္ code ေရးစရာ မလိုေတာ့ပါဘူး။အရမ္း သက္သာပါတယ္။ အခုဆိုရင္ေတာ့ ကြ်န္ေတာ္ တို႔
program က အလုပ္စလုပ္ေနပါျပီ။

အခု ဆက္လက္ျပီး level ေတြ ထည့္မယ္။ ကြ်န္ေတာ္ တို႔ ဂိမ္းမွာ beginner, intermediate level,
advance level ဆိုျပီး သံုးမ်ိဴးထည့္မယ္။

New Game ေအာက္က Beginner ဆုိတဲ့ menu strip ကို၂ ခ်က္ႏွိပ္ ေအာက္က code ေရး။

private void beginnerToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 800;
timer1.Enabled = true;
level.Text = "beginner";
}

ျပီးရင္ intermediate ကို ၂ခ်က္ႏွိပ္။ ေအာက္က code ေရး

private void intermediateToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 600;
timer1.Enabled = true;
level.Text = "Intermediate";
}
ျပီးရင္ Advance ကို ၂ခ်က္ႏွိပ္။ ေအာက္က code ေရး။

private void advanceToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 400;
timer1.Enabled = true;
level.Text = "Advanced"; // user ေရးလိုက္တ့ဲ game level ကို ျပတာ။

အခု ေနာက္ဆံုး Exit ကို ႏွိပ္ ။ ေအာက္က code ေရး။

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

ကြ်န္ေတာ္ တို႔ program ကို Run လိက


ု ရ
္ င္ ပံု (၅) အတိုင္း ရလာပါမယ္။

ပ့ု-၅
Program Code အျပည့္အစံုက ေအာက္ပါ အတိုင္းျဖစ္ပါတယ္။ Class အသစ္ယူထားတဲ့ code
ကိုေတာ့ အေပၚမွာ အျပည့္အစံုေဖၚျပျပီး ျဖစ္လ႔ို ျပန္မေဖၚျပေတာ့ပါဘူး။ ဒီ Game နဲ႔ ပက္သက္ျပီး
နားမလည္တာ ရွိရင္ ျပန္လည္ ေမးျမန္းႏိုင္ပါတယ္။

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 Typing_Game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}
Random rd = new Random();
Stats stats = new Stats();
private void timer1_Tick(object sender, EventArgs e)
{
listBox1.Items.Add((Keys)rd.Next(65, 90));// စာလုံးေတြကို listbox မွာ Random ေပၚေစ
if (listBox1.Items.Count > 8)
{
listBox1.Items.Clear();
listBox1.Items.Add("GAME OVER");
timer1.Stop();
}

private void Form1_Load(object sender, EventArgs e)


{

private void Form1_KeyDown(object sender, KeyEventArgs e)


{
// User က Keyboard မွ ရိုက္လိုက္တ့ဲ စာလံုးနဲ႔ ListBOX မွာ Random ျပတဲ့ စာလံုးတူရင္ အဲဒီစာလံုးကို ဖ်တ္
// game speed ကိုျမွင့္
if (listBox1.Items.Contains(e.KeyCode))
{
listBox1.Items.Remove(e.KeyCode);
listBox1.Refresh();
if (timer1.Interval > 1000)
timer1.Interval -=50;
if (timer1.Interval > 800)
timer1.Interval -= 30;
if (timer1.Interval > 500)
timer1.Interval -= -20;
if (timer1.Interval > 300)
timer1.Interval -= 20;
progressbar.Value = 1500 - timer1.Interval;
stats.Update(true);
}
else
{
stats.Update(false);
}
lblcorrect.Text = "Correct :" + stats.Correct;
lblmiss.Text = "Missed:" + stats.Missed;
lbltotal.Text = "Total:" + stats.Total;
lblaccuracy.Text = "Accuracy:" + stats.Accuracy + "%";
}

private void beginnerToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 800;
timer1.Enabled = true;
level.Text = "beginner";
}

private void intermediateToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 600;
timer1.Enabled = true;
level.Text = "Intermediate";
}

private void advancedToolStripMenuItem_Click(object sender, EventArgs e)


{
stats.Correct = 0;
stats.Missed = 0;
stats.Total = 0;
stats.Accuracy = 0;
listBox1.Items.Clear();
progressbar.Value = 0;
timer1.Interval = 400;
timer1.Enabled = true;
level.Text = "Advanced";
}
}
}
နိဂံုး---

ကြ်န္ေတာ္ နိဒါန္းမွာ ေဆြးေႏြးခဲ့တ့ဲ Game ရဲ႕ အလုပ္လုပ္ ပံုအေၾကာင္း ကို ေသခ်ာနားလည္ေအာင္


ဖတ္ေစခ်င္ပါတယ္။ ဘာ့ေၾကာင့္လည္း ဆိုေတာ့ project တခု ဖန္တီးေတာ့မယ္ ဆိုရင္ goal ကို
အရင္ခ်ရပါတယ္။ ကိုယ့္ program ကို ဘယ္လို အလုပ္လုပ္ေစခ်င္တာလဲ ဆိုတာ အရင္
စဥ္းစားရပါ့မယ္။ ရျပီဆိုရင္ ကိုယ္ လုပ္ေစခ်င္တဲ့ အလုပ္ေတြ လုပ္ဘို႔ အတြက္ ဘာ tool ေတြ သံုးရမလဲ
ဆိုတာ ဆက္ စဥ္းစားရပါ့မယ္။ အဲဒိ tool ေတြထဲက ဘယ္ tool ကိုေတာ့ကိုယ္က ကြ်မ္းကြ်မ္းက်င္က်င္
သံုးႏိုင္တယ္။ မသံုးႏို္င္ဘူးဆိုတာ သိလာပါမယ္။ ကို မသိေသးတဲ့ tool ေတြ နဲ႔ ပက္သက္ျပီး
ေလ့လာလိုက္မယ္ ဆို project တခု ဖန္တီးႏိုင္ပါျပီ။ အခု ဒီ program မွာဆို timer,progressbar, key
event, တိ႕ု ကို အဓိက သံုးသြားတာပါ။ အဲဒီ အေၾကာင္းေတြကို ေရွ႕သင္ခန္းစာေတြမွာ
ေဆြးေႏြးခဲ့ျပီးျဖစ္လို႔ စာဖတ္သူ အေနနဲ႔ ဒီ Game ကို အနည္းငယ္ေတာ့ နားလည္လိမ့္မယ္
ထင္ပါတယ္။ကြ်န္ေတာ္ ေျပာခဲ့သလို ဒီ Game ရဲ႕ အသက္က speed ပါ။ level (၃)
ကိုခြဲသြားတာကလည္း speed နဲ႔ ဘဲ ခြဲသြားတာပါ။ ေရးထားတဲ့ code က အတူတူပါဘဲ။

timer1.Interval = 800; အဲဒီေနရာက တန္ဖိုးေလး ေျပာင္းျပီး level ခြဲလိုက္တာပါ။ Class ခြဲ


ျပီးေရးထားတာကေတာ့ Reference variable ပါဘဲ။ Stats.Update(true or false ) ဆိုတ့ဲ ေနရာ
ေရာက္ရင္ သူညႊန္းထားတ့ဲ လိပ္စာ ေနရာ ျဖစ္တဲ့ Stats.Class ဆိုတဲ့ file ထဲသြားျပီး
အလုပ္လုပ္ပါတယ္။ Game ရဲ႔႕ score ကို အဲဒီ class ထဲမွာ ေရးထားတာပါ။ ဒီ Game က
အင္တာနက္ေပၚက ေတြ႕တဲ့ project တခုကို အနည္းငယ္ျပင္ျပီး နားလည္ေအာင္
ျပန္ေရးထားတာျဖစ္ပါတယ္။ မရွင္းလင္းတာ ရွိခဲ့ရင္ ကြ်န္ေတာ္ တုိ႕ page မွာ ေမးျမန္းႏိုင္ပါတယ္။

Number System Converter

ကြ်န္ေတာ္ ေရွ႕သင္ခန္းစာမွာ key press နဲ႕ ASCII CODE ဖမ္းတာကို ေဆြးေႏြးခဲ့ပါတယ္။ အဲဒီမွာ ေတာ့ char
--- > decimal --- > binary ကိုေျပာင္းတာပါ ထည့္သြင္းေဆြးေႏြးခဲ့ပါတယ္။ အဲလို ေျပာင္းတဲ့ေနရာမွာ သခ်ာၤ
တြက္နည္းအတိုင္း decimal ဂဏန္းကို အၾကြင္း 0 or 1 ရတဲ့အထိ တြက္ ၂ နဲ႔စားျပီး တြက္ထုတ္ခဲ့ပါတယ္။
အဲဒီ သခ်ာၤ formula ယူျပီး program code အျဖစ္ ေျပာင္းတဲ့အခါမွာ code ေတြက ရွည္သြားပါတယ္။ အခု ဒိ
သင္ခန္းစာမွာေတာ့ သက္ေတာင့္ သက္သာဘဲ C# program key word ေတြကို
သံုးျပီးေျပာင္းသြားပါ့မယ္။ကြ်န္ေတာ္ တိ႔ု သခ်ာၤ နဲ႔ လူ႕ပတ္၀န္းက်င္မွာ အသံုးမ်ားတာဟာ base -10 system
ျဖစ္တဲ့ decimal ပါ။ ကြန္ပ်ဴတာမွာေတာ့ base-1 system binary(0,1), base 16 system hexa(0 to 15 )
နဲ႔ base 8 system octal(0 to 7 ) ကိုဘဲ သံုံးပါတယ္။ အခု decimal ကေန အဲဒီ system ေတြကို ေျပာင္းတာနဲ႔
အဲဒီ System ေတြကေန Decimal ကို ေျပာင္းတဲ့ Number System Converter ေလး တခု ဖန္တီးပါ့မယ္။
Software တခုထုတ္တဲ့အခါမွာ user ေတြဘက္ကေန စမ္းစဥ္းရပါတယ္တဲ့။ ကိုယ္ ေရးလိုက္တဲ့ software က
user ကို သက္ေတာင့္ သက္သာနဲ႕ အလြယ္တကူ အသံုးျပဳလို႔ရေစရန္ အတြက္ပါ ရည္ရြယ္ျပီး
ဖန္တီးေပးရပါတယ္လို႔ Developer ေတြက ဆိုပါတယ္။ ကြ်န္ေတာ္ တိ႔ု Beginner ေတြကေတာ့
အေျဖထြက္သြားျပီးေရာေပါ့ဗ်ာ။ user ဘက္က မစဥ္းစားႏိုင္ေသးဘူး။ ကိုယ့္ဟာကိုယ္ေတာင္လိုခ်င္တဲ့ အေျဖ
ထြက္ေအာင္ အံၾကိတ္ေရးေနရတာ  ။ စကားေတြက မ်ားမိျပီ :P ။ ထားလိုက္ေတာ့။ အခု ဒီ Program မွာ
အဓိက function က Number System ဆိုေပမယ့္ User တိတိက်က် နဲ႔ မွန္မွန္ အသံုးျပဳလို႔ရရန္ အတြက္
Key_press function ေလးေတြ ထည့္ေရးထားတယ္။ ကြ်န္ေတာ္ တိ႔ု က Number System Converter
ဆိုေတာ့ ဂဏန္းေတြခ်ည္းဘဲ ။ အဲဒီေတာ့ အဂၤလိပ္အကၡရာ ေတြျဖစ္တဲ့ A-Z key ေတြကို ကြ်န္ေတာ္ တုိ႔
program မွာ အလုပ္လုပ္ခြင့္ေပးမထားျခင္းျဖင့္ ကြ်န္ေတာ္ တုိ႔ converter သည္ မွန္မွန္ကန္ကန္နဲ႔ user ကို
အေျဖ ထုတ္ေပးႏိုင္မွာ ျဖစ္တယ္။ ဒီေနရာမွာ တခ်က္ ေျပာစရာရွိတာက Hexadecimal မွာ
ဂဏန္းေတြတင္မကဘဲ (A,B,C,D,E,F) ဆုိတဲ့ အဂၤလိပ္ အကၡရာ ၆ လံုး ပါပါလာတယ္။ အဲဒါ
ဘယ္လိုျဖစ္ရတာလဲဆိုေတာ့ သူက base 16 system ။ ဂဏန္းေတြ ရွိတာက 0-9 ဘဲရွိတယ္။ ၁၀ ၊၁၁
သြားလုပ္ရင္လည္း Decimal နဲ႔ ေရာသြားႏိုင္တယ္။ အဲဒီေတာ့ အဂၤလိပ္ အကၡရာ ရဲ႕ အစဂဏန္းေတြျဖစ္တဲ့ (A-
10,B-12,C-13,D-14,E-15,F-16) ဆိုျပီး ယူသုံးခဲ့ၾကတယ္။ ဒါေပမယ့္ ကြ်န္ေတာ့္ရဲ႕ ဒီ program မွာ A-Z key
function ေတြ ပိတ္ထားတဲ့အတြက္ အဲဒီ အကၡရာ ေတြကို ကီးဘုတ္ ကေန
အသံုးျပဳႏိုင္မွာေတာ့မဟုတ္ဘူး။Program မွာ ထည့္ေပးထားတဲ့ button ေတြကေနဘဲ အသံုးျပဳႏိုင္ပါလိမ့္မယ္။

ကဲ စၾကရေအာင္---

Form ၁ ခု ယူျပီး အဲဒီ Form ေပၚမွာ label (1) ခု , TextBox-1 တခု ယူျပီး

Label 1---- > text--- >Char

TextBox1--- > Name--- >char_txt ဆိုျပီးေပးလိုက္ ။ ျပီးရင္ Group Box တခု ယူျပီး အဲဒီ ေပၚမွာ TextBox(4)
ခု၊ Button (၇) ခု ၊ RadioButton (4) ခု ယူျပီး ၎ တိ႔႕ု ရဲ႕ properties မွာ ေအာက္ပါ အတုိင္း ျပင္မယ္။

Radio Button

Radiobutton1---- > name ---- > dec_radio

Text---- > Decimal

Radiobutton2---- > name ---- > bi_radio

Text---- >Binary
Radiobutton3---- > name ---- > oct_radio

Text---- > Octal

Radiobutton1---- > name ---- > dec_radio

Text---- > Decimal

TextBox

TextBox1----- > Name---- >dec_txt

TextBox2----- > Name---- >bi_txt

TextBox3----- > Name---- >hex_txt

TextBox4----- > Name---- >oct_txt

Button

Button 1-- -- > Name---- > btn_clear;

Text------ >Clear;

Button 2 ------ > Name----- >B_btn

Text------ >B

Button 2 ------ > Name----- >C_btn

Text------ >C

Button 2 ------ > Name----- >D_btn

Text------ >D

Button 2 ------ > Name----- >E_btn

Text------ >E
Button 2 ------ > Name----- >F_btn

Text------ >F

Button (2-7) အားလံုး ရဲ႕ size ကို 38,26 ဘဲ ထားပါမယ္။ ျပီးရင္ Form1 ရဲ႕ BackGround Color နဲ႔ Group
Box ရဲ႕ Background color ကို ေျပာင္းေပးပါ။ Form1--- > Text---- >Number System Conveter လိ႔ုေပးပါ။
ေအာက္ပါ ပံု(၁) မွာ ၾကည့္ပါ။

ပံု-

ျပင္ဆင္မႈ ပိုင္းျပိးပါျပီ coding ပိုင္း စပါ့မယ္။Form 1 ကို double click ႏွိပ္ျပီး ေအာက္ပါ code ကိုေရးပါ။

private void Form1_Load(object sender, EventArgs e)


{
//Form စတတ္ တဲ့အခါမွာ A-F Button ေတြ ကို disable ေပးထားတာပါ
A_btn.Enabled = false;
B_btn.Enabled = false;
C_btn.Enabled = false;
D_btn.Enabled = false;
E_btn.Enabled = false;
F_btn.Enabled = false;
}

char_txt Key_press မွာ ေအာက္ပါ code ေရးပါ။ code ထဲမွာ ကြ်န္ေတာ္ ျမန္မာလို ရွင္းလင္းေပးထားပါတယ္။
ဘယ္ code က ဘာ အတြက္အလုပ္လုပ္တယ္ဆိုတာ

private void char_txt_KeyPress(object sender, KeyPressEventArgs e)


{
char_txt.Text = e.KeyChar.ToString();
//ASCII code ကို decimal အျဖစ္ဖမ္း
dec_txt.Text = ((int)e.KeyChar).ToString();
char_txt.Text = "";
if (dec_txt.Text != "")
{
// dec to binary ေတြေျပာင္းတဲ့ code
bi_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 2);
// dec to hexa ေတြေျပာင္းတဲ့ code
hex_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 16);
// dec to oct ေတြေျပာင္းတဲ့ code
oct_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 8);
}
}

ျပီးရင္ dec_radio ကို double click ႏွိပ္ျပီး ေအာက္ပါ code ကို ေရးပါ။

private void groupBox1_Enter(object sender, EventArgs e)


{
dec_radio.Enabled = true;
bi_radio.Enabled = true;
Hex_radio.Enabled = true;
oct_radio.Enabled = true;
}

dec_radio ကို double click ႏွိပ္ျပီး ေအာက္ပါ code ကို ေရးပါ။

private void bi_radio_CheckedChanged(object sender, EventArgs e)


{
// dec to binary ေျပာင္းတဲ့ code
if (dec_txt.Text != "")
bi_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 2);
}

hex_radio ကို double click ႏွိပ္ျပီး ေအာက္ပါ code ကို ေရးပါ။

private void Hex_radio_CheckedChanged(object sender, EventArgs e)


{
// A to F button ေတြကို Enable ျပန္ေပး
A_btn.Enabled = true;
B_btn.Enabled = true;
C_btn.Enabled = true;
D_btn.Enabled = true;
E_btn.Enabled = true;
F_btn.Enabled = true;
// dec to hexa ေျပာင္းတဲ့ code

if (dec_txt.Text != "")
{
hex_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 16);
}

oct_radio ကို double click ႏွိပ္ျပီး ေအာက္ပါ code ကို ေရးပါ။

private void oct_radio_CheckedChanged(object sender, EventArgs e)


{
// dec to oct ေျပာင္းတဲ့ code

if (dec_txt.Text != "")
oct_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 8);

}
ျပိးရင္ dec_txt key press event မွာ ေအာက္ပါ code ကိုေရးပါ။

private void dec_txt_KeyPress(object sender, KeyPressEventArgs e)


{
// 0 to 9 number key ေတြနဲ႔ backspace ၂ ခုလံုး အလုပ္လုပ္မယ္။ မဟုတ္ရင္ ေအာက္က message ျပ

if ((e.KeyChar > (char)Keys.D9 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type number 0 to 9 ");
}

}
}

ျပိးရင္ bi_txt key press event မွာ ေအာက္ပါ code ကိုေရးပါ။

private void bi_txt_KeyPress(object sender, KeyPressEventArgs e)


{
// 0 or 1 နဲ႔ backspace ၂ ခုလံုး အလုပ္လုပ္မယ္။ မဟုတ္ရင္ ေအာက္က message ျပ

if ((e.KeyChar > (char)Keys.D1 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type binary number 0 or 1 ");
}
}
}

// 0 to 7 နဲ႔ backspace ၂ ခုလံုး အလုပ္လုပ္မယ္။ မဟုတ္ရင္ ေအာက္က message ျပ

private void oct_txt_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar > (char)Keys.D7 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type binary number 0 to 7 ");
}
}
}
}
}

ျပီးရင္ Hex_txt key presss event မွာ dec_txt_KeyPress ဆိုျပီးေရြးေပးပါ။ ဒါက ဘာ ကိုေျပာတာလဲဆိုရင္
Hex_txt key presss အတြက္ ေနာက္ထပ္ မေရးေတာ့ဘဲ dec_txt_KeyPress မွာေရးထားတဲ့ function
အတိုင္း ယူသံုးလိုက္တာပါ။

ျပီးရင္ A_btn ကို ႏွိပ္ျပီး ေအာက္ပါ code ကို ေရးပါ။

private void A_btn_Click(object sender, EventArgs e)


{
Button btnHex = (Button)sender;
hex_txt.Text += btnHex.Text;
}

က်န္တဲ့ B_btn,C,D,E,F,G_btn ေတြ ရဲ႕ Click မွာ A_btn ဆိုတာကို ေရြးေပးပါ။ အဲဒါေတြကလည္း အေပၚက အတိုင္းဘဲ A_btn
ရဲ႕ function ကို copy လုပ္တာပါဘဲ။ သူ႔အတြက္ သိးသန္ထပ္ေရးစရာမလိုေတာ့ဘူး။ Button တခုခ်င္းစိ အတြက္
လို္က္ေရးေနရရင္ ေတာ္ ေတာ္ ရွည္သြားပါလိမ့္မယ္။ ဒါေလးကေတာ့ ဒီ program မွာ ကြ်န္ေတာ္ အၾကိဳက္ဆံုး function တခုပါဘဲ
။ တကယ့္ magic code ပါဘဲ။

ျပီးရင္TextBox ေတြရဲ႕ Key down မွာ ေအာက္ပါ code ကို ေရးေပးပါ။ ဒါကိုေတာ့ အေသးစိတ္ မေရးေတာ့ပါဘူး။
လြယ္လယ
ြ ္ေလးမို႔ပါ။ program code အျပည့္အစံုမွာ ၾကည့္လိုက္ရင္ ရွင္းသြားပါလိမ့္မယ္၊။

private void hex_txt_KeyDown(object sender, KeyEventArgs e)


{
bi_txt.Clear();
dec_txt.Clear();
oct_txt.Clear();
}

Clear_button ကို ႏွိပ္ျပိး ေအာက္ပါ code ေရးပါ။

private void btn_clear_Click(object sender, EventArgs e)


{
bi_txt.Clear();
oct_txt.Clear();
hex_txt.Clear();
dec_txt.Clear();
char_txt.Clear();

ျပီးရင္ program ကို Run လိုက္ပါ။ေအာက္ပါ ပံု (၂) ကိုၾကည့္ပါ။ ပံု (၂) ရဲ႕ အေပၚဆံုးက Char ဆိုတ့ဲ အကြက္မွာ P ဆိုတာကို
ရိုက္လိုက္ရင္ ေအာက္မွာ သူ႕ရဲ႕ ASCII table က decimal တန္ဖးုိ ျပေပးပါတယ္။ေအာက္မွာေတာ့ အဲဒီ decimal ကို သက္ဆိုင္ရာ
Number system ေျပာင္းထားပါတယ္။

ပံု-၂

ဒီတခါ Decimal အကြက္ထဲက 80 ဆိုတာ ကိုဖ်တ္ျပီး ကိုယ္ ထည့္ခ်င္တဲ့ ဂဏန္းရို္က္ထည့္လိုက္ပါ။ ကြ်န္ေတာ္ပံု


(၃)မွာေတာ့ ၅၆၆ ဆိုျပီး ရိုက္လို္က္ပါတယ္။ ၾကိဳက္တဲ့ ဂဏန္း ရိုက္ျပီး သက္ဆိုင္ရာ number system
ေဘးက radio button ေလးေတြကို နွိပ္ေပးလိုက္ရင္ သူ႕တန္ဖိုးေတြကို ေဖၚျပေပးပါလိမ့္မယ္။ ပံု (၃) မွာ
ၾကည့္ပါ။
ပံု-၃

ဒီတခါ က်န္တဲ့ system ေတြကေန Decimal ကို ျပန္ေျပာင္းပါ့မယ္။ ကြ်န္ေတာ္ကေတာ့ Hexa ကေန decimal
ကိုေျပာင္းပါတယ္။ ပံု (၄) မွာ ၾကည့္ပါ။ 57AB ဆိုျပိးေရးထားပါတယ္။ 57 ကေတာ့ keyboard ကေန
ရို္က္တာျဖစ္ျပီး AB ကိုေတာ့ ေဘးက Button ေတြကိုႏွိပ္ျပီး ထည့္လိုက္တာျဖစ္ပါတယ္။ ျပိးရင္ decimal ေဘးက
button ကိုႏွိပ္ပါ။ ပံုမွာ ျပထားတဲ့အတိုင္း အေျဖထြက္ေနပါလိမ့္မယ္။က်န္တဲ့ number system
ေတြကိုေျပာင္းခ်င္ရင္ decimal ကေနတဆင့္ဘဲ ေျပာင္းလို႔ရပါတယ္။ သူတ႔ိုအခ်င္းခ်င္းေျပာင္းလို႔မရပါဘူး။
ဥပမာ - octal ကေန Hexa ကိုေျပာင္းခ်င္ရင္ oct အကြက္မွာ octal တန္ဖိုးေရး။ျပီးရင္ decimal radio button
ကို အရင္ႏွိပ္။ ျပီးမွာ hexa radio button ကို ႏွိပ္ေပးလိုက္ရင္ လိခ
ု ်င္တဲ့ oct to hex ေျပာင္းတဲ့ပံုစံျဖစ္ပါတယ္။

ပံု-၄
အခုဆိုရင္ ကြ်န္ေတာ္တို႔ရဲ႕ Number System Converter program ျပိးပါျပီ။ ကဲ အမွ်ေ၀လိုက္ၾကရေအာင္။
ေနာက္ကလို္က္ဆို ၊ အဲ -- မဟုတ္ပါဘူး ။ တရားပြဲနဲ႔ မွားသြားလို႔ :P ။

အခု ကြ်န္ေတာ္ တိ႕ု program မွာ မွာ အဓိက ေပးခ်င္တဲ့ code (၄ ) ပိုင္း ရွိတယ္။

(၁) Decimal မွ အျခား system ေတြလို႕ေျပာင္းျခင္း

// dec to binary ေတြေျပာင္းတဲ့ code


bi_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 2);
// dec to hexa ေတြေျပာင္းတဲ့ code
hex_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 16);
// dec to oct ေတြေျပာင္းတဲ့ code
oct_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 8);
(၂) အျခားSystem ေတြမွာ decimal သိ႕ု ေျပာင္းျခင္း

//Octal အျဖစ္ေျပာင္း
if (oct_txt.Text !="")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(oct_txt.Text,8)).ToString();
}
// Hexa အျဖစ္ေျပာင္း
else if (hex_txt.Text != "")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(hex_txt.Text, 16)).ToString();
}
//binary အျဖစ္ေျပာင္း
else if (bi_txt.Text != "")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(bi_txt.Text, 2)).ToString();
}

အထက္ပါ Code ၂ ခုကိုႏိူင္းယွဥ္ၾကည့္ရင္ နားလည္မယ္ထင္ပါတယ္။

(၃) Key ေတြကို disable ေပးျခင္း

(၄) function ေတြ copy ကူးျခင္း

private void A_btn_Click(object sender, EventArgs e)


{
Button btnHex = (Button)sender;
hex_txt.Text += btnHex.Text;
}
A Button မွာ ေရးထားတဲ့ function ကို က်န္တ့ဲ Button Click Event မွာ A_btn ေပးျပီး copy ကူးတာ။ code ေတာင္
ေရးစရာမလိုဘူး။ Click Event မွာ သြားျပင္လိုက္ရံုဘ။ဲ

အားလံုးဘဲ ေက်နပ္ၾကမယ္လို႔ထင္ပါတယ္ ။ေအာက္မွာ program code ေပးလိုက္ပါတယ္။

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 number_system_converter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void char_txt_KeyPress(object sender, KeyPressEventArgs e)


{
char_txt.Text = e.KeyChar.ToString();
//ASCII code ကို decimal အျဖစ္ဖမ္း
dec_txt.Text = ((int)e.KeyChar).ToString();
char_txt.Text = "";
if (dec_txt.Text != "")
{
// Char to number system system ေတြေျပာင္းတဲ့ code
bi_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 2);
hex_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 16);
oct_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 8);
}
}

private void btn_clear_Click(object sender, EventArgs e)


{
bi_txt.Clear();
oct_txt.Clear();
hex_txt.Clear();
dec_txt.Clear();
char_txt.Clear();

private void dec_radio_CheckedChanged(object sender, EventArgs e)


{
//Octal အျဖစ္ေျပာင္း
if (oct_txt.Text !="")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(oct_txt.Text,8)).ToString();
}
// Hexa အျဖစ္ေျပာင္း
else if (hex_txt.Text != "")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(hex_txt.Text, 16)).ToString();
}
//binary အျဖစ္ေျပာင္း
else if (bi_txt.Text != "")
{
dec_txt.Text = Convert.ToInt64(Convert.ToInt64(bi_txt.Text, 2)).ToString();
}
}

private void bi_radio_CheckedChanged(object sender, EventArgs e)


{
if (dec_txt.Text != "")
bi_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 2);
}

private void Hex_radio_CheckedChanged(object sender, EventArgs e)


{
A_btn.Enabled = true;
B_btn.Enabled = true;
C_btn.Enabled = true;
D_btn.Enabled = true;
E_btn.Enabled = true;
F_btn.Enabled = true;

if (dec_txt.Text != "")
{
hex_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 16);
}

private void oct_radio_CheckedChanged(object sender, EventArgs e)


{
if (dec_txt.Text != "")
oct_txt.Text = Convert.ToString(Convert.ToInt64(dec_txt.Text), 8);

private void Form1_Load(object sender, EventArgs e)


{
//Form စတတ္ တဲ့အခါမွာ A-F Button ေတြ ကို disable ေပးထားတာပါ
A_btn.Enabled = false;
B_btn.Enabled = false;
C_btn.Enabled = false;
D_btn.Enabled = false;
E_btn.Enabled = false;
F_btn.Enabled = false;
}

private void A_btn_Click(object sender, EventArgs e)


{
Button btnHex = (Button)sender;
hex_txt.Text += btnHex.Text;
}

private void bi_txt_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar > (char)Keys.D1 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type binary number 0 or 1 ");
}
}
}

private void dec_txt_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar > (char)Keys.D9 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type number 0 to 9 ");
}

}
}

private void oct_txt_KeyPress(object sender, KeyPressEventArgs e)


{
if ((e.KeyChar > (char)Keys.D7 || e.KeyChar < (char)Keys.D0) && (e.KeyChar != (char)Keys.Back &&
e.KeyChar != '.'))
{
e.Handled = true;
{
MessageBox.Show(" only type binary number 0 to 7 ");
}
}
}

private void hex_txt_KeyDown(object sender, KeyEventArgs e)


{
bi_txt.Clear();
dec_txt.Clear();
oct_txt.Clear();
}

private void oct_txt_KeyDown(object sender, KeyEventArgs e)


{
bi_txt.Clear();
dec_txt.Clear();
hex_txt.Clear();
}

private void dec_txt_KeyDown(object sender, KeyEventArgs e)


{
bi_txt.Clear();
oct_txt.Clear();
hex_txt.Clear();
}

private void bi_txt_KeyDown(object sender, KeyEventArgs e)


{
dec_txt.Clear();
oct_txt.Clear();
hex_txt.Clear();
}
}
}

Text ေတြကို program code ျဖင့္ ဖတ္ခိုင္းျခင္း


ကြ်န္ေတာ္ ဒီေန႔ C# ရဲ႕ တကယ္ကို လန္းတဲ့ system ေလးတခ်ိဴ႕ နဲ႔ မိတ္ဆက္။ ၎ တို႔ဟာ Text
Editor မွာ ကြ်န္ေတာ္ တိ႔ု ေရးလိုက္တဲ့ text ေတြကို ဖတ္ေပးႏိုင္ပါတယ္။Pause , Resume
လုပ္ေပးႏို္င္သလို Recording ပါ လုပ္ေပးႏိုင္ပါတယ္။ အဲဒီ system ေတြကေတာ့

using System.Speech; // include


using System.Speech.Recognition; // speak to the computer and it do what you say
using System.Speech.Synthesis; // speak to the computer and it talk to you

တို႔ဘဲ ျဖစ္ပါတယ္။ အခု အဲဒီ System ေလးကို သံုးျပီး text ေလးေတြကို ဖတ္ရေအာင္။

Form တခု ယူလိုက္ပါ။ Form ေပၚမွာ ေအာက္ပါ tools မ်ား ယူလို္က္ပါ။


Level (၃) ခု။ TrackBar(2) ခု။ RichTextBox (၁) ခု ၊ Button (၅) ခု၊ Groupbox (၁) ယူျပီး ပံု(၁) မွာ
ျပထားတဲ့အတိုင္း တည္ေဆာက္လိုက္ပါ။ အဲဒိ Tool ေတြေပၚမွာ ေရးရမဲ့ Text ေတြကိုလည္း ပံုမွာ
ျပထားတဲ့အတိုင္း ေရးလိုက္ပါ။ Name ေတြကို ေတာ့ေအာက္ပါအတိုင္းေပးပါ။

Rich TextBox--- > Name-- >msg_txt

Burron(5) ခု---- > name - > read_btn , pause_btn,resume_btn,btn_record, close_btn

TrackBar1----- >Name----- >trackbarvolume

Minimun----> 0

Maximun---->100

Large change----- > 10

small change----- > 5

value----------- > 80

TrackBar2----- >Name----- > trackbarspeed

Minimun----> 0

Maximun---->10

Large change----- >2

small change----- > 1

value----------- > 1
ပံု-၁

အခု code ေတြ မေရးခင္မွာ လိုအပ္တဲ့ assembly reference ေပါင္းေပးရပါ့မယ္။ Solution Explorer
ေပၚက Reference ေပၚကို Right click ေထာက္ပါ။(solution Explorer ေပ်ာက္ေနရင္ Ctrl+w+S or
Tool bar ေပၚက view မွာ သြားေဖၚပါ ) ။ Add reference ကို ေရြးပါ။Reference Manager ဆိုတဲ့
window box ေလးက်လာရင္ ညာဘက္က search box ေလးထဲမွာ system.speech ဆိုတာကို
ရို္က္ပါ။ ေပၚလာရင္ အမွန္ျခစ္ ေပးျပီး OK ေပးပါ။ ယခု Form ေပၚကို R_click ေထာက္ျပီး view code
ေပးပါ။ အေပၚဆုံးက System မွာ ေအာက္ပါ code 2 ခု ေပါင္းေပးပါ။

using System.Speech;
using System.Speech.Synthesis;

အခုဆို လိုအပ္တ့ဲ reference assembly ေပါင္းျပီးပါျပီ။ public form1() ဆိုတ့ဲအေပၚမွာ SpeechSynthesizer ss; ဆိုျပိးေရးပါ။
မ်က္စိထဲမေပၚလွ်င္ ေအာက္မွာ code အျပည့္အစံုေပးထားပါတယ္။ အဲဒိမွာ ၾကည့္ပါ။ ျပီးရင္ Form ကို double click ႏွိပ္ျပီး
ေအာက္ပါ code ေရးပါ။

private void Form1_Load(object sender, EventArgs e)


{
ss = new SpeechSynthesizer();
}
Read Button ကိုႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void read_btn_Click(object sender, EventArgs e)


{
// Text ကို ဖတ္တာ
ss.Rate = trackbarspeed.Value;
ss.Volume = trackbarvolume.Value;
ss.SpeakAsync(msg_txt.Text);
}

Pause Button ကိုႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void pause_btn_Click(object sender, EventArgs e)


{
ss.Pause();
}

Resume Button ကိုႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void btn_conti_Click(object sender, EventArgs e)


{
ss.Resume();
}

Record Button ကိုႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။


private void btn_record_Click(object sender, EventArgs e)
{
//Record
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Rate = trackbarspeed.Value;
ss.Volume = trackbarvolume.Value;
// Record လုပ္ထားတဲ့ audio file ကို wav အမ်ိဴးအစား နဲ႔ save
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Wave Files| *.wav";
sfd.ShowDialog();
ss.SetOutputToWaveFile(sfd.FileName);
ss.Speak(msg_txt.Text);
ss.SetOutputToDefaultAudioDevice();
MessageBox.Show("Recording Completed...", "C# and C++ for Beginner");
}

Close Button ကိုႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void btn_close_Click(object sender, EventArgs e)


{
//Close
Application.Exit();
}

အခုဆို ကြ်န္ေတာ္တို႔ ရဲ႕ Text Reading and recording program ေလးျပီးပါျပီ။ Run ျပီး Text Box
မွာ အဂၤလိပ္စာေတြ ရိုက္လို္က္ပါ။ျပီးရင္ Read Button ကိႏ
ု ွိပ္လိုက္ရင္ program က textbox ထဲက
စာေတြကို ဖတ္ေနမွာျဖစ္ျပီး pause ေပးထားရင္ ရပ္သြားမွာ ျဖစ္ပါတယ္။ Resume ေပးရင္ေတာ့
ေရာက္တ့ေ
ဲ နရာကေန ဆက္ဖတ္မွာ ျဖစ္ျပီး Record ကို ႏွိပ္လိုက္ရင္ေတာ့ save dialog box
ေလးေပၚလာျပီး save ရမဲ့ ေနရာ ေတာင္းျပီး .wav file type နဲ႔ save ေပးပါလိမ့္မယ္။ ပ့ု (၂) မွာ
ၾကည့္ပါ။

ကြ်န္ေတာ္ တု႔ိ program မွာေတာ့ english language တခုဘဲ ဖတ္ႏို္င္ပါတယ္။ အျခား language
ေတြပါ အလုပ္လုပ္ခ်င္ရင္ေတာ့ code အနဲငယ္ ထပ္ေရးဘိ႔ု လိုပါတယ္။ ေနာက္ အခန္းေတြမွာ
ၾကံဳရင္ကြ်န္ေတာ္ ေဆြးေႏြးပါဥိးမယ္။ ဒါေပမယ့္ ကြ်န္ေတာ္ တိ႔ု ျမန္မာဘာသာ ေတာ့ မရေသးပါဘူး။
သက္ဆိုင္ရာ code ေတြမွာ ဘာအတြက္ အလုပ္လုပ္တာကို ေရးေပးထားျပီးျဖစ္တဲ့အတြက္ ကြ်န္ေတာ္
သီးသန္႔မရွင္းေတာ့ပါဘူး။ ရွင္းလိ႔လ
ု ည္း မရပါဘူး။ ဘာလိ႔လ
ု ည္းဆိုေတာ့ C# library မွာ ပါတဲ့
assembly reference နဲ႔ Key word ေတြကို ဘဲ သံုးထားတာျဖစ္လို႔ပါ။ မိမိ program အသံုးျပဳဘို႔
လိုအပ္လာရင္ ဒီအတိုင္း ဆြဲယူျပီးသံုးလိ႔ရ
ု ပါတယ္။ ဒီ program code ေတြကို copy မကူးဘဲ နဲ႔
ကိုယ္တိုင္ ရိုက္ျပီး ေရးဘိ႔ု အၾကံေပးလိုပါတယ္။ copy ကူးတာနဲ႔ ရို္က္တာ မတူပါဘူး။အခုလိုဘဲ
ၾကည့္ျပီး ရို္က္ပါမ်ားရင္ program ရဲ႕ သေဘာတရားေတြ နားလည္လာပါလိမ့္မယ္။ code ေတြကို
အလြတ္ရစရာမလိုပါဘူး။ နားလည္ဘို႔ဘဲ လိုပါတယ္။ နားလည္ေအာင္ ကိုယ္တိုင္မ်ားမ်ား ရိုက္ျပီး
Trace လိုက္မွဘဲ နားလည္မွာပါ။ ေနာက္အခန္းမွာ program တပုဒ္ကို Trace လိုက္နည္းကို
ေဆြးေႏြးသြားပါ့မယ္။ဒီ program ေလးကို အားလံုးဘဲ သေဘာက် ၾကမယ္လို႔ထင္ပါတယ္။

ပံု-၂

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;
using System.Speech;
using System.Speech.Synthesis;
namespace Speech_record_
{
public partial class Form1 : Form
{
SpeechSynthesizer ss;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
ss = new SpeechSynthesizer();
}

private void read_btn_Click(object sender, EventArgs e)


{
// Text ကို ဖတ္တာ
ss.Rate = trackbarspeed.Value;
ss.Volume = trackbarvolume.Value;
ss.SpeakAsync(msg_txt.Text);
}

private void pause_btn_Click(object sender, EventArgs e)


{
ss.Pause();
}

private void resume_btn_Click(object sender, EventArgs e)


{
ss.Resume();
}

private void btn_record_Click(object sender, EventArgs e)


{
//Record
SpeechSynthesizer ss = new SpeechSynthesizer();
ss.Rate = trackbarspeed.Value;
ss.Volume = trackbarvolume.Value;
// Record လုပ္ထားတဲ့ audio file ကို wav အမ်ိဴးအစား နဲ႔ save
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Wave Files| *.wav";
sfd.ShowDialog();
ss.SetOutputToWaveFile(sfd.FileName);
ss.Speak(msg_txt.Text);
ss.SetOutputToDefaultAudioDevice();
MessageBox.Show("Recording Completed...", "C# and C++ for Beginner");
}

private void btn_close_Click(object sender, EventArgs e)


{
//Close
Application.Exit();
}

}
}

Timer အသံုးျပဳ၍ Splash Screen ျပဳလုပ္ျခင္း

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

ကြ်န္ေတာ္ ဒီေန႔ timer ကိုသံုးျပီး splash screen ျပဳလုပ္ပုံကို ေဆြးေႏြးလိုပါတယ္။ screen ကို ျဖည္းျဖည္းခ်င္း
ေပၚတာကို splash screen လိ႔ေ
ု ခၚပါတယ္။ တကယ့္ကို Easy Going ပါဘဲ။ ကဲ ၾကည့္ၾကရေအာင္။

Form တခုကို ယူလိုက္ပါ။ Form ေပၚမွာ picture box တခု ယူျပီး အဲဒီ Box ရဲ႕ အေပၚ ညာဘက္ ထိပ္ေထာင့္
မွာ Dock in Parent Container ကိုေပးပါ။အဲဒီ picture Box ဟာ Form အျပည့္ ျဖစ္သြားပါလိမ့္မယ္။ျပီးရင္
picture Box ထဲကို ပံု ထည့္ဘို႔ ၎ ရဲ႕ properties ကို သြားပါ။ Image ကိုေရြးျပီး Properties Resource file
ကေန Import လုပ္ပါ။ျပီးရင္ ေအာက္နားနဲနဲ ဆင္းလိုက္ရင္ sizeMode ဆိုတာကို ေတြ႔႕ပါလိမ့္မယ္။
StrectchImage ကို ေရြးပါ။ ပံုနဲ႔ Form နဲ႔ ကြက္တိ ျဖစ္သြားပါလိမ့္မယ္။ ျပီးရင္ လိုအပ္တ့ဲ code ေရးပါ့မယ္။
solution Explorer က Form1.cs ကို ေထာက္ျပီး view code ကိုေရြးပါ။ Initialize component ေအာက္မွာ
ေအာက္ပါ ဒီပုံစံ code ေရးပါ။

public Form1()
{
InitializeComponent();
this.Opacity = .01;
this.CenterToScreen();
}

ျပီးရင္ Timer 1 ကို double click ေပးျပိး ေအာက္ပါ code ေရးပါ။

private void timer1_Tick(object sender, EventArgs e)


{
this.Opacity = this.Opacity + .01;
if (this.Opacity == 1)
{
timer1.Enabled = false;
this.Visible = false;
this.Close();
}
}

ဒီေနရာမွာဘဲ ကြ်န္ေတာ္တို႔ရဲ႕ splash screen form ျပီးပါျပီ။ program ကို Run လိုက္ရင္ screen က တျဖည္းျဖည္းခ်င္း slow
motion နဲ႔ မႈန၀
္ ါး၀ါး တတ္လာျပီး အျပည့္အ၀ ေပၚလာတဲ့အခါ ျပန္ေပ်ာက္သြာပါလိမ့္မယ္။ ဒီ program မွာ အဓိက
အလုပ္လုပ္သြားတာက

this.Opacity = this.Opacity + .01; ဒီ code ဘဲ ျဖစ္ပါတယ္။ .01 ဆိုတ့ဲ ေနရာမွာ တန္ဖိုးဘဲ ျဖစ္ပါတယ္။ အဲဒီ တန္ဖးုိ
.01 ကေန 1 ေရာက္တဲ့အထိ ျဖည္းျဖည္းခ်င္း Form ေပၚလာတာျဖစ္ပါတယ္။.01 ေနရာမွာ .1 ထားလိုက္ရင္ ေပၚတာ
ပိုျမန္ပါမယ္။ 1 ထားလိုက္ရင္ေတာ့ ခ်က္ျခင္း ေပၚျပီး တန္းေပ်ာက္သြားပါမယ္။ေအာက္မွာ if (this.Opacity == 1)
ထားခဲ့လို႔ပါ။1 ေရာက္တာနဲ႔ Form က အလိုလိုပိတ္သြားပါလိမ့္မယ္။ အရမ္းလြယ္တဲ့အတြက္ ပုံ နဲ႔ မျပေတာ့ပါဘူး။
အားလံုးဘဲ အဆင္ေျပလြယ္ကူၾကမယ္လို႔ထင္ပါတယ္။ ေအာက္မွာ code အျပည့္အစံုေပးလိုက္ပါတယ္။

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 Splash_Screen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Opacity = .01;
this.CenterToScreen();
}

private void timer1_Tick(object sender, EventArgs e)


{
this.Opacity = this.Opacity + .01;
if (this.Opacity == 1)
{
timer1.Enabled = false;
this.Visible = false;
this.Close();
}
}

}
}

ကိုယ္ ပိုင္ Text Editor ဖန္တီးျခင္း

နိဒါန္း
ကြ်န္ေတာ္ တိ႔ု ဒီေန႔ ကိုယ္ ပိုင္ TextEditor ေလး တခု ဖန္တီးၾကရေအာင္။ Text Editor မွာေတာ့ .txt နဲ႔ .rtf
file အမ်ိဴးအစား ၂ မ်ိဴး အလုပ္လုပ္ႏိုင္ပါတယ္။ .txt ကေတာ့ notepad file ျဖစ္ျပီး rtf ကေတာ့ Wordpad
ျဖစ္ပါတယ္။ ကြ်န္ေတာ္ တိ႔ု Text Editor မွာ notepad ထက္ function စံုျပီး WordPad ထက္ေတာ့ နဲပါတယ္။
notepad နဲ႔ WordPad ၾကားဆိုေတာ့ nordpad လိ႔ု နာမည္ေပးလိုက္ရင္ေကာင္းမလားဘဲ :D ။
Notepad နဲ႔ Wordpad ကို ျမင္ခ်င္ရင္ေတာ့ window +R ---- > notepad or wordpad တခုခု ရိုက္လိုက္ရင္
ေတြ႕ရပါလိမ့္မယ္။ အိုေက-- အခု ဒီ သင္ခန္းစာမွာ အဓိက text editor ဆုိေပမယ့္ သူနဲ႔ဆက္စပ္ျပီး C# ရဲ႕
power full ျဖစ္တဲ့ key word အခ်ိဴ႕ ကိုပါ ေတြ႕ရမွာ ျဖစ္ပါတယ္။ Public Access Type ကို အသံုးျပဳျပိး Form
တခုကေန အျခား Form ေတြကိုလွမ္းေခၚသံုးတာကိုလည္း ဒီ program မွာစတင္
မိတ္ဆက္ေပးထားပါတယ္။ေနာက္ပုိင္း project ေတြ ေရးတဲ့အခါ Form တခုထဲနဲ႔က ေရးဘို႔ မျဖစ္ႏိုင္ပါဘူး။
Form ေတြ အမ်ားၾကီး သံုးရပါေတာ့မယ္။ အဲဒါေၾကာင့္ အခုက စျပိး မိတ္ဆက္ေပးလိုက္တာပါ။ ေနာက္တခုက
ကြ်န္ေတာ္ ေရွ႕သင္ခန္းစာမွာ ေဆြးေႏြးခဲ့တဲ့ Splash Screen ကို ဒီ program မွာ ထည့္သြင္း
အသံုးျပဳထားပါတယ္။

Text Editor Form ျပင္ဆင္ျခင္း

Window Form Application တခုယူျပီးေအာက္ပါ Tool မ်ားကိုထည့္သြင္းအသုံးျပဳသြားမွာ


ျဖစ္ပါတယ္။

Menustrip (1) ခု

Toolstrip (1) ခု

Color DialogBox (1) ခု

RichTextBox (1) ခု

ပထမ ဆံုး MenuStrip ယူျပီး

ေအာက္ပါ text မ်ား ေရးေပးပါ။

(1) File --- File Menu ရဲ႕ေအာက္မွာ sub menu ေတြက


(1.1) New
(1.2) Open
(1.3) Save
(1.4) Save As
(1.5) Exit

(2)Edit--- Edit ေအာက္က Sub Menu ေတြက

(2.1) Undo
(2.2) Redo

(2.3) Find

(2.4)Find Replace

(2.5) Select All

(2.6) Copy

(2.7)Cut

(2.8) Pause

(2.9)Delete

(2.10)Find Next

(3)Font -------- Font ရဲ႕ Sub Menu ေတြက

(3.1)WordWrap

(3.2)Select Font

(3.3)Font Color

(3.4)Bold

(3.5)Italic

(3.6)Underline

(3.7)Normal

(3.8)Page Color

(3.9)Selected Font Color

(4) Bullet

(4.1)Add Bullet

(4.2) RemoveBullet
(5)About

ျပီးရင္ ကြ်န္ေတာ္ တုိ႔ text Editor မွာ short cut Key ေတြ ဖန္တီးၾကမယ္။ အေပၚက File ေအာက္က
New မွာ ကို ေထာက္လိုက္။ ျပီးရင္ သူ႕ရဲ႕ Properties မွာ ShortCutKeys ဆိုတာေလးကို နွိပ္လိုက္ရင္
Ctrl , Shift, Alt ဆိုတာနဲ႔ ေအာက္မွာ Key ဆိုတာေတြ႕လိမ့္မယ္။ ကြ်န္ေတာ္ တိ႔ုက New မွာ Ctrl+N
ထားခ်င္တာဆိုေတာ့ Ctrl ကို အမွန္ျခစ္ျပီးေအာက္က Key ထဲက N ကုိေရြးလိုက္တယ္။ အျခား short
cut key ေတြလည္းအဲဒီပုံစအတိုင္းလိုက္လုပ္ပါ။ကိုယ္ေပးခ်င္တဲ့ key ေပးလိ႔ရ
ု ပါတယ္။ Select All
ဆိုရင္ Ctrl+A, Copy—Ctrl+C အစရွိသျဖင့္ စိတ္ၾကိဳက္ဖန္တီးလို႔ရပါတယ္။

ဒီတခါ ToolStrip ယူျပီး Button (၁၁) ခု Add ပါ။ျပီးရင္ အဲဒီ button ေတြမွာ image ေတြထည့္ပါမယ္။
အဲဒီ button ကို click ပါ။ ျပိးရင္ properties --- > image ကေန သြားထည့္ပါ။ျပီးရင္ Richtext box
တခု ယူျပီး ညာဘက္ထိပ္မွာပါတဲ့ ၾတိဂံပံုေသးေသးေလးက Dock in Parent Container ကို ေရြးပါ။
ပံု(၁) မွာ ျပထားတဲ့အတိုင္း ရလာပါလိမ့္မယ္။အဲဒီပံုရဲ႕ ဒုတိယ bar မွာျမင္ေနရတဲ့ Folder,စာလံုး၊
မွန္ဘီလူး၊ aligement စတာေတြက Button ေပၚေတြမွာ image ေတြ add ထားတာပါ။ အဲဒီ
ပံုေတြကေတာ့ ကိုယ့္စက္ထဲမွာ ရွိမွ ရပါ့မယ္။ မရွိရင္လည္း ရွိတဲ့ ပံု add ပါ။ ဘာပံုမွ
မထည့္လည္းရပါတယ္။အဲလိုဆို၇င္ေတာ့ သူ႕ရဲ႕ မႈရင္းေပးထားတဲ့အတိုင္း ရွိေနပါလိမ့္မယ္။ျပီ

ပံု-၁
MenuStrip မွာ နာမည္ေပးတာနဲ႕ Tool Strip အသံုးျပဳပံုကို Typing Master Game မွာ အေသးစိတ္
ေဆြးေႏြးခဲ့ျပီးျဖစ္ပါတယ္။ေအာက္ပါ link မွာ သြားၾကည့္ပါ။

https://www.facebook.com/771934899529239/photos/pcb.777058325683563/7770573
59016993/?type=1&theater

(၂) Coding ပိုင္း

Coding ပိုင္းမွာ Button ေတြမ်ားလိ႔ု ေရးစရာေတြမ်ားေပမယ့္ C# keyword ေတြကိုဘဲ


အသုံးျပဳထားတာ ျဖစ္တဲ့အတြက္ ရွင္းစရာ နဲပါတယ္။ အိုေက စရေအာင္။ အရင္ဆံုး လိုအပ္တဲ့
variable ေတြကို ေၾကျငာရပါမယ္။ Public Form(1) ဆိ္ုတဲ့ စာလံုးရဲ႕ အေပၚမွာ ေအာက္ပါ
အတိုင္းေရးပါ။

public string Path = "";


public static string FindText;
public static string ReplaceText;
public static Boolean Matchcase;
int x;

ဒီေနရာမွာ ဘာ့ေၾကာင့္ Public ေတြ သံုးလဲဆိုေတာ့ အျခား Form ေတြကေန ေခၚသံုးမွာေၾကာင့္ဘဲ ျဖစ္ပါတယ္။ Public
အေၾကာင္းအေသးစိတ္ကိုေတာ့ မၾကာခင္ သီအရ
ုိ ီ အပိုင္းမွာ အေသးစိတ္ ရွင္းျပပါလိမ့္မယ္။အခုေတာ့ ဒီအတိုင္းေလးဘဲ
နားလည္ထားလိုက္ပါဥိး ။ ျပီးရင္ File ေအာက္က New ဆိတ
ု ာ ကို ႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void newToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Clear();
}

Open ကို ႏွိပ္ျပိး ေအာက္ပါ code ကို ေရးပါ။

private void openToolStripMenuItem_Click(object sender, EventArgs e)


{
// စက္ထဲက ရွိတ့ဲ txt File ကို Rightext box ေပၚ loading လုပ္ျခင္း
OpenFileDialog op = new OpenFileDialog();
op.Filter = "Text files(*.txt)|*.txt|(*.RTF)|*.rtf";
op.FileName = "";
if (op.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(op.FileName, RichTextBoxStreamType.PlainText);
Path = op.FileName;
}
}

ဒီ op.Filter = "Text files(*.txt)|*.txt|(*.RTF)|*.rtf"; code အေၾကာင္းကိုေတာ့ နဲနဲရွင္းျပခ်င္ပါတယ္။ C# မွာ File


Extension ေၾကျငာတာ (*.filename)|File Extension ျဖစ္ပါတယ္။ ဆိလ
ု တ
ုိ ာက (*.txt) ဆိတ
ု ာ File name ပါ။ သူ႕ေနာက္က
*.txt ဆိုတာကမွ File Extension ျဖစ္ပါတယ္။ သူတုိ႔ ၂ ခုၾကားမွာ | (တုတ္ေခ်ာင္းေလး shift+\) ခံေရးေပးရပါတယ္။ Spacebar
မလိုပါဘူး။ Spacebar ပါရင္ အမွန္အတိုင္း အလုပ္မလုပ္ပါဘူး။အဲဒီ တုတေ
္ ခ်ာင္း | ေလးက အေရးၾကီးပါတယ္။ အဲဒီထဲကို
ေနာက္ထပ္ Extension ထပ္ေပါင္းခ်င္ရင္လည္း |(*.fielname)|*.file Extension ဆိုျပီးေပါင္းေပးရပါတယ္။ C# program ရဲ႕
Syntax structure အရ အဲလိုသတ္မွတ္ထားလို႔ျဖစ္ပါတယ္။

အိုေက ။ ျပီးရင္ save ကိႏ


ု ပ
ိွ ျ္ ပီး ေအာက္ပါ code ကိုေရးပါ။

private void saveToolStripMenuItem_Click(object sender, EventArgs e)


{
// File Save ျခင္း
SaveFileDialog SFD = new SaveFileDialog();
if (Path != "")
{
richTextBox1.SaveFile(Path);
}
else
{
// Save file extension ကို .txt နဲ႔ save မယ္ဆိုျပီး စစ္ထုတ္လိုက္တာပါ။
SFD.Filter = "Text files(*.txt)|*.txt|(*.RTF)|*.rtf";
SFD.FileName = "";
if (SFD.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(SFD.FileName, RichTextBoxStreamType.PlainText);
Path = SFD.FileName;
}
}
}

ဒီေနရာမွာ SaveFileDialog function ကို ယူျပီးသံုးလိုက္တာပါဘဲ။အလားတူဘဲ save ရမဲ့ file extension ကို txt , rtf ဆိုျပီး
စစ္ေပးထားပါတယ္။။ ျပိးရင္ Save As ကိႏ
ု ပ
ိွ ျ္ ပိး ေအာက္ပါ code ကိုေရးပါ

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)


{
SaveFileDialog SFD = new SaveFileDialog();
SFD.Filter = "Text File(*.txt)|*.txt|(*.RTF)|*.RTF";
SFD.FileName = "";
if (SFD.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(SFD.FileName, RichTextBoxStreamType.PlainText);
Path = SFD.FileName;
}

Exit ကို ႏွိပ္ျပီး ေအာက္ပါ code ေရးပါ။

private void exitCtrlEToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

ျပီးရင္ နံပတ္ (၂) column ျဖစ္တ့ဲ Edit ေအာက္က Undo ကို ႏွိပ္ျပီး ေအာက္ပါ code ကိုေရးပါ

private void undoCtrlZToolStripMenuItem_Click(object sender, EventArgs e)


{
// Undo လုပ္ျခင္း
richTextBox1.Undo();
}

ျပီးရင္ Redo

private void redoCtrlRToolStripMenuItem_Click(object sender, EventArgs e)


{
//Redo လုပ္ျခင္း
richTextBox1.Redo();
}

ျပီးရင္ Find ကိႏ


ု ပ
ိွ ျ္ ပီး ေအာက္က code ကိုေရးပါ။ ဒိေနရာမွာေတာ့ သီးျခား ရွင္းစရာေတြပါလာပါျပိ။ သူက အျခား Form ကို
လွမ္းျပီး command ေပးတာျဖစ္လို႔ပါ။

private void findCtrlFToolStripMenuItem_Click(object sender, EventArgs e)


{
// Text ေတြကို ရွာျခင္း
Find F = new Find();
F.ShowDialog();
if (FindText != "")
{
richTextBox1.Find(FindText);
}
}
အထက္ပါ code က Find ဆိုတာကို အခု program မွာ မပါေသးပါဘူး။ အဲဒီ Find ကို ထည့္ရပါတယ္။ Solution Explorer
ေအာက္က window form application Form 1 ဆိုတာကို R_click ေထာက္ျပီး Add--- >Window Form ဆိုျပီးေပးပါ။ Window
ေလးတခု ေပၚလာပါမယ္။ အဲဒီကေန Window Form ဆိုတာကိုေရြးလိုက္ရင္ ေအာက္က name အကြက္ေလးထဲမွာ Form2.cs
ဆိျု ပီး ျဖစ္ေနလိမ့္မယ္။ အဲဒါကို Find.Cs ဆိျု ပီး ျပင္-- Add ေပးလိုက္ပါ။ အခု ဆိရ
ု င္ ကြ်န္ေတာ္ တို႔ program မွာ Find ဆိုတ့ဲ
Window Form တခု ထပ္တိုးလာျပီ ျဖစ္ပါတယ္။ အဲဒီ Find ကို ၂ခ်က္ ႏွိပ္ဖင
ြ ့္ျပီး ပံု (၂) အတိုင္း ရေအာင္ ျပင္လိုက္ပါ။

ပံု၂

Form----- > Properties ----- > FormBorderStyle----- > FixedToolWindow ေပးလိုက္ရင္ အေပၚက bar အတိုင္း close
button ဘဲ ေတြ႕ရေတာ့မွာ ျဖစ္ပါတယ္။ က်န္တာကေတာ့ ဖန္တီးတတ္မယ္ထင္ပါတယ္။ အိုေက-- အခု Find Button ကို ႏွိပ္ျပီး
ေအာ္ကပါ code ေရးပါ။ အခု ေရးတဲ့ code ေတြက ကြ်န္ေတာ္ တို႕ရဲ႕ main form မွာ မဟုတ္ဘူးေနာ္။ အသစ္ယူထားတဲ့ Find
Form က Find Button ေအာက္မွာ ေရးမွာ။

private void Find_btn_Click(object sender, EventArgs e)


{
Form1.FindText = textBox1.Text;
this.Close();
}

ျပီးရင္ Cancel Button

private void cancel_btn_Click(object sender, EventArgs e)


{
Form1.FindText = "";
this.Close();
}

ျပီးရင္ CheckedBox ကို ႏွိပ္ျပိး

private void checkBox1_CheckedChanged(object sender, EventArgs e)


{
if (checkBox1.Checked == true)
{
Form1.Matchcase = true;
}
else
{
Form1.Matchcase = false;
}
}

Find Form အတြက္ လိုအပ္တဲ့ code ေတြေရးျပီးပါျပီ။ အဲဒီ Find Form နဲ႔ Find.cs ကို ပိတ္လို္က္ပါ။ အခု ကြ်န္ေတာ္ တို႔ရဲ႕ Main
Form ကို ျပန္သြားပါမယ္။ Edit ေအာက္က FindReplace ကို ႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void findReplaceCtrlShiftFToolStripMenuItem_Click(object sender, EventArgs e)


{
Replace R = new Replace();
R.ShowDialog();
richTextBox1.Find(FindText);
if (richTextBox1.SelectedText != "")
richTextBox1.SelectedText = ReplaceText;
}

ဒီေနရာမွာလည္း Replace ဆိုတာကို ေတြ႕ဦးမွာမဟုတ္ပါဘူး။ သူ႕အတြက္ ေနာက္ထပ္ Form တခု ထပ္ add ေပးရပါမယ္။
အေပၚက နည္းအတိုင္း Add ပါ။ File name မွာ Replace.cs ဆိုျပိးေပးပါ။ အဲဒါဆိုရင္ ေနာက္ထပ္ Replace Form တခု
ေပၚလာပါျပီ။ ေအာက္ပါ ပံု(၃) အတိုင္း လိုအပ္တ့ဲ tool ေတြ add ပါ

ပံု-၃

ျပီးရင္ Replace Button ကိႏ


ု ပ
ိွ ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void button1_Click(object sender, EventArgs e)


{
Form1.FindText = textBox1.Text;
Form1.ReplaceText = textBox2.Text;
this.Close();
}
Replace Form နဲ႔ Replace.cs ဆိုတာကို ပိတ္ပါ။ ကြ်န္ေတာ္ တို႔ရဲ႕ Mainform ကို ျပန္သြားပါမယ္။

Select All ကို ေရးျပီးေအာက္ပါအတိုင္း ေရးပါ။

private void selectAllCtrlAToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.SelectAll();
}

ျပိးရင္ Copy

private void copyCtrlCToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Copy();
}

ျပီးရင္ Cut

private void cutCtrlXToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Cut();
}

ထို႕ေနာက္ Pause

private void pasetCtrlVToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Paste();
}

ျပီးေတာ့ Delete

private void deleteCtrlDToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.SelectedText = "";
}

အခုေနာက္ဆံုး FindNext Text

private void findNextCtrlShiftFToolStripMenuItem_Click(object sender, EventArgs e)


{
if (FindText != "")
{
if (Matchcase == true)
x = richTextBox1.Find(FindText, (x + 1), richTextBox1.Text.Length,
RichTextBoxFinds.MatchCase);
else
x = richTextBox1.Find(FindText, (x + 1), richTextBox1.Text.Length, RichTextBoxFinds.None);

}
}

အခု တတိယ Column ျဖစ္တ့ဲ Font ေအာက္က WordWrap ဆိုတာကို ႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ

private void wordWrapCtrlWToolStripMenuItem_Click(object sender, EventArgs e)


{
if (wordWrapCtrlWToolStripMenuItem.Checked == true)
{
richTextBox1.WordWrap = true;
}
else
richTextBox1.WordWrap = false;
}

ထို႔ေနာက္ Select Font

private void selectFontToolStripMenuItem_Click(object sender, EventArgs e)


{
FontDialog FD = new FontDialog();
if (FD.ShowDialog() == DialogResult.OK)
{
richTextBox1.Font = FD.Font;
}
}

ျပီးရင္ Font Color

private void fontColorToolStripMenuItem_Click(object sender, EventArgs e)


{
ColorDialog CD = new ColorDialog();
if (CD.ShowDialog() == DialogResult.OK)
{
richTextBox1.ForeColor = CD.Color;
}
}

ျပီးရင္ Bold

private void boldCtrlBToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Bold);
}

ဆက္လက္ျပီး Italic

private void italicCtrlIToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Italic);
}

ေနာ္ကတခုက Underline

private void underlineCtrlUToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Underline);
}

ျပီးရင္ Normal

private void normalCtrlRToolStripMenuItem_Click(object sender, EventArgs e)


{
richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^ FontStyle.Regular);
}
ျပီးရင္ Pagecolor

private void pageColorCtrlShiftCToolStripMenuItem_Click(object sender, EventArgs e)


{
ColorDialog CD = new ColorDialog();
if (CD.ShowDialog() == DialogResult.OK)
{
richTextBox1.BackColor = CD.Color;
}
}

ေနာက္ဆံုးတခုက Selected Font Color

private void selectedFontColorToolStripMenuItem_Click(object sender, EventArgs e)


{
ColorDialog CD = new ColorDialog();
if (CD.ShowDialog() == DialogResult.OK)
{
richTextBox1.SelectionColor = CD.Color;
}
}
အခု စတုတၳ column Bullet ရဲ႕ Add Bullet ေအာက္မွာ

private void removeBulletToolStripMenuItem_Click(object sender, EventArgs e)


{
if (removeBulletsToolStripMenuItem.Checked == true)
{
removeBulletsToolStripMenuItem.Checked = false;
richTextBox1.BulletIndent = 10;
richTextBox1.SelectionBullet = false;
}
else
richTextBox1.SelectionBullet = true;
}

ေနာက္ထပ္ Remove Bullet မွာ

private void addBulletsToolStripMenuItem_Click(object sender, EventArgs e)


{
if (removeBulletsToolStripMenuItem.Checked == true)
{
richTextBox1.BulletIndent = 10;
richTextBox1.SelectionBullet = true;
addBulletToolStripMenuItem.Checked = false;
}
else
{
richTextBox1.SelectionBullet = false;
}
}

အခု ဆို ကြ်န္ေတာ္ တုိ႔ Text Editor က ျပီးမယ္ဆို ျပီးလို႔ရေနျပီ။ဒါေပယ့္က်ြ န္ေတာ္က က ေၾကာ္ျငာ ၀င္ခ်င္ေသးေတာ့ About
Form တခု ထပ္ထည့္ထားေသးတယ္ဗ်။ အဲဒီေတာ့ ေနာ္ကဆံုးက About ကို ၂ ခ်က္ႏွိပ္ျပိး ေအာက္က code ေရးလိုက္ပါဥိး။

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)


{
About A = new About();
A.ShowDialog();
}

ဒီေနရာမွာလည္း About ဆိုတ့ဲ Form ကို အထက္ပါ နည္းေတြအတိုင္း ထပ္ျပီး add ပါ။ name ကိုေတာ့ About.Cs
ဆိုျပီးေပးပါ။ျပိးရင္ ပံ(ု ၄) အတိုင္း ျပင္လိုက္ပါ။
ပံ-ု ၄

အဲဒီစာက level ၁ ခုယူျပီး level မွာ ေရးထားတာပါ။အဲဒိ Form မွာ go page ဆိုတ့ဲ အျပာေရာင္ စာလုံးေလးနဲ႔
မ်ဥ္းသားထားတာကို ေတြ႕ရလိမ့္မယ္ဗ်။ အဲဒါေလးက linklabel ယူျပီး text မွာ go page လို႔ေရးထားတာပါ။ အဲဒီ ေပၚကို ၂
ခ်က္ႏွိပ္ျပိး ေအာက္ပါ code ေရးပါ။ အဲဒါေလးကို ႏွိပ္လိုက္ရင္ ကြ်န္ေတာ္ တို႔ညႊန္းထားတဲ့ internert page ကို
ေရာက္သြားပါလိမ့္မယ္။

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)


{
System.Diagnostics.Process.Start("https://www.facebook.com/pages/C-and-C-plus-plus-programming-
language-for-beginner/771934899529239");
}

အခုဆို ကြ်န္ေတာ္ တို႔ရဲ႕ program ေလး အဆံုးသတ္-ေတာ့မွာ ျဖစ္ပါတယ္။ သတ္ေတာ့မသတ္ေသးပါဘူး။ ကြ်န္ေတာ္ နိဒါန္းမွာ
ေျပာခဲ့သလို ေရွ႕သင္ခန္းစာက splash screen ကို အသံုးျပဳမယ္ဆိုတာေလ။ အဲဒီေတာ့ ေနာက္ ထပ္ Form တခု ထပ္ယူျပီး
Splash.cs လို႔ နာမည္ေပးလိုက္။ ျပီးရင္ ကြ်န္ေတာ္ တို႔ ေရွ႕သင္ခန္းစာ အတိုင္းဘဲ picture box ယူမယ္ ။ Dock ေပးမယ္။ picture
ထည့္မယ္။ ျပီးရင္ Form ရဲ႕ Properties မွာ FormBolder Style ကို None ေပးမယ္။ timer တခု ယူမယ္။ double click--- >
ေအာက္ပါ code ကို ေရးမယ္။

public Splash_Screen()
{
this.Opacity = .01;
this.CenterToScreen();
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)


{
this.Opacity = this.Opacity + .01;
if (this.Opacity == 1)
{
timer1.Enabled = false;
this.Visible = false;
this.Close();
}
}
ဒီအတိုင္း run လိုက္ရင္ အဲဒီ splash screen ၾကီးက program စတတ္တတ္ခ်င္း အလုပ္မလုပ္ပါဘူး။ကြ်န္ေတာ္တို႔က program
စတတ္တတ္ခ်င္းမွာ slow motion ေလးနဲ႔တတ္ျပိးမွ ကြ်န္ေတာ္ တို႔ mainform ကို ေပၚေစခ်င္တာ။ Ro ဆန္ေနတာ  ။
အဲဒီလိုျဖစ္ေအာင္ Solution Explorer မွာ Program.cs ဆိုတ့ဲ File ကို ရွာ(ေတြ႔ေအာင္ရွာေနာ္။ မွားလည္းမမွားေစနဲ႔။ အျခား file
မရဘူး။) ျပီး အခုလိုပံုစံေလးျဖစ္ေအာင္ ျပင္လိုက္ပါ။

static void Main()


{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Splash_Screen());
Application.Run(new Form1());
}

အဲဒီမွာ ကြ်န္ေတာ္ တို႔ ထပ္ေပါင္းေပးရတာ Application.Run(new Splash_Screen()); ဆိုတာေလးဘဲ။က်န္တာက သူ႕ နဂို


ရွိျပိးသားပါ။ စာဖတ္သူ မ်က္စိလည္ေနမွာစိုးလိ႔ တခါထဲ အျပည့္အစံုေပးလိုက္တာ။

အခု ကြ်န္ေတာ္ တို႔ menustrip bar က textbox ေတြမွာ code ေတြ အကုန္ ေရးျပိးျပီ။ အခု အဲဒီ code ေတြကို toolstrip bar
က button ေတြမွာ copy လုပ္မယ္။ အဲဒီလို function ေတြကို copy လုပ္တ့ဲ နည္းကိုလည္း number system converter မွာ
ကြ်န္ေတာ္ ေဆြးေႏြးျပီးျဖစ္ပါတယ္ေနာ္။ အခု toolstrip bar ဘယ္ဘက္ထိပ္ဆံုးက toolStripButton1 ဆိုတာကို နွိပ္လုိက္ပါ။
အဲဒီေနရာမွာ စာဖတ္သူ စိတ္ၾကိဳက္ text ျပင္လို႔ရပါတယ္။ ကြ်န္ေတာ္ကေတာ့ new လို႔ျပင္ထားပါတယ္။
မျပင္လည္းရေတာ့ရပါတယ္။ ဟုတျ္ ပီး အဲဒီေပၚကိုတခ်က္ ႏွိပ္ျပိး သူရဲ႕ Event -----> Click မွာ(button 11 ခုလံုး၇ဲ႕ Click Event
မွာ ျဖစ္ပါတယ္။ ေအာက္ပါ အတိုင္း အစဥ္လိုက္ထည့္သြားပါ။ ဆိလ
ု တ
ုိ ာက Button1---click---event= toostripbuttonclick,
Button2--- click--- envet---- =openToolstripmenuitemclick-- အစရွိသျဖင့္)

(၁)toolStripButton1_Click

(၂)openToolStripMenuItem_Click

(၃)saveToolStripMenuItem_Click

(၄)selectFontToolStripMenuItem_Click

(၅)toolStripButton5_Click

(၆)toolStripButton6_Click

(၇)toolStripButton7_Click

(၈)boldCtrlBToolStripMenuItem_Click

(၉)underlineCtrlUToolStripMenuItem_Click

(၁၀)italicCtrlIToolStripMenuItem_Click
(၁၁)findCtrlFToolStripMenuItem_Click

ဆိုျပီးေပးလိုက္ရင္ ကြ်န္ေတာ္တို႔ menu strip bar မွာ ေရးထားတဲ့ လုပ္ငန္းမွန္သမွ်ဟာ အထက္ပါ button ေတြမွာ အလုပ္လုပ္မွာ
ဘဲျဖစ္ပါတယ္။ ကြ်န္ေတာ္ ျပထားတဲ့ပံုထဲမွာေတာ့ ကြ်န္ေတာ့္ button ေတြ မွာ image ေတြ add ထားတာျဖစ္လို႔ ထည့္ထားတဲ့
ပံုေတြ အတိုင္းျပေနပါတယ္။ စာဖတ္သူက ဘာပံုမွ ထည့္မထားဘူးဆိုရင္မူရင္း အတိုင္း ေတာင္ထိပ္မွာ
ေနထြက္ေနတဲ့ပံုေသးေသးေလးဘဲ ျပေနပါလိမ့္မယ္။

ကဲ အခုေတာ့ ကြ်န္ေတာ္တုိ႔႕ Text Editor ျပီးပါျပိ။ Run ျပီး အဲဒိထဲက function ေတြကို တခုခ်င္း စမ္းၾကည့္ေစခ်င္ပါတယ္။
Zawgyione လည္း ရိုက္လ႔ိုရပါတယ္။

နိဂံုး
ကြ်န္ေတာ္ ဒိ Text Editor ကို ေဆြးေႏြးရျခင္းရဲ႕ ရည္ရြယ္ခ်က္ကို ေျပာျပခ်င္ပါတယ္။ ကြ်န္ေတာ္ တိ႔ု
ကြန္ပ်ဴတာမွာ MS word , notepad, wordpad အစရိွသျဖင့္ ဒီထက္ေကာင္းတဲ့ text editor
ေတြရွိျပီးသားျဖစ္လုိ႔ဒီ texteditor ေတြကို သံုးမွာေတာ့မဟုတ္ပါဘူး။ဒါေပသိ-- programming ကို
ေလ့လာေနတဲ့သူတေယာက္အေနနဲ႔ အဲဒီ text Editor ေတြေနာက္မွာ program code ေတြ
ဘယ္လိုအလုပ္လုပ္ေနသလဲဆိုတာ ကို သိေစခ်င္တဲ့ အခ်က္ရယ္။ အဓိကကေတာ့ အသုံး၀င္တဲ့ C#
ရဲ႕ key word ေတြနဲ႔ မိတ္ဆက္ေပးခ်င္တာပါဘဲ။ ဒီထဲမွာတကယ့္ကို အသံုး၀င္တဲ့ key word ေတြ
အမ်ားၾကီးပါပါတယ္။ Find Function ဆိ၇
ု င္ ကိုယ္ပိုင္ အဘိဓါန္ေတြ ေဆာက္တဲ့ေနရာမွာ
သံုးလိ႔ရ
ု တယ္။အျခားသံုးလို႔ရတဲေ့နရာေတြလည္း အမ်ားၾကီး ရွိပါတယ္။ ဒီထဲက code ေတြကို
နားလည္ထားျခင္းအားျဖင့္ လိုအပ္တဲ့ အခါ ကိုယ္လိုတဲ့ အပိုင္းေလးကိုဘဲ ဆြဲသံုးလို႔ရႏိုင္မွာ
ျဖစ္ပါတယ္။ အားလံုးဘဲ ေက်နပ္ၾကမယ္လို႔ ေမွ်ာ္လင့္ပါတယ္။ေနာက္ေန႔မွ ျပန္ဆံုၾကတာေပါ့ဗ်ာ
။ေအာက္မွာ Code အျပည့္အစံုေပးလိုက္ပါတယ္။

Form1.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 Notepad

public partial class Form1 : Form

public string Path = "";

public static string FindText;

public static string ReplaceText;

public static Boolean Matchcase;

int x;

public Form1()

InitializeComponent();

private void newToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Clear();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)

// စက္ထဲက ရွိတဲ့ txt File ကို Rightext box ေပၚ loading လုပ္ျခင္း

OpenFileDialog op = new OpenFileDialog();

op.Filter = "Text files(*.txt)|*.txt|(*.RTF)|*.rtf";

op.FileName = "";

if (op.ShowDialog() == DialogResult.OK)

richTextBox1.LoadFile(op.FileName, RichTextBoxStreamType.PlainText);

Path = op.FileName;

private void saveToolStripMenuItem_Click(object sender, EventArgs e)

// File Save ျခင္း

SaveFileDialog SFD = new SaveFileDialog();

if (Path != "")

richTextBox1.SaveFile(Path);
}

else

// Save file extension ကို .txt နဲ႔ save မယ္ဆိုျပီး စစ္ထုတ္လိုက္တာပါ။

SFD.Filter = "Text files(*.txt)|*.txt|(*.RTF)|*.rtf";

SFD.FileName = "";

if (SFD.ShowDialog() == DialogResult.OK)

richTextBox1.SaveFile(SFD.FileName, RichTextBoxStreamType.PlainText);

Path = SFD.FileName;

private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)

SaveFileDialog SFD = new SaveFileDialog();

SFD.Filter = "Text File(*.txt)|*.txt|(*.RTF)|*.RTF";

SFD.FileName = "";

if (SFD.ShowDialog() == DialogResult.OK)

richTextBox1.SaveFile(SFD.FileName, RichTextBoxStreamType.PlainText);
Path = SFD.FileName;

private void exitCtrlEToolStripMenuItem_Click(object sender, EventArgs e)

Application.Exit();

private void undoCtrlZToolStripMenuItem_Click(object sender, EventArgs e)

// Undo လုပ္ျခင္း

richTextBox1.Undo();

private void redoCtrlRToolStripMenuItem_Click(object sender, EventArgs e)

//Redo လုပ္ျခင္း

richTextBox1.Redo();

}
private void findCtrlFToolStripMenuItem_Click(object sender, EventArgs e)

// Text ေတြကို ရွာျခင္း

Find F = new Find();

F.ShowDialog();

if (FindText != "")

richTextBox1.Find(FindText);

private void findReplaceCtrlShiftFToolStripMenuItem_Click(object sender,


EventArgs e)

Replace R = new Replace();

R.ShowDialog();

richTextBox1.Find(FindText);

if (richTextBox1.SelectedText != " ")

richTextBox1.SelectedText = ReplaceText;

private void selectAllCtrlAToolStripMenuItem_Click(object sender, EventArgs e)


{

richTextBox1.SelectAll();

private void copyCtrlCToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Copy();

private void cutCtrlXToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Cut();

private void pasetCtrlVToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Paste();

private void deleteCtrlDToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.SelectedText = "";
}

private void findNextCtrlShiftFToolStripMenuItem_Click(object sender, EventArgs e)

if (FindText != "")

if (Matchcase == true)

x = richTextBox1.Find(FindText, (x + 1), richTextBox1.Text.Length,


RichTextBoxFinds.MatchCase);

else

x = richTextBox1.Find(FindText, (x + 1), richTextBox1.Text.Length,


RichTextBoxFinds.None);

private void wordWrapCtrlWToolStripMenuItem_Click(object sender, EventArgs e)

if (wordWrapCtrlWToolStripMenuItem.Checked == true)

richTextBox1.WordWrap = true;

else
richTextBox1.WordWrap = false;

private void selectFontToolStripMenuItem_Click(object sender, EventArgs e)

FontDialog FD = new FontDialog();

if (FD.ShowDialog() == DialogResult.OK)

richTextBox1.Font = FD.Font;

private void fontColorToolStripMenuItem_Click(object sender, EventArgs e)

ColorDialog CD = new ColorDialog();

if (CD.ShowDialog() == DialogResult.OK)

richTextBox1.ForeColor = CD.Color;

private void boldCtrlBToolStripMenuItem_Click(object sender, EventArgs e)


{

richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^


FontStyle.Bold);

private void italicCtrlIToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^


FontStyle.Italic);

private void underlineCtrlUToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^


FontStyle.Underline);

private void normalCtrlRToolStripMenuItem_Click(object sender, EventArgs e)

richTextBox1.Font = new Font(richTextBox1.Font, richTextBox1.Font.Style ^


FontStyle.Regular);

}
private void pageColorCtrlShiftCToolStripMenuItem_Click(object sender, EventArgs
e)

ColorDialog CD = new ColorDialog();

if (CD.ShowDialog() == DialogResult.OK)

richTextBox1.BackColor = CD.Color;

private void selectedFontColorToolStripMenuItem_Click(object sender, EventArgs


e)

ColorDialog CD = new ColorDialog();

if (CD.ShowDialog() == DialogResult.OK)

richTextBox1.SelectionColor = CD.Color;

private void addBulletsToolStripMenuItem_Click(object sender, EventArgs e)

if (removeBulletsToolStripMenuItem.Checked == true)
{

richTextBox1.BulletIndent = 10;

richTextBox1.SelectionBullet = true;

addBulletToolStripMenuItem.Checked = false;

else

richTextBox1.SelectionBullet = false;

private void removeBulletToolStripMenuItem_Click(object sender, EventArgs e)

if (removeBulletsToolStripMenuItem.Checked == true)

removeBulletsToolStripMenuItem.Checked = false;

richTextBox1.BulletIndent = 10;

richTextBox1.SelectionBullet = false;

else

richTextBox1.SelectionBullet = true;

}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)

About A = new About();

A.ShowDialog();

private void toolStripButton9_Click(object sender, EventArgs e)

private void toolStripButton5_Click(object sender, EventArgs e)

richTextBox1.SelectionAlignment = HorizontalAlignment.Left;

private void toolStripButton1_Click(object sender, EventArgs e)

richTextBox1.Clear();

}
private void toolStripButton6_Click(object sender, EventArgs e)

richTextBox1.SelectionAlignment = HorizontalAlignment.Center;

private void toolStripButton7_Click(object sender, EventArgs e)

richTextBox1.SelectionAlignment = HorizontalAlignment.Right;

private void selectedFontBackgroundToolStripMenuItem_Click(object sender,


EventArgs e)

}
Computer System tool
ကြ်န္ေတာ္ ဒီေန႔ computer System Tool ဖန္တီးတဲ့ သင္ခန္းစာကို ေဆြးေႏြးသြားမွာ ျဖစ္ပါတယ္။ အဲဒီ
program မွာ OS ရဲ႕ System control ေတြျဖစ္တဲ့ Taskmanager ၊ registry ၊ Run Box ၊ CMD ၊ Control
Panel disable,enable လုပ္တာ။ကြ်န္ေတာ္ တု႔ိ ကြန္ပ်ဴတာ ရဲ႕ System information ေတြ ၾကည့္တာ timer
နဲ႔ shutdown, restart ခ်တာေတြ၊ Alarm ေပးတာ စတဲ့ Function ေတြပါ၀င္မွာျဖစ္ပါတယ္။ Function ေတြ
မ်ားတဲ့အတြက္ ဒီသင္ခန္းစာ ကို ၂ ပိုင္း ခြဲျပီး ေဆြးေႏြးသြားမွာျဖစ္ပါတယ္။ ဒီေန႔ ပထမ အပိုင္း အေနနဲ႔ေတာ့
System control ပိုင္းကို ေဆြးေႏြးသြာမွာ ျဖစ္ျပီး Timer နဲ႔ ပက္သက္တဲ့ function ေတြကို ေတာ့ ဒုတယ

အပိုင္းမွာ ဆက္လက္ေဆြးေႏြးသြားမွာျဖစ္ပါတယ္။

အပိုင္း(၁) System Control


Window Form တခု ကို ယူျပီး ေအာက္ပါ tool မ်ား add လိုက္ပါ။

GroupBox (၁) ခု

CheckBox (၅) ခု

Button (၂) ခု

ပံု(၁) မွာ ျပထားတဲ့ အတိုင္း ရလာပါမယ္။

ပံ-ု

ပံု(၁) မွာ ျပထားတဲ့အတိုင္း နာမည္ေပးလိုက္ပါ။ျပီးရင္ checkbox ေတြ အားလံုးရဲ႕ properties ကို သြားျပီး
Check state--- > Check ေပးထားပါ။ ျပီးရင္ Task Manager Enable ကို double click ႏွိပ္ျပီး ေအာက္ပါ
code ကိုေရး။ မေရးခင္မွာ လိုအပ္တဲ့ System ေၾကျငာေပးရမယ္။ေအာက္က ၂ ေၾကာင္းကို အေပၚဆံုးမွာ
သြားေၾကျငာ ေပးပါ။

using Microsoft.Win32;
using System.Diagnostics;

private void checkBox1_CheckedChanged(object sender, EventArgs e)


{
if (checkBox1.Checked == false)
{
RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;
RegistryKey key =
HKCU.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
key.SetValue("DisableTaskMgr", 1, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
MessageBox.Show("TaskManager is Disable");
}

else
{
Microsoft.Win32.RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey key =
HKCU.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
key.SetValue("DisableTaskMgr", 0, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
MessageBox.Show("TaskManager is Enable");
}
}
ကြ်န္ေတာ္ ဒီcode ကို နဲနဲ ရွင္းျပပါမယ္။ ေနာက္လာမဲ့ code ေတြ က် မရွင္းေတာ့ပါဘူး။ သေဘာတရားအတူတူမိုလို႔ပါ။
Taskmanager ဆိုတဲ့ Checkbox က program စတတ္တဲ့ အခ်ိန္မွာ check box state – check ေပးထားတာ ပါတယ္။
အဓိပၸါယ္က ေလာေလာဆယ္ taskmanager Enable ပါ။ program ကို Run ျပီး အမွန္ျခစ္ကို ျဖဳတ္လိုက္ရင္ သူ႕ရဲ႕ state က
false ျဖစ္သာြ းပါျပီ။ အဲဒီေတာ့ check1.checked= false ျဖစ္တဲ့ အတြက္ ပထမ condition အတိုင္း အလုပ္လုပ္ပါမယ္။ အဲဒီမွာ
RegistryKey ဆိတ
ု ာ ကြ်န္ေတာ္ တို႔ အေပၚမွာ ေၾကျငာခဲ့တ့ဲ Microsoft.Win32 ဆိုတ့ဲ System ေအာက္မွာ ရွိတာပါ။အဲဒါေၾကာင့္
အဲဒါကို အရင္ေၾကျငာေပးမွ RegistryKey ဆိုတာ ေပၚလာတာပါ။ Run Box ကေန regedit လို႔ရိုက္ျပီးဖြင့္လိုက္ရင္ registry
editor ေပၚလာပါမယ္။ My computer ေအာက္မွာ
(1) H_C_R
(2) H_C_U
(3) H_L_M
(4) H_U
(5) H_C_C ဆိုျပီးေတာ့ Registry Main Root (၅) ခုေတြ႔ပါလိမ့္မယ္ ။ အခ်ိန္ကုန္မွာဆုိးလို႔ အတိုေတြဘဲ ေရးလို္က္ပါတယ္။
အခု ကြ်န္ေတာ္ ေအာက္မွာ ေရးလိုက္တ့ဲ code က ဒုတိယ ေျမာက္ Hkey_Current_User ေအာက္ကို
ညႊန္းလိုက္တာပါ။

RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;

အခုဆိုကြ်န္ေတာ္ တို႔က H_C_U ေအာက္ထဲ ေရာက္ေနျပီ။ အဲဒီထမ


ဲ ွာ
HKCU.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"); ဒီ command နဲ႔
Registry sub key တခု ဖန္တီးလို္က္ျပီး Key Value ကို “DiasableTaskMgr” နဲ႔ Value ကို 1 ဆိုျပီး

key.SetValue("DisableTaskMgr", 0, Microsoft.Win32.RegistryValueKind.DWord);

ဒီ command နဲ႕ ေပးလိုက္ပါတယ္။ အဲဒီ 1 ဆိုတ့ဲ တန္ဖိုးက အေရးၾကိးပါတယ္။ registry value 0 =true ျဖစ္ျပီး
registry value 1 =false ျဖစ္ပါတယ္။ Disable, Enable ကို အဲဒီ value(1,0) နဲ ဘဲ သတ္မွတ္ပါတယ္။ ႔အဓိပၸါယ္ကေတာ့
အထက္ပါ code ေတြ နဲ႔ ကိယ
ု ္ တိင
ု ္ registry key ေတြ ဖန္တီးျပီး Task Manager ကို control လုပ္လိုက္တာ ျဖစ္ပါတယ္။ Virus
ေရးသားတဲ့ programmer ေတြကလည္း အခုလိုဘဲ သူတုိ႔ program ေတြမွာ ကိုယ္ပိုင္ regedit key ေတြ ဖန္တီးျပိး
ကြန္ပ်ဴတာကို ထိန္းခ်ဴပ္တတ္ၾကပါတယ္။သူတို႔ကေတာ့ ကြ်န္ေတာ္ တို႔ထက္ Effect ျမင့္တဲ့ code ေတြ နဲ႔ ေရးတာေပါ့ဗ်ာ။ အျခား
task ေတြ အမ်ားၾကီးလည္း ပါတာေပါ့။ ကြ်န္ေတာ္တုိ႔ကေတာ့ Beginner အဆင့္ဆိုေတာ့ ဒီေလာက္ဘဲရတယ္ဗ်ာ :D ။
အလားတူဘဲ က်န္တဲ့ System control ကိုလည္း Registry မွာ လမ္းေၾကာင္းသတ္မွတ္၊ ကိယ
ု ပ
္ င
ုိ ္ Key ေတြ ဖန္တီးျပီး
ေရးသားထားပါတယ္။ အားလံုးဟာ CheckBox ေတြကို Double click ႏွိပ္ျပီး checkBox1_CheckedChanged မွာ
ေရးထားတာဘဲ ျဖစ္ပါတယ္။ အားလုံးကို ေအာက္မွာ တစုတေ၀းတည္းေဖၚျပေပးလို္က္ပါတယ္။

private void checkBox2_CheckedChanged(object sender, EventArgs e)


{
if (checkBox2.Checked == false)
{
RegistryKey
SystemRegistry=Registry.CurrentUser.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policie
s\\System");
SystemRegistry.SetValue("DisableRegistryTools",1);
SystemRegistry.Close();
MessageBox.Show("Registry Disable");
}
else
{
RegistryKey SystemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
SystemRegistry.SetValue("DisableRegistryTools", 0);
SystemRegistry.Close();
MessageBox.Show("Registry Enable");
}
}

private void checkBox3_CheckedChanged(object sender, EventArgs e)


{
if (checkBox3.Checked == false)
{
RegistryKey systemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
systemRegistry.SetValue("DisableCMD", 1);
systemRegistry.Close();
MessageBox.Show("Command Prompt is Disable");
}
else
{
{
RegistryKey systemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
systemRegistry.SetValue("DisableCMD", 0);
systemRegistry.Close();
MessageBox.Show("Command Prompt is Enable");
}
}
}

private void checkBox4_CheckedChanged(object sender, EventArgs e)


{
if (checkBox4.Checked == false)
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoRun", 1);
systemRegedit.Close();
MessageBox.Show("Don't Allow Run Box");
}
else
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoRun", 0);
systemRegedit.Close();
MessageBox.Show("Run Box is enable");
}
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
if (checkBox5.Checked == false)
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoControlPanel", 1);
systemRegedit.Close();
MessageBox.Show("Control Panel is disable");
}
else
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoControlPanel", 0);
systemRegedit.Close();
MessageBox.Show("Control Panel Box is enable");
}
}
အထက္ပါ code ေတြကို သတိထားျပီး ေလ့လာၾကည့္ရင္ CreateSubKey ေနာက္က Key path ေတြ
ေျပာင္းသြးတာဘဲ ရွိပါတယ္။ က်န္တာကေတာ့ သေဘာတရားအားလံုးအတူတူပါဘဲ။ Program ကို Run
လိုက္ပါ။ျပီးရင္ check Box ေတြကို Check, Uncheck လုပ္ၾကည့္ပါ။ TaskManager ကို Uncheck
လုပ္လိုက္ရင္ TaskManager is disable ဆိုတဲ့ message box ေပၚလာပါလိမ့္မယ္။ ေအာက္က toolbar မွာ
R_Click ေထာက္ျပီး ၾကည့္ၾကည့္ပါ။ Taskmanager disable ျဖစ္ေနပါျပီ။ Ctrl+Alt+del ႏွိပ္ျပီး ေခၚၾကည့္ပါဥိး
အဲဒီမွာလည္း Task Manager ေပ်ာက္ေနပါတယ္။Check ျပန္လုပ္လိုက္မွ Enable ျပန္ျဖစ္ပါမယ္။ အလားတူ
အျခား checkbox ေတြလည္း အကုန္ အဲဒီ အတိုင္းပါဘဲ။ တခု သတိထားရမွာက Run Box ကေတာ့ Restart
ခ်မွ Active ျဖစ္ပါတယ္။ အခု TabControl တခုယူလိုက္ပါ။ ယူျပီး ပံု (၂) မွာ ျပထားတဲ့အတိုင္း label tool
ေတြယူလိုက္ပါ။ အားလံုး label tool (၁၀) ခု ရွိပါတယ္။ျပီးရင္ အဲဒီ ထိပ္က Hardware ဆိုတဲ့ စာလံုးေလး ကို
ေပၚေအာင္ နာမည္ ေပးမယ္။ အဲဒီ Tab Screen ေပၚကို R_click ေထာက္ျပီး properties ကိုသြားပါ။ Tab Page
က collection ကို ႏွိပ္ပါ။ TabPage collection Editor ဆိုတဲ့ window ေပၚလာပါလိမ့္မယ္။ အဲဒီက Text မွာ
HardWare လိ႔န
ု ာမည္ေပးပါ။ အဲဒီမွာ tabpage ေတြ ထပ္ျပိး Add ခ်င္ရင္ ေအာက္က Add button ကို ႏွိပ္ျပီး
Add လို႔ရသလို ျပန္ဖ်တ္ခ်င္ရင္ေတာ့ Remove ဆိုတာနဲ႔ ျပန္ဖ်တ္လို႔ရပါတယ္။ တခါထဲဘဲ Tabpage 2 ကို
ေထာက္ျပီး text မွာ software လို႔ နာမည္ေပးပါ။ အဲဒိ software မွာလည္း ပံု (၃) မွာ ျပထားတဲ့အတိုင္း tool
ေတြ add ပါ။ အဲဒီထဲမွာလည္း level 10 ခု ရွိပါတယ္။ျပီးသြားရင္System Button ကိုႏွိပ္ျပီး ေအာက္ပါ code ကို
ေရးပါ။
private void button1_Click(object sender, EventArgs e)
{
try
{
label18.Text = SystemInformation.PrimaryMonitorSize.ToString();
label2.Text = System.Environment.SystemDirectory;
label4.Text = System.Environment.MachineName;
label6.Text = System.Environment.WorkingSet.ToString();
int q = System.Environment.TickCount;
int w = (q / 1000) / 60;
label8.Text = w.ToString() + " Minute(s)";
label10.Text = System.Environment.OSVersion.ToString();
label12.Text = System.Environment.Version.ToString();
label14.Text = System.Environment.UserName;
label16.Text = System.Environment.UserDomainName;
RegistryKey Rkey = Registry.LocalMachine;
Rkey = Rkey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
label20.Text = (string)Rkey.GetValue("ProcessorNameString");
}
catch (Exception EX)
{
MessageBox.Show("The Following ERROR Occur ..." + EX.Message.ToString());
}
}

ျပိးရင္ System button ကို ႏွိပ္လိုက္ရင္ စာဖတ္သူ ရဲ႕ computer system information ကို ျပေပးပါလိမ့္မယ္။ ကြ်န္ေတာ့္ ရဲ႕
computer System Tool ပထမပိုင္း ကို ဒီမွာဘဲ နားပါမယ္။ ေနာက္တေန႔မွ က်န္တ့ဲ ဒုတိယ ပိုင္းကို ဆက္ပါမယ္။
ပံု-

ပံ-ု ၃
အပိုင္း(၂)
ဒုတယ
ိ အပိုင္း အေနနဲ႔ ကြ်န္ေတာ္တို႕ comuter သံုးတဲ့အခါမွာ က်န္ခဲ့တဲ အမိႈက္ file(temp,prfetch)
ေတြရွင္းတာ၊ Auto Scan Disk ၊ Disk Defragment ,internet cookies ေတြ ဖ်တ္တာ အစရွိတဲ့ Function
အလုပ္လုပ္ပံု အေၾကာင္းကို ေဆြးေႏြးသြားမွာ ျဖစ္ပါတယ္။ အဲဒီ function ေတြ ကို C# မွာ မဟုတ္ဘဲ
အျပင္ဘက္က .bat file ကို လွမ္းေခၚျပီး သံုးသြားမွာ ျဖစ္ပါတယ္။ ဒီေနရာမွာ ေျပာဘို႔ လိုလာတာက bat file
ဆိုတာဘာလဲ ? ? ?? အတိုဆံုးနဲ႔ အရွင္းဆုံးေျပာရရင္ Computer OS အတြက္ command တခု သိ႔မ
ု ဟုတ္
တခုထက္ပိုတဲ့ command Series ေတြပါတဲ့ text file တခုျဖစ္ျပီး .bat extension နဲ႔အဆံုး
သတ္ပါတယ္။ဥပမာ Rum ---- > cmd --- > systeminfo လိ႕ု ရို္က္လိုက္ရင္ ကြ်န္ေတာ္ တို႔ computer ရဲ႕
information ေတြ ကို ေတြ႕ရမွာ ျဖစ္ျပီး notepad ထဲမွာ systemifo.exe လိ႕ု ရိုက္ျပီး sys.bat ဆိုျပီး save
ပါ။ ျပီးရင္ double click ေပးလိုက္ရင္ command prompt မွာလိုဘဲ information ေတြ ျမင္ရမွာ ျဖစ္ပါတယ္။
ေနာက္ပိုင္းက် မွ bat programming နဲ႔ C# တြဲတာကို အေသးစိတ္ ေဆြးေႏြးပါဥိးမယ္။ ဒီမွာေတာ့
အျမည္းေလးနဲ႔ဘဲ ေက်နပ္ေပးၾကပါဥိး :D ။ အခု ဒီ command ကို

@echo off

title PC Cleanup Utility http://www.youtube.com/user/techki-tv

:menu

cls

echo --------------------------------------------------------------------------------

echo PC Cleanup Utility

echo --------------------------------------------------------------------------------

echo.

echo Select a tool

echo =============

echo.
echo [1] Delete Internet Cookies

echo [2] Delete Temporary Internet Files

echo [3] Delete Tempfile and Prefetch File

echo [4] Disk Cleanup

echo [5] Disk Defragment

echo [6] Exit

echo.

set /p op=Run:

if %op%==1 goto 1

if %op%==2 goto 2

if %op%==3 goto 3

if %op%==4 goto 4

if %op%==5 goto 5

if %op%==6 goto exit

goto error

:1

cls

echo --------------------------------------------------------------------------------

echo Delete Internet Cookies

echo --------------------------------------------------------------------------------

echo.

echo Deleting Cookies...

ping localhost -n 3 >nul


del /f /q "%userprofile%\Cookies\*.*"

del /q C:\WINDOWS\Temp

del /q C:\WINDOWS\Prefetch

cls

echo --------------------------------------------------------------------------------

echo Delete Internet Cookies

echo --------------------------------------------------------------------------------

echo.

echo Cookies deleted.

echo.

echo Press any key to return to the menu. . .

pause >nul

goto menu

:2

cls

echo --------------------------------------------------------------------------------

echo Delete Temporary Internet Files

echo --------------------------------------------------------------------------------

echo.

echo Deleting Temporary Files...

ping localhost -n 3 >nul

del /f /q "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"

cls
echo --------------------------------------------------------------------------------

echo Delete Temporary Internet Files

echo --------------------------------------------------------------------------------

echo.

echo Temporary Internet Files deleted.

echo.

echo Press any key to return to the menu. . .

pause >nul

goto menu

:3

cls

echo --------------------------------------------------------------------------------

echo Delete Prefetch and Temp file

echo --------------------------------------------------------------------------------

echo.

echo Deleting Temp and prefetch...

ping localhost -n 3 >nul

del /q C:\WINDOWS\Temp

del /q C:\WINDOWS\Prefetch

cls

echo --------------------------------------------------------------------------------

echo Delete Temp and prefetch. files

echo --------------------------------------------------------------------------------
echo.

echo Filesdeleted.

echo.

echo Press any key to return to the menu. . .

pause >nul

goto menu

:4

cls

echo --------------------------------------------------------------------------------

echo Disk Cleanup

echo --------------------------------------------------------------------------------

echo.

echo Running Disk Cleanup...

ping localhost -n 3 >nul

if exist "C:\WINDOWS\temp"del /f /q "C:WINDOWS\temp\*.*"

if exist "C:\WINDOWS\tmp" del /f /q "C:\WINDOWS\tmp\*.*"

if exist "C:\tmp" del /f /q "C:\tmp\*.*"

if exist "C:\temp" del /f /q "C:\temp\*.*"

if exist "%temp%" del /f /q "%temp%\*.*"

if exist "%tmp%" del /f /q "%tmp%\*.*"

if not exist "C:\WINDOWS\Users\*.*" goto skip

if exist "C:\WINDOWS\Users\*.zip" del "C:\WINDOWS\Users\*.zip" /f /q

if exist "C:\WINDOWS\Users\*.exe" del "C:\WINDOWS\Users\*.exe" /f /q


if exist "C:\WINDOWS\Users\*.gif" del "C:\WINDOWS\Users\*.gif" /f /q

if exist "C:\WINDOWS\Users\*.jpg" del "C:\WINDOWS\Users\*.jpg" /f /q

if exist "C:\WINDOWS\Users\*.png" del "C:\WINDOWS\Users\*.png" /f /q

if exist "C:\WINDOWS\Users\*.bmp" del "C:\WINDOWS\Users\*.bmp" /f /q

if exist "C:\WINDOWS\Users\*.avi" del "C:\WINDOWS\Users\*.avi" /f /q

if exist "C:\WINDOWS\Users\*.mpg" del "C:\WINDOWS\Users\*.mpg" /f /q

if exist "C:\WINDOWS\Users\*.mpeg" del "C:\WINDOWS\Users\*.mpeg" /f /q

if exist "C:\WINDOWS\Users\*.ra" del "C:\WINDOWS\Users\*.ra" /f /q

if exist "C:\WINDOWS\Users\*.ram" del "C:\WINDOWS\Users\*.ram"/f /q

if exist "C:\WINDOWS\Users\*.mp3" del "C:\WINDOWS\Users\*.mp3" /f /q

if exist "C:\WINDOWS\Users\*.mov" del "C:\WINDOWS\Users\*.mov" /f /q

if exist "C:\WINDOWS\Users\*.qt" del "C:\WINDOWS\Users\*.qt" /f /q

if exist "C:\WINDOWS\Users\*.asf" del "C:\WINDOWS\Users\*.asf" /f /q

:skip

if not exist C:\WINDOWS\Users\Users\*.* goto skippy /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.zip del C:\WINDOWS\Users\Users\*.zip /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.exe del C:\WINDOWS\Users\Users\*.exe /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.gif del C:\WINDOWS\Users\Users\*.gif /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.jpg del C:\WINDOWS\Users\Users\*.jpg /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.png del C:\WINDOWS\Users\Users\*.png /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.bmp del C:\WINDOWS\Users\Users\*.bmp /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.avi del C:\WINDOWS\Users\Users\*.avi /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.mpg del C:\WINDOWS\Users\Users\*.mpg /f /q


if exist C:\WINDOWS\Users\AppData\Temp\*.mpeg del C:\WINDOWS\Users\Users\*.mpeg /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.ra del C:\WINDOWS\Users\Users\*.ra /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.ram del C:\WINDOWS\Users\Users\*.ram /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.mp3 del C:\WINDOWS\Users\Users\*.mp3 /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.asf del C:\WINDOWS\Users\Users\*.asf /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.qt del C:\WINDOWS\Users\Users\*.qt /f /q

if exist C:\WINDOWS\Users\AppData\Temp\*.mov del C:\WINDOWS\Users\Users\*.mov /f /q

:skippy

if exist "C:\WINDOWS\ff*.tmp" del C:\WINDOWS\ff*.tmp /f /q

if exist C:\WINDOWS\ShellIconCache del /f /q "C:\WINDOWS\ShellI~1\*.*"

cls

echo --------------------------------------------------------------------------------

echo Disk Cleanup

echo --------------------------------------------------------------------------------

echo.

echo Disk Cleanup successful!

echo.

pause

goto menu

:5

cls

echo --------------------------------------------------------------------------------

echo Disk Defragment


echo --------------------------------------------------------------------------------

echo.

echo Defragmenting hard disks...

ping localhost -n 3 >nul

defrag -c -v

cls

echo --------------------------------------------------------------------------------

echo Disk Defragment

echo --------------------------------------------------------------------------------

echo.

echo Disk Defrag successful!

echo.

pause

goto menu

:error

cls

echo Command not recognized.

ping localhost -n 4 >nul

goto menu

:exitကို notepad မွာ copy ကူးျပီး clear.bat ဟု အမည္ေပးျပီး ကြ်န္ေတာ္ တိ႔ု အခု ေရးေနတဲ့ C# program
ရဲ႕ Debug folder (bin ေအာက္မွာ ရွိပါတယ္။) ေအာက္မွာ save ပါ။ ျပီးရင္ Clear Button ကို ႏွိပ္ျပိး ေအာက္ပါ
code ကို ေရးပါ။ ဒီ Bat file program code ကို http://www.instructables.com/id/5-Cool-Batch-Files/step5/PC-
Cleanup-Utility/ ဒီကေန သြားမ လာ ျပီး ကြ်န္ေတာ္ လိုခ်င္တဲ ့code ၂ ေၾကာင္းေလာက္ဘဲထပ္ေပါင္းေရးထားတာပါ။

private void btn_DSK_Click(object sender, EventArgs e)


{
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "clear.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
MessageBox.Show("You computer disk is cleaned by autommatically");
// textBox1.Text = processinfo.ToString();

}
}

အထက္ပါ code ကေတာ့ ကြ်န္ေတာ္ တို႔ save လိုက္တဲ့ bat file ကို C# program ကေန ေခၚသုံးတာ ျဖစ္ပါတယ္။ ကြ်န္ေတာ္
တို႔ အပိုင္းက အစမွာ ေၾကျငာခဲ့တဲ့ using System.Diagnostics; ရဲ႕ Process command သံုးျပီး ေခၚလိုက္တာ
ဘဲျဖစ္ပါတယ္။ အထက္ပါ code နဲ႔ program ျပင္ပက .bat file ေတြကို ေခၚသံုးႏိုင္ပါတယ္။တခု
သတိထားရမွာက အဲဒီ bat file ကို ကြ်န္ေတာ္ တု႔ိ program ရဲ႕ application ရွိတဲ့ folder(debug folder) နဲ႔
တေနရာတည္း ရွိေနရ မွာ ျဖစ္ပါတယ္။

ျပီးရင္ Program ကို Run ျပီး Clear Button ကို ႏွိပ္ပါ။ေအာက္ပါ ပုံမွာ ျပထားတဲ့ command Prompt ထြက္လာပါလိမ့္မယ္။
အဲဒီ ထဲကေနမွ 1 ဆိုတာကို နွိပ္လိုက္ရင္ Internet Cookies ေတြကို ဖ်တ္မွာျဖစ္ပါတယ္။ ကို အသံုးျပဳခ်င္တဲ့ function ေတြကို
(1,2,3,4,5) ဂဏန္းေတြ ႏွိပ္ျပီး command ေပးသြားပါ။
ကြ်န္ေတာ့္ ရဲ႕ PC system tool program ဒုတယ
ိ ပိုင္းကို ဒီမွာ ဘဲ ရပ္နားခြင့္ျပဳပါခင္ဗ်ာ။ အစကေတာ့ Timer
နဲ႔ Alarm function ေတြကိုပါ တခါထဲ ေဆြးေႏြးဘို႔ စီစဥ္ထားတာပါ။ ကြ်န္ေတာ္ ဒီရက္ပိုင္းအေရးၾကီး
စာေမးပြဲေလးတခု ေျဖစရာရွိလို႔ ေနာက္တစ္ပိုင္းခြဲလိုက္ရတာ ျဖစ္ပါတယ္။ အားလံုးဘဲ အဆင္ေျပၾကမယ္လို႔
ေမွ်ာ္လင့္ပါတယ္။

PC System Tool အပိုင္း (၃)


ကြ်န္ေတာ္ ဒီေန႔ PC System tool အပိုင္း(၃) ကို ဆက္လက္ေဆြးေႏြးသြားမွာ ျဖစ္ပါတယ္။ ဒီ အပိုင္းမွာ
computer ကို shutdown Timer နဲ႕ Alarm ေပးတဲ့ Task ၂ ခုကို ပါ၀င္မွာ ျဖစ္ပါတယ္။ Alarm မွာ ကြ်န္ေတာ္
တိ႔ု ေရးထားတဲ့ Text file ကို ဖတ္ခိုင္းျပီး alarm ျမည္ေစ မွာ ျဖစ္တဲ့အတြက္ေအာက္ပါ System ကို သံုးမွာ
ျဖစ္ပါတယ္။

using System.Speech.Synthesis;

ကြ်န္ေတာ္ တို႔ အခု လိုအပ္တဲ့ Tool ေတြ ျပင္ဆင္ၾကရေအာင္။ Tab Control မွာ ေနာက္ထပ္ Tab Page တစ္ခု ထပ္ေပါင္းျပီး
Timer လို႔ အမည္ေပးလို္က္ပါ။ ေပါင္းတဲ့ နည္းကို အပိုင္း(၁) မွာ ေဆြးေႏြးခဲ့ျပီးပါျပီ။ အခု ပံု (၁) မွာ ျပထားတဲ့အတိုင္း tool ေတြ
ေပါင္းလို္က္ပါ။

ပံု-

Time Seconds, Second Left, 0 ေတြက label ေတြေပၚမွာေရးထားတာ ျဖစ္ျပိး box ၂ ခုကေတာ့ text box နဲ႔ combo box
ျဖစ္ပါတယ္။ Start နဲ႔ Stop ကေတာ့ Button ၂ ခု ျဖစ္ပါတယ္။ Timer 1 တခု ယူလိုက္ပါဥိး။ Timer1 properties မွာ Enable---
> true, Interval---- > 1000 ျပင္ပါ။ Text ေတြမွာ ပံုပါ အတိုင္း စာေရးေပးရံုဘဲ ျဖစ္ပါတယ္။ Combo Box ကလြဲရင္ ျပင္စရာ
အေထြအထူး မရွိပါဘူ။ အခု Combox ရဲ႕ Properties----- > Items ----- > Collection မွာ

Shutdown

Restart

Logout

ဆိျု ပီး တစ္ေၾကာင္းခ်င္းစီ သြားေရးေပးပါ။

Form ကို double click ႏွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။

private void Form1_Load(object sender, EventArgs e)


{
timer1.Enabled = false;
}

ျပီးရင္ Start Button ကို ႏွိပ္ျပိး ေအာက္ပါ code ကိေ


ု ရးပါ။

string shutdown;
private void btn_start_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
Process.Start("Shutdown", shutdown + " -t " + textBox1.Text+ @" -c ""Window is Shutting down""");
timer1.Start();
label23.Text = textBox1.Text;

ဒီေနရာမွာ " -t " + textBox1.Text+ @" -c ""Window is Shutting down"""); ဒီအပိုင္းက spacebar error
တတ္တတ္ပါတယ္။ အဲဒီ code အတိုင္းသာ copy ကူးျပီးထည့္ေပးလိုက္ပါ။ ျပိးမွ ကိုယ့္ဘာသာ ကိုယ္ ဘယ္ေနရာမွာ space
ဘယ္ႏွခ်က္ဆိုတာျပန္ေရးၾကည့္ပါ။

ျပီးရင္ Stop Button ကို ႏွိပ္ျပိး ေအာက္ပါ Code ေရးပါ။

private void btn_stop_Click(object sender, EventArgs e)


{
Process.Start("Shutdown", " -a ");
timer1.Stop();
}
ျပီးရင္ Combo box ကို ႏွိပ္ျပိး ေအာက္ပါ code ကို ေရးပါ။

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
switch (comboBox1.SelectedIndex)
{
case 0: shutdown = " -s "; break;
case 1: shutdown = " -t "; break;
case 2: shutdown = " -l "; break;
}
}

ျပီးရင္ timer1 ကို ႏွိပ္ျပီး ေအာက္ပါ code ကိုေရးပါ။ label 23 ေနရာမွာ စာဖတ္သူ ရဲ႕ program က label name ျဖစ္ပါမယ္။

private void timer1_Tick(object sender, EventArgs e)


{
label23.Text = (Convert.ToInt32(label23.Text) - 1).ToString();
}

ျပီးရင္ Run လို္က္ပါ။ ပုံ (၂) အတိုင္း ေတြ႕ရ


႔ ပါလိမ့္မယ္။ time Second ဆိုတ့ဲ Box မွာ ကြ်န္ေတာ္ ၂၀ ရိုက္လိုက္ျပီး start button
ကို ႏွိပ္ပါ။ Combox မွာ Shutdown ကိုေရြးပါ။ စသြားေနပါျပီ ။စကၠန္႕ (၂၀) ျပည့္ရင္ shutdown ဆင္းသြားပါလိမ့္မယ္။
မဆင္းခ်င္ရင္ Stop ကို ႏွိပ္ပါ.။ Logoff is cancel ဆိုျပိး ေအာက္က toolbar မွာ ေဖၚျပေပးပါလိမ့္မယ္။

ပံု-
Shutdown timer function မွာ coding ပိုင္း အ အေထြအထူးရွင္းစရာ မပါပါဘူး။ Computer Run box မွာ
command ေပးျပီး shutdown ေပးဘူးရင္ နားလည္ပါလိမ့္မယ္ ။ CMD မွာ ေအာက္ပါအတိုင္းေပးျပိး Enter
ေခါက္ၾကည့္ပါ။ Shutdown.exe –s –t ”60” စကၠန႔္ (၆) အတြင္း ShutDown
ဆင္းသြားပါလိမ့္မယ္။ စကၠန႔္ (၆၀) ဆိုတဲ့ တန္ဖိုးကို text box ထဲထည့္ျပီး timer နဲ႔
ဖမ္းလို္က္တာပါဘဲ။ အားလံုးဘဲ နားလည္ၾကမယ္လို႔ ထင္ပါတယ္။အခု ကြ်န္ေတာ္ တိ႔ု ဆက္ျပီး Alarm
program ကို ဆက္သြားၾကရေအာင္။

Tab Control ေပၚကို ေထာက္ျပီး Alarm လိ႔ု နာမည္ နဲ႔ Tab page တစ္ခုထပ္Add ပါ။ျပီးရင္ Alarm Tab page
မွာ (ပံ-ု ၃) ပါ အတိုင္း Tool ေတြ တည္ေအာက္ပါ။ဒီေနရာမွာ current time,Alarm time စတဲ့ စာေတြကိုေတာ့
label tool ကိုသုံးျပီး ေရးထားတာ ျဖစ္ပါတယ္။

အားလံုးေပါင္း label(5)ခု၊

TetxtBox (၃) ခု ၊

Button (3) ခု ၊

CheckBox (1)

numericupdown (3)ခု။ Alarm Time ေအာက္က 0,0,0 ဆိုျပီး ေရးထားတာဟာ numericupdown ေတြမွာ
ေရးထားတာပါ။

ျပီးရင္ Ststustrip (1) ခု၊

timer(1) ခု၊ နဲ႔

NotifyIcon (၁) ခု သံုးထားပါတယ္။

ကြ်န္ေတာ္ အခု သံုးထားတဲ့ tool ေတြအားလံုး toolbox မွာ အဲဒီနာမည္ေတြ အတုိင္း ရွိပါတယ္။ ျမန္ျမန္ဆန္ဆန္
ရွာခ်င္ရင္ Toolobx ရဲ႕ Search box မွာ အဲဒီ နာမည္ေတြအတိုင္း ရိုက္ရွာပါ။ေတြ႕ပါတယ္။ျပိးရင္ Name
ေပးၾကပါမယ္။။

Current Time ရဲ႕ေအာက္မွာ ရွိတဲ့ textbox ကို Properties----- >Name--- > timeBox

Message Box ေဘးက TextBox ကို textBox

Speech ေဘးက TextBox ကို speakBoxဟု အမည္ေပးပါ။ စာလံုးအၾကိးအေသးက အစမွားလို႔မရပါဘူး။ C#


က Case Sensitive ျဖစ္တယ္ဆိုတာ သီအိုရီပိုင္း မွာ variable ခန္းမွာ ေဆြးေႏြးခဲ့ျပီးျဖစ္ပါတယ္။
ျပီးရင္ NumericUpdown ေတြမွာ ဘယ္စြန္ hoursChoice, အလယ္ minutesChoice , ညာစြန္
secondsChoice ဟု ေပးပါ။

Statustrip မွာ statuslabel တခုယူျပီး AlarmStatus ဟုအမည္ေပးပါ။

NotifyIcon ကို trayicon ဟု အမည္ေပးျပီး Icon box မွာ ၾကိဳက္ႏွစ္သက္ရာ icon တခု ထားပါ။ ဒီေနရာမွာ
file ကေတာ့ .ico နဲ႔ ဆံုးတဲ့ icon file တခု ျဖစ္ရပါမယ္။အဲဒီ icon ပံုက program ကို tray လုပ္တဲ့အခါ toolbar
မွာ သြားေပၚမွာပါ။

Timer(2) ကို name--- timer

Enable--- true

Interval--- 1000 ဟုေပးပါ။

ပံု-၃

ျပီးရင္ Function တခု ေရးပါမယ္။ မေရးခင္မွာ လိုအပ္တဲ့ variable ေတြ ေၾကျငာရပါ့မယ္။


Public partial class Form1:Form ဆိုတဲ့ ေအာက္မွာ ဒီအတိုင္းေရးပါ။(Form1 ေနရာမွာ
စာဖတ္သူ ေပးထားတဲ့ နာမည္ ျဖစ္မယ္။)

public partial class Form1 : Form


{
public DateTime alarmTime = Properties.Settings.Default.alarmTime;
public SpeechSynthesizer s = new SpeechSynthesizer();
public bool isActive = false;

public Form1()
{
InitializeComponent();
hoursChoice.Value = alarmTime.Hour;
minutesChoice.Value = alarmTime.Minute;
secondsChoice.Value = alarmTime.Second;
textBox.Text = Properties.Settings.Default.textBoxText;
speakBox.Text = Properties.Settings.Default.speakText;

ေအာက္ပါ code ကေတာ့ ကြန္ပ်ဴတာ ရဲ႕ လက္ရိွ current time နဲ႔ numeric up down မွာ ေပးလိုက္တ့ဲ number ေတြကို alarm
time အတြက္ ယူေစရန္ ေအာက္ပါ activateAlarm() function ကိုေရးပါတယ္။ Tool ေအာက္မွာေရးတာမဟုတ္ပါဘူး။ Function
class ေရးတယ္လို႔ေခၚပါတယ္။ အဲဒီ Function ကိုက်ြ န္ေတာ္ တုိ႔ ဒီ program ရဲ႕ Assembly တူေသာ (class တခုအတြင္း )
ၾကိဳက္တ့ေ
ဲ နရာကေန ေခၚသုံးလို႔ရပါတယ္။ ယခု လိုအပ္တဲ့ Function (၃) ခုကို ေရးမွာ ျဖစ္ပါတယ္။

/// Function မ်ားေရးသားျခင္း

/// (၁) Activate Function

private void activateAlarm()


{
DateTime dt = DateTime.Now;
alarmTime = new DateTime(dt.Year, dt.Month, dt.Day,
(int)hoursChoice.Value, (int)minutesChoice.Value, (int)secondsChoice.Value);
AlarmStatus.Text = "Alarm set for " + alarmTime.ToString("HH:mm:ss");
isActive = true;
trayIcon.Visible = true;
trayIcon.ShowBalloonTip(5, "Alarm Active",
"An alarm is set for " + alarmTime.ToString("HH:mm:ss") + ".",
ToolTipIcon.Info);
}

// -------------------------------------------------------------------------------
/// Speaker Function

private void s_SpeakCompleted(object sender, SpeakCompletedEventArgs e)


{
if (isActive)
{
s.SpeakAsync(speakBox.Text);
}
}

// -------------------------------------------------------------------------------
/// Deactivate မ်ားေရးသားျခင္း

private void Deactive()


{
isActive = false;
s.SpeakAsyncCancelAll();
trayIcon.Visible = false;
AlarmStatus.Text = "Alarm not active.";
}

// -------------------------------------------------------------------------------

ျပီးရင္ Active Button ဆိုတာကို ႏွိပ္ျပီး ေအာက္ပါ code ကိုေရးပါ။

private void button2_Click(object sender, EventArgs e)


{
activateAlarm();
}

ကြ်န္ေတာ္ တို႔ အေပၚမွာ ေရးထားတဲ့ activateAlarm ဆိုတ့ဲ function ကို ဒီ button ကေန ေခၚသံုးလို္က္တာဘဲ ျဖစ္ပါတယ္။ အဲဒီ
နည္းကို မွတ္ထားေပးပါ။ ေနာက္ပိုင္းမွာ function က ေရးျပီး အခုလိုေခၚသံုးတာ အမ်ားၾကီး ေတြ႕ရပါလိမ့္မယ္။ျ

Timer ကိႏ
ု ိွပ္ပါ။ Shutdown တုန္းက Timer နဲ႔ မွားႏိုင္ပါတယ္။ ယခု Alarm အတြက္ ယူထားတဲ့ Timer ကို ႏွိပ္ျပီး ေအာက္ပါ
code ကိုေရးပါ။
private void timer_Tick(object sender, EventArgs e)
{
timeBox.Text = DateTime.Now.ToString("HH:mm:ss");
if (isActive && timeBox.Text.Equals(alarmTime.ToString("HH:mm:ss")))
{
if (speakCheck.Checked)
{
s.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(s_SpeakCompleted);
s.SpeakAsync(speakBox.Text);
}
if (MessageBox.Show(textBox.Text, "Alarm", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Deactive();
}
}
}

ဒီ code ရဲ႕ လုပ္ေဆာင္ပံု ကို နဲနဲရွင္းပါ့မယ္


timeBox.Text = DateTime.Now.ToString("HH:mm:ss");
code က TextBox မွာ ကြန္ပ်ဴတာ ရဲ႕ current tume ကို ျပေစမွာ ျဖစ္ျပီး

if (isActive && timeBox.Text.Equals(alarmTime.ToString("HH:mm:ss")))

TetxtBox မွာ ျပတဲ့ current time နဲ႔ numeric up down မွာ ေပးလို္က္တ့ဲ time တူမတူကိုေတာ့ အထက္ပါ if statement နဲ႕
စစ္ပါတယ္။
SpeakBox မွာ check လုပ္မလုပ္ကိုေတာ့
if (speakCheck.Checked)
{
s.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(s_SpeakCompleted);
s.SpeakAsync(speakBox.Text);
}
အထက္ပါ code နဲ႔ စစ္ျပိး စစ္ခ့ဲရင္ အဲဒီ text box မွာ ေရးထားတဲ့ စာကို ဖတ္ခို္င္းေစမွာ ျဖစ္ပါတယ္။
အထက္ပါ code မွာ (s_SpeakCompleted); ဆိတ
ု ာ textbox မွာ ေရးထားတဲ့ စာကို ဖတ္ခိုင္းတဲ့ function တခုဘဲ ျဖစ္ပါတယ္။
အဲဒိ Function အတြက္ အေပၚက speaker function ဆိုျပီးေရးျပီးခဲ့ျပီးျဖစ္ပါတယ္။

အလားတူဘဲ MessageBox မွာ ေရးထားတဲ့ စာကိုေတာ့ Alarm time ေရာက္တ့ဲအခါမွာ ေအာက္ပါ code နဲ႔ ျပေစျပီးေတာ့
messagebox ကို ok ေပးလိုက္ရင္ Deactive function ကို လုပ္ပါမယ္လို႔ command ေပးထားတာျဖစ္ပါတယ္။

if (MessageBox.Show(textBox.Text, "Alarm", MessageBoxButtons.OK,


MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Deactive();
}

ျပီးရင္ deactive button ကို နွိပ္ျပိး ေအာက္ပါ code ကိုေရးပါ။အထက္က အတိုင္းဘဲ Deactive function ကို ေခၚသံုးလိုက္တာဘဲ
ျဖစ္ပါတယ္။

private void dec_btn_Click(object sender, EventArgs e)

{
Deactive();
}
ျပီးရင္ Access and Sent to Tray ကို ႏွိပ္ျပီး ေအာက္ပါ code ကိုေရးပါ။
private void button3_Click(object sender, EventArgs e)
{
activateAlarm();
this.Hide();
}
ဒီေနရာမွာလည္း activateAlarm function အတိုင္း အလုပ္လုပ္ေစမွာျဖစ္ျပီး Form ကို ေအာက္ေျခ toolbar မွာ tray icon အျဖစ္
သြားေပၚေစတာျဖစ္ပါတယ္။

ျပီးရင္ trayicon clik မွာ ေအာက္ပါ code ကိုေရးပါ။ double click မဟုတ္ပါဘူး။ click ပါ။

private void trayIcon_Click(object sender, EventArgs e)


{
this.Show();
}

ျပီးရင္ Hourchoice click မွာ ေအာက္ပါ code ေရးပါ။

private void hoursChoice_Click(object sender, EventArgs e)


{
NumericUpDown nud = (NumericUpDown)sender;
nud.Select(0, 2);
}
Numericupdown မွာ ရို္က္လိုက္တ့ဲ စာလံုးမွန္သမွ်ကို ၂ လံုးအျဖစ္ ျဖတ္တာ ပါ။ ၃ လံးု ရို္က္ရင္ အလုပ္မလုပ္ပါဘူး။
အခုဆို ကြ်န္ေတာ္တု႔ရ
ိ ဲ႕ alarm program ျပိးပါျပီး Run လိက
ု ပ
္ ါ။ ပံု (၄) အတိုင္း ျပပါလိမ့္မယ္။ အဲဒီမွာ ၾကည့္ပါ။ ကြ်န္ေတာ့္
Alarm ကို 01:51:10 လို႕ေပးထားပါတယ္။ ကြန္ပ်ဴတာရဲ႕ Current time---- 01:51:10 ေရာက္တ့ဲအခ်ိန္မွာ Message Box မွာ
ေရးထားတဲ့ Alarm ဆိုတ့ဲ message Box ေပၚလာျပိး Speech Box မွာ ေရးထားတဲ့ Wake Up Time ဆိုျပီး အမ်ိဴးသမီး
အသံနဲ႔ထေအာ္ေနပါတယ္။ ပုံထမ
ဲ ွာေတာ့ အသံမျမည္ဘူးဆိုျပီးေတာ့ေတာ့ မျငင္းရဘူးေနာ္  ။ စာဖတ္သူ ရဲ႕ စက္မွာ ကိုယ္တိုင္
စမ္းၾကည့္ပါ။ textbox မွာ ေရးထားတဲ့အတိုင္း ေအာ္ေနပါလိမ့္မယ္။ အဂၤလိပ္လိုဘဲ ေရးရမွာေနာ္။ ကြ်န္ေတာ္ တို႔ကုိ ႏိူးမဲ့
အမ်ိဴးသမိးက အဂၤလိပ္လူမ်ိဴးဗ် :P ။ အဲဒီမွာ Activate and Send Tray button ကို ႏွိပ္လိုက္ရင္ ကြ်န္ေတာ္တုိ႔ရဲ႕ program
ၾကီးက ကြန္ပ်ဴတာ ရဲ႕ ညာဘက္ေအာက္မွာ tray icon အျဖစ္သာြ းေပၚမွာပါ။ icon ေလးေတာ့ ထည့္ထားဘို႔လိုတာေပါ့ေနာ္။

ပုံ-၄

နိဂံုး

ကြ်န္ေတာ္ ရဲ႕ PC system tool သင္ခန္းစာ ဒီမွာတင္ ဆံုးခန္း တိုင္ပါျပိ။ ဒီသင္ခန္းရဲ႕ ပထမ အပိုင္းမွာ
computer ရဲ႕ system control ပိုင္းေတြ ျဖစ္တဲ့
(1) taskmanager
(2) Registry
(3) CMD
(4) Run Box
(5) Control Panel
တိ႔ိက
ု ို enable ,disable လုပ္တာ ကိုေဆြးေႏြးထားပါတယ္။ virus ကို္က္လို႔ျဖစ္ျဖစ္၊
ကိုယ့္ဟာကို ကလိလို္က္လ႔ဘ
ို ဲ ျဖစ္ျဖစ္ အေၾကာင္း အမ်ဴိးမ်ိဴးေၾကာင့္ အထက္ပါ system
control ေတြ ေပ်ာက္သြားရင္ ဒီ program နဲ႔ ျပန္ေဖၚႏိုင္မွာ ျဖစ္ပါတယ္။

ဒုတိယ အပိုင္းမွာေတာ့ ကြန္ပ်ဴတာ ရဲ႕ system information နဲ႔


(1) internet cookies clear
(2) Temp and prefetch clear
(3) Internet tempfile clear
(4) Disk Defragment
(5) DiskClean Up
တိ႔က
ု ို batch file မွာ ေရးျပီး အဲဒီ bat program ကို C# ကေန
လွမ္းေခၚသံုးတဲ့အေၾကာင္းကိုေဆြးေႏြးထားပါတယ္။

တတိယ အပိုင္းမွာေတာ့ Shutdown timer နဲ႔ Alarm clock အေၾကာင္း ကိုေဆြးေႏြးေပးထားပါတယ္။ အမွန္က
အဲဒီ Function (၂) ခုကို တခုထဲေပါင္းေရးလိ႔ုရပါတယ္။ စာဖတ္သူအေနနဲ႔ စမ္းၾကည့္ေစခ်င္ပါတယ္။ အႏွစ္ခ်ဴပ္
အေနနဲ႔ ေျပာရရင္ ဒီ program မွာ မတူကြဲျပားျခားနဲ႔ function ေတြ အမ်ားၾကီးကိုေပါင္းျပိး
ေရးထားတာျဖစ္ပါတယ္။ စာဖတ္သူအေနန႔ဲ႔ အဲဒီ function ေတြထဲက code ေတြရဲ႕
အလုပ္လုပ္ပံုကိုနားမလည္မယ္ဆိုရင္ ကိုယ္ လိုအပ္တဲ့ ေနရာ ကေန ဆြဲသံုးလိ႔ုရပါတယ္။ သူမ်ား ေရးထားတဲ့
code ေတြကို နားလည္ေအာင္ ဘယ္လိုေလ့လာမလဲဆိုတဲ့ ေခါင္းစဥ္ နဲ႕ trace လိုက္ျခင္းသင္ခန္းစာကို
ေနာက္အပိုင္းေတြမွာ ကြ်န္ေတာ္ ေဆြးေႏြးေပးပါမယ္။ အားလံုးဘဲ အဆင္ေျပၾကပါေစလို႔ ေမွ်ာ္လင့္ပါတယ္။ဒီ
program နဲ႔ ပက္သက္ျပီး တစံုတရာ နားမလည္တာရွိရင္ message ပိ႔၍
ု ေသာ္ လည္းေကာင္း၊ comment box
ကေန ေသာ္လည္းေကာင္းေမးႏိုင္ပါတယ္။
ေအာက္မွာ program တစ္ခုလံုးရဲ႕ code အျပည့္အစံုေပးလို္က္ပါတယ္။

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;
using Microsoft.Win32;
using System.Diagnostics;
using System.Speech.Synthesis;

namespace Taskmanager
{
public partial class Form1 : Form
{
public DateTime alarmTime = Properties.Settings.Default.alarmTime;
public SpeechSynthesizer s = new SpeechSynthesizer();
public bool isActive = false;

public Form1()
{
InitializeComponent();
hoursChoice.Value = alarmTime.Hour;
minutesChoice.Value = alarmTime.Minute;
secondsChoice.Value = alarmTime.Second;
textBox.Text = Properties.Settings.Default.textBoxText;
speakBox.Text = Properties.Settings.Default.speakText;

private void Form1_Load(object sender, EventArgs e)


{
timer1.Enabled = false;
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)


{
if (checkBox1.Checked == false)
{
RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;
RegistryKey key =
HKCU.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
key.SetValue("DisableTaskMgr", 1, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
MessageBox.Show("TaskManager is Disable");
}

else
{
Microsoft.Win32.RegistryKey HKCU = Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey key =
HKCU.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
key.SetValue("DisableTaskMgr", 0, Microsoft.Win32.RegistryValueKind.DWord);
key.Close();
MessageBox.Show("TaskManager is Enable");
}
}

private void checkBox2_CheckedChanged(object sender, EventArgs e)


{
if (checkBox2.Checked == false)
{
RegistryKey
SystemRegistry=Registry.CurrentUser.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policie
s\\System");
SystemRegistry.SetValue("DisableRegistryTools",1);
SystemRegistry.Close();
MessageBox.Show("Registry Disable");
}
else
{
RegistryKey SystemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
SystemRegistry.SetValue("DisableRegistryTools", 0);
SystemRegistry.Close();
MessageBox.Show("Registry Enable");
}
}

private void checkBox3_CheckedChanged(object sender, EventArgs e)


{
if (checkBox3.Checked == false)
{
RegistryKey systemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
systemRegistry.SetValue("DisableCMD", 1);
systemRegistry.Close();
MessageBox.Show("Command Prompt is Disable");
}
else
{
{
RegistryKey systemRegistry =
Registry.CurrentUser.CreateSubKey(@"Software\Policies\Microsoft\Windows\System");
systemRegistry.SetValue("DisableCMD", 0);
systemRegistry.Close();
MessageBox.Show("Command Prompt is Enable");
}
}
}

private void checkBox4_CheckedChanged(object sender, EventArgs e)


{
if (checkBox4.Checked == false)
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoRun", 1);
systemRegedit.Close();
MessageBox.Show("Don't Allow Run Box");
}
else
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoRun", 0);
systemRegedit.Close();
MessageBox.Show("Run Box is enable");
}
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
if (checkBox5.Checked == false)
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoControlPanel", 1);
systemRegedit.Close();
MessageBox.Show("Control Panel is disable");
}
else
{
RegistryKey systemRegedit =
Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer");
systemRegedit.SetValue("NoControlPanel", 0);
systemRegedit.Close();
MessageBox.Show("Control Panel Box is enable");
}
}

private void button1_Click(object sender, EventArgs e)


{
try
{
label18.Text = SystemInformation.PrimaryMonitorSize.ToString();
label2.Text = System.Environment.SystemDirectory;
label4.Text = System.Environment.MachineName;
label6.Text = System.Environment.WorkingSet.ToString();
int q = System.Environment.TickCount;
int w = (q / 1000) / 60;
label8.Text = w.ToString() + " Minute(s)";
label10.Text = System.Environment.OSVersion.ToString();
label12.Text = System.Environment.Version.ToString();
label14.Text = System.Environment.UserName;
label16.Text = System.Environment.UserDomainName;
RegistryKey Rkey = Registry.LocalMachine;
Rkey = Rkey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
label20.Text = (string)Rkey.GetValue("ProcessorNameString");
}
catch (Exception EX)
{
MessageBox.Show("The Following ERROR Occur ..." + EX.Message.ToString());
}
}

private void tabPage2_Click(object sender, EventArgs e)


{

}
string shutdown;
private void btn_start_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
Process.Start("Shutdown", shutdown + " -t " + textBox1.Text+ @" -c ""Window is Shutting down""");
timer1.Start();
label23.Text = textBox1.Text;

private void btn_stop_Click(object sender, EventArgs e)


{
Process.Start("Shutdown", " -a ");
timer1.Stop();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)


{
switch (comboBox1.SelectedIndex)
{
case 0: shutdown = " -s "; break;
case 1: shutdown = " -t "; break;
case 2: shutdown = " -l "; break;
}
}

private void timer1_Tick(object sender, EventArgs e)


{
label23.Text = (Convert.ToInt32(label23.Text) - 1).ToString();
}

private void tabPage1_Click(object sender, EventArgs e)


{

private void tabPage4_Click(object sender, EventArgs e)


{

private void btn_DSK_Click(object sender, EventArgs e)


{
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "clear.bat";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.UseShellExecute = false;
proc.Start();
proc.WaitForExit();
MessageBox.Show("You computer disk is cleaned by autommatically");
// textBox1.Text = processinfo.ToString();

}
}

private void tabPage3_Enter(object sender, EventArgs e)


{

}
/// <summary>
/// Alarm ေရးသားျခင္း
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// //--------------------------------------------------------
/// Function မ်ားေရးသားျခင္း
private void activateAlarm()
{
DateTime dt = DateTime.Now;
alarmTime = new DateTime(dt.Year, dt.Month, dt.Day,
(int)hoursChoice.Value, (int)minutesChoice.Value, (int)secondsChoice.Value);
AlarmStatus.Text = "Alarm set for " + alarmTime.ToString("HH:mm:ss");
isActive = true;
trayIcon.Visible = true;
trayIcon.ShowBalloonTip(5, "Alarm Active",
"An alarm is set for " + alarmTime.ToString("HH:mm:ss") + ".",
ToolTipIcon.Info);
}

// -------------------------------------------------------------------------------
private void s_SpeakCompleted(object sender, SpeakCompletedEventArgs e)
{
if (isActive)
{
s.SpeakAsync(speakBox.Text);
}
}

// -------------------------------------------------------------------------------
private void Deactive()
{
isActive = false;
s.SpeakAsyncCancelAll();
trayIcon.Visible = false;
AlarmStatus.Text = "Alarm not active.";
}

// -------------------------------------------------------------------------------
private void button2_Click(object sender, EventArgs e)
{
activateAlarm();
}

private void timer_Tick(object sender, EventArgs e)


{
timeBox.Text = DateTime.Now.ToString("HH:mm:ss");
if (isActive && timeBox.Text.Equals(alarmTime.ToString("HH:mm:ss")))
{
if (speakCheck.Checked)
{
s.SpeakCompleted += new EventHandler<SpeakCompletedEventArgs>(s_SpeakCompleted);
s.SpeakAsync(speakBox.Text);
}
if (MessageBox.Show(textBox.Text, "Alarm", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Deactive();
}
}
}
private void dec_btn_Click(object sender, EventArgs e)

{
Deactive();
}

private void hoursChoice_Click(object sender, EventArgs e)


{
NumericUpDown nud = (NumericUpDown)sender;
nud.Select(0, 2);
}

private void button3_Click(object sender, EventArgs e)


{
activateAlarm();
this.Hide();
}
private void trayIcon_Click(object sender, EventArgs e)
{
this.Show();
}

}
}

အထက္ပါ သင္ခန္စားမ်ား မွာ https://www.facebook.com/pages/C-and-C-plus-plus-programming-


language-for-beginner/771934899529239 FB Page တြင္ ေဆြးေႏြးထားျပီးခဲ့ေသာ သင္ခန္းစာမ်ားျဖစ္ပါသည္။
ေနာက္ဆက္တြဲ သင္ခန္းစာမ်ားကို ဆက္လက္ေလ့လာလိုက ၎ စာမ်က္ႏွာတြင္ သြားေရာက္ေလ့လာႏိုင္ပါသည္။

You might also like