1
1
Ch ng 3: ươ
M t s k thu t
trong l p trình trên .Net CF
ThS. Tr n Minh Tri t ế
Đ i h c Khoa h c T nhiên, ĐHQG-HCM
Khoa Công Ngh Thông Tin
2
2
Xác đ nh đ ng d n c a ng d ng ườ
Xác đ nh t đ ng đ ng d n c a ng d ng (runtime) ườ
m_startuppath =
System.Reflection.Assembly.GetExecutingAssembly().
GetModules()[0].FullyQualifiedName;
m_startuppath = m_startuppath.Replace(
System.Reflection.Assembly.GetExecutingAssembly().
GetModules()[0].Name, "" );
m_BmBanCo =new Bitmap
(m_startuppath+"BanCoPocketPC.jpg");
m_BmQuanCo=new Bitmap
(m_startuppath+"QuanCoPocKetPC.bmp");
m_BmChonCo=new Bitmap
(m_startuppath+"ChonQuanPocketPC.bmp");
L y danh
sách các
Assembly
Xóa tên file,
ch gi l i
đ ng d nườ
Tr n v n tên
đ ng d n c a ườ
module
Tên c a module
3
3
Xác đ nh đ ng d n c a ng d ng ườ
S d ng đ ng d n tuy t đ i (hard-code)!!! ườ
Ph i bi t tr c đ ng d n (tuy t đ i) s ch a ch ng ế ướ ườ ươ
trình th c thi
public class Constant
{
public static int LEFT = 24;
public static int TOP = 24;
public static string AppPath
= @"\Program Files\MummyMaze\";
public static string ImagesPath
= @"\Program Files\MummyMaze\";
}
4
4
Load nh t file
Có th load các nh t file vào đ i t ng ki u ượ Bitmap
Các đ nh d ng nh thông d ng mà WinCE h tr (BMP,
JPG, PNG…)
Bitmap RedMummyBmp =
new Bitmap(Constant.ImagesPath+"redmummy.bmp");
Bitmap HelloBmp =
new Bitmap(Constant.ImagesPath+"hello.jpg");
5
5
S d ng Timer (1)
Khai báo bi n thu c ki u ế
System.Windows.Forms.Timer
Kh i t o bi n Timer ế
private System.Windows.Forms.Timer MyTimer;
private void InitializeComponent()
{
this.MyTimer = new System.Windows.Forms.Timer();
this.MyTimer.Interval = 300; // 300 ms
this.MyTimer.Tick +=
new System.EventHandler(this.MyTimer_Func);
}Tên hàm
x
Timer