User Control ကို ခြုံငုံကြည့်ခြင်း
Microsoft® .NET controls (build-in ပါလာတဲ့ .Net controls) တွေ အားလုံးဟာ UserControl လို့ခေါ်တဲ့ base class ရဲ့ လက်အောက်မှာ (inherit) ရှိကြပါတယ်.. အဲဒီ base class တွေမှာ Window Form control တွေ ဖန်တီးတဲ့ function တွေပါ၀င်ပါတယ် . Usercontrol class လက်အောက်ကို ရောက်တာနဲ့ အဲဒီ properties and events တွေ အားလုံးကို သုံးလို့ ရပီ ဖြစ်ပါတယ်.
Properties များကို ယူသုံးခြင်း
ဒီမှာ UserControl base class အောက်မှာ အခု ၃၀ လောက်ရှိတဲ့ properties တွေ ရှိပါတယ်. ဥပမာ .. backcolor, forecolor, anchoring and docking.. အဲဒါတွေ အားလုံးကို override လုပ်ပီး ကိုယ့်စိတ်ကြိုက်ပြင်ပေးနိုင်ပါတယ်. ဒါမှ မဟုတ်လဲ Default အတိုင်းထားပီးလည်း သုံးနိုင်ပါတယ်.
Events များကို ယူသုံးခြင်း
ဒီမှာလည်း အခု ၄၀ လောက် ရှိတဲ့ Events တွေ အားလုံးကို inherits လုပ်နိုင်ပါတယ်. ဥပမာ .. Load, Resize, Textchanged စတာတွေ အပြင် mouse event တွေ ဖြစ်တဲ့ Click, DoubleClick, MouseUp and MouseDown.. ဒါတွေကိုလည်း On
ကိုယ်ပိုင် Control အသုံးပြုခြင်း vs. Microsoft build-in Control အသုံးပြုခြင်း
Microsoft ကနေပြီး build-in လုပ်ပေးထားတဲ့ Control ပေါင်းများစွာ ရှိပါတယ် .. ထပ်လည်း ဖြည့်ပေးနေတုန်းပါပဲ .. ဒါပေမယ့် တခါတလေမှာ အဲဒီ Toolbox ထဲမှာ မပါတဲ့ Control မျိုးသုံးချင်တဲ့ အခါတွေ ၊နောက်ပီး တခါတရံမှာ Special Control တစ်ခုကို ထပ်ခါတလဲလဲ သုံးချင်တဲ့ အခါတွေ ရှိလာတတ်ပါတယ်. အဲဒီအခါမှာ ဒီ UserControl ကို သုံးလာရတာပါပဲ .. UserControl ကို နေရာ အမျိုးမျိုးတွေ မှာ သုံးလာကြပါပီ. UserControl ကို dll file တောင် ရောင်းနေတဲ့ ခေတ်ကို ရောက်နေပါပြီ.. အောက်တွင် UserControl ကို အသုံးပြုပုံကို ရှင်းပြသွားပါမယ် .. အလွယ်ဆုံး ဥပမာကနေ စရအောင် ..
ပထမဦးဆုံး ClassLibrary project ကနေ စပါမယ်..
ပြီးရင် အဲဒီမှာပါလာတဲ့ class1.cs ကို ဖျက်ပီး Add => User Control လုပ်ပါမယ်..
နာမည် ပြောင်းပါမယ် ..
အဲဒီ form ပေါ်မှာ label ၂ ခုထည့်ပါမယ်..
form ကို double-click ပြီး Datetime ဖော်ပြမယ့် code ဖြည့်ပါမယ်..
ပြီးရင် နောက် WindowForm တစ်ခုဆောက်ပြီး အဲဒီ User Control ကို သုံးကြည့်ပါမယ်.. အရင်ဆုံး အဲဒီ dll file ကို Reference Add ပေးပါ..
ပြီးရင် ဘေးဘက် Toolbox မှာပေါ်နေတဲ့ myusercontrol ကို ယူပြီး form ပေါ်ကို တင်လိုက်ပါမယ်..
ဒါဆိုရင်တော့ auto datetime ဖော်ပြတဲ့ label ပါ၀င်တဲ့ User Control ပြီးပါပြီ..
http://msdn.microsoft.com/en-us/library/aa302342.aspx ကို ဘာသာပြန်ပြီး ရေးပါသည်.
Creating a Windows Form User Control
Tuesday, December 28, 2010
min that thant
Posted in
C#
Subscribe to:
Post Comments (Atom)

No Response to "Creating a Windows Form User Control"
Post a Comment