Creating a Windows Form User Control

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 ဆိုတာနဲ့ override လုပ်ပီး သုံးနိုင်ပါတယ် ..
ကိုယ်ပိုင် 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 ကို ဘာသာပြန်ပြီး ရေးပါသည်.

Windows Forms User Settings in C#

http://www.codeproject.com/KB/cs/UserSettings.aspx

Making UserControl Topmost (WinForm)

စိတ်ပေါက်ပေါက်နဲ့ Usercontrol တစ်ခုလုပ်ပါတယ်..။ Project မှာ Number ကို Textbox ထဲရိုက်ထည့်နေရတာထက် အခုလို mouse နဲ့ပဲ နှိပ်မလားလို့ စဉ်းစားမိလို့ပါ...။ ဒါဆိုရင် နောက် Touchscreen တွေအတွက်လည်း အဆင်ပြေပါတယ်..။ ကုန်ပစ္စည်းကုတ်တွေကို လက်နဲ့ နှိပ်ပြီး ဖြည့်ရုံပါပဲ..။ Usercontrol လုပ်ပြီးသွားတဲ့အခါ သူ့မှာ Windowform လို Topmost property ပါမလာပါဘူး ..။ သူက တခြားစာသားကို ဖုံးနေပါတယ်...။ အဲဒါရှာကြည့်လိုက်တော့ အောက်ပါအတိုင်း Usercontrol မှာ SendToBack() နဲ့ BringToFront() ကို ထည့်သုံးသွား ရုံပါပဲ...။ Now all ok..!


HERE source code of my UserControl

powered by Blogger