先创建一个隐藏的菜单,假定名为popmenu,并添加两个菜单项:退出、联系作者
然后在公共模块添加以下代码:
Public Declare Function Shell_NotifyIcon Lib "shell32dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As LongPublic Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String 64
End Type
Public tp As NOTIFYICONDATA
最后在窗体添加以下代码:
Private Sub Form_Load()tphWnd = MehWnd
tpuID = MeIcon
tpuFlags = 7
tpuCallbackMessage = &H200
tphIcon = MeIconHandle
tpszTip = "左键显示界面,右键d出菜单" & vbNullChar
tpcbSize = Len(tp)
Shell_NotifyIcon &H0, tp
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case X / ScreenTwipsPerPixelX
Case &H201
If MeWindowState = 1 Then MeWindowState = 0
Case &H204
MePopupMenu popmenu
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon &H2, tp
End Sub
声明多个NotifyIcon实例不就行了?
通知区域中的图标是一些进程的快捷方式,这些进程在计算机后台运行,如防病毒程序或音量控制。这些进程不会具有自己的用户界面。NotifyIcon 类提供了编写此功能的方法。 Icon 属性定义显示在通知区域中的图标。 图标的d出菜单由 ContextMenu 属性确定。 Text 属性分配工具提示文本。 要在通知区域中显示图标,必须将 Visible 属性设置为 true。
示例下面的代码示例演示如何使用 NotifyIcon 类在通知区域中显示某一应用程序的图标。 该示例演示如何设置 Icon、 ContextMenu、 Text 和 Visible 属性以及如何处理 DoubleClick 事件。 一个带有 “退出”项的 ContextMenu 被分配给 NotifyIcon ::ContextMenu 属性,使用户可以关闭应用程序。 当发生 DoubleClick 事件时,将通过调用 Form ::Activate 方法来激活该应用程序窗体。
using System;
using SystemDrawing;
using SystemWindowsForms;
public class Form1 : SystemWindowsFormsForm
{
private SystemWindowsFormsNotifyIcon notifyIcon1;
private SystemWindowsFormsContextMenu contextMenu1;
private SystemWindowsFormsMenuItem menuItem1;
private SystemComponentModelIContainer components;
[STAThread]
static void Main()
{
ApplicationRun(new Form1());
}
public Form1()
{
thiscomponents = new SystemComponentModelContainer();
thiscontextMenu1 = new SystemWindowsFormsContextMenu();
thismenuItem1 = new SystemWindowsFormsMenuItem();
// Initialize contextMenu1
thiscontextMenu1MenuItemsAddRange(
new SystemWindowsFormsMenuItem[] {thismenuItem1});
// Initialize menuItem1
thismenuItem1Index = 0;
thismenuItem1Text = "E&xit";
thismenuItem1Click += new SystemEventHandler(thismenuItem1_Click);
// Set up how the form should be displayed
thisClientSize = new SystemDrawingSize(292, 266);
thisText = "Notify Icon Example";
// Create the NotifyIcon
thisnotifyIcon1 = new SystemWindowsFormsNotifyIcon(thiscomponents);
// The Icon property sets the icon that will appear
// in the systray for this application
notifyIcon1Icon = new Icon("appiconico");
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked
notifyIcon1ContextMenu = thiscontextMenu1;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon
notifyIcon1Text = "Form1 (NotifyIcon example)";
notifyIcon1Visible = true;
// Handle the DoubleClick event to activate the form
notifyIcon1DoubleClick += new SystemEventHandler(thisnotifyIcon1_DoubleClick);
}
protected override void Dispose( bool disposing )
{
// Clean up any components being used
if( disposing )
if (components != null)
componentsDispose();
baseDispose( disposing );
}
private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
// Show the form when the user double clicks on the notify icon
// Set the WindowState to normal if the form is minimized
if (thisWindowState == FormWindowStateMinimized)
thisWindowState = FormWindowStateNormal;
// Activate the form
thisActivate();
}
private void menuItem1_Click(object Sender, EventArgs e) {
// Close the form, which closes the application
thisClose();
}
}
以上就是关于怎么能让VB 程序最小化时在托盘显示呀全部的内容,包括:怎么能让VB 程序最小化时在托盘显示呀、怎样在任务栏的托盘里显示后台运行程序的图标、高分求教:VB6.0实现运行程序后在托盘显示图标,鼠标左键单击显示或隐藏程序界面,右键单击有退出!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)