Notify icon ကို system tray မှာ ပေါ်ဖို့ အတွက် VB2005 မှာရေးရတာ VB6 ထက် အများကြီးပိုလွယ်ပါတယ်။ VB2005 မှာ Windows Application တစ်ခုကို ဖန်တီးပါ။ ထို့နောက် အောက်ပါပုံတွင် ပြထားသည့် အတိုင်း NotifyIcon control ကို ထည့်ပါ။
"NotifyIcon1" control ကို Select မှတ်ပါ။ ထို့နောက် သူ့ရဲ့ properties window မှာ "Icon" ကိုရွေးပြီး သင်သုံးချင်တဲ့ icon ကို သတ်မှတ်ပါ။ ဘာ icon မှ သတ်မှတ်မပေးခဲ့ရင် notify icon ကို system tray မှာ မြင်ရမှာ မဟုတ်ပါဘူး။
သင့် application ကို ပိတ်တဲ့ အခါ notify icon ကို ပေါ်စေဖို့ အတွက် အောက်ပါ code များကို FormClosing event တွင်ရေးပါ။
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Do you really want to exit?", "Exit", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
e.Cancel = True
Me.Visible = False
NotifyIcon1.Visible = True
End If
End Sub
Notify Icon ကို double click နှိပ်လိုက်ရင် application ကို ပြန်ပေါ်လာစေဖို့ အောက်ပါ code များကို NotifyIcon1 ၏ MouseDoubleClick event တွင်ရေးပါ။
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
Me.Visible = True ' Show the form.
Me.Activate() ' Activate the form.
NotifyIcon1.Visible = False
End Sub
File menu နဲ့ context menu တွေကနေ application ပိတ်လို့ရစေဖို့ အောက်ပါ controls များကိုထည့်ပါ။
ထို့နောက် 'Me.Close()' ကို သူတို့ရဲ့ click event မှာဖြည့်ပါ။
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
' Close the form, which closes the application.
Me.Close()
End Sub
Private Sub ContextMenuStrip1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenuStrip1.Click
Me.Close()
End Sub
Notify Icon ပေါ်မှာ right click နှိပ်တဲ့အခါ pop up menu ပေါ်စေဖို့ NotifyIcon1 control ကို Select မှတ်ပြီး သူ့ရဲ့ ContestMenuStrip property မှာ ContextMenuStrip1 ကိုသတ်မှတ်ပေးပါ။
ပြီးရင် သင့် program ကို run နိုင်ပါပြီ။ ဝင်းဒိုး ကို ပိတ်လိုက်ရင် တစ်ကယ် ထွက်မထွက် မေးဖို့ message box တစ်ခုပေါ်လာမှာ ဖြစ်ပြီး "No" ကိုရွေးရင် system tray ထဲမှာ ကျန်နေပါလိမ့်မယ်။ Notify Icon ကို double click ပြန်နှိပ်ရင် application ပြန်ပေါ်လာမှာဖြစ်ပါတယ်။
No comments:
Post a Comment