标签:object .net net dllimport framework stat open point work
.net framework4.5.2 环境下使用NotifyIcon 托盘 默认状态下弹出的右键菜单是在左边 别家的都是在右边。
使用ContextMenuStrip 在其opening事件中
m_NotifyIcon.ContextMenuStrip.Opening += ContextMenuStripOnOpening;
private void ContextMenuStripOnOpening(object sender, CancelEventArgs cancelEventArgs)
{
Point p = CursorPosition.GetCursorPosition();
Point menuPosition = new Point();
menuPosition.X =p.X;
menuPosition.Y = p.Y - 5 - m_NotifyIcon.ContextMenuStrip.Size.Height;
m_NotifyIcon.ContextMenuStrip.Show(menuPosition);
}
鼠标位置的获取:
public class CursorPosition
{
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public static Point GetCursorPosition()
{
POINT mousestart = new POINT();
GetCursorPos(out mousestart);
Point p = new Point();
p.X = mousestart.X;
p.Y = mousestart.Y;
return p;
}
}
托盘程序菜单位置 NotifyIcon menu position
标签:object .net net dllimport framework stat open point work
原文地址:http://www.cnblogs.com/ppzbty/p/7866995.html