ContextMenu重绘
private void cm_DrawItem(object sender, DrawItemEventArgs e)
{
try
{
Color cms1 = SkinForm.GetColor("gv", "abcolor");
Color cms2 = SkinForm.GetColor("gv", "rhbcolor");
Color cms3 = SkinForm.GetColor("gv", "afcolor");
MenuItem mnuItem = (MenuItem)sender;
SolidBrush Brush1 = new SolidBrush(cms1);
SolidBrush Brush2 = new SolidBrush(cms2);
SolidBrush Brush3 = new SolidBrush(cms3);
Pen cmPen = new Pen(SkinForm.GetColor("gv", "asfcolor"));
StringFormat Format = new StringFormat();
if ((e.State & DrawItemState.Selected) != 0)
{
if (this.Enabled)
{
e.Graphics.FillRectangle(Brush1, e.Bounds);
e.Graphics.DrawRectangle(cmPen, e.Bounds.Left, e.Bounds.Y, e.Bounds.Width - 2, e.Bounds.Height - 2);
}
}
else
{
e.Graphics.FillRectangle(Brush2, e.Bounds);
}
if (this.Text != "-")
{
Rectangle DisplayRect = new Rectangle(e.Bounds.Left, e.Bounds.Top + 2, e.Bounds.Width, e.Bounds.Bottom);
Format.Alignment = StringAlignment.Center;
if (this.Enabled)
{
e.Graphics.DrawString(mnuItem.Text, gv_songlist.Font, Brush3, DisplayRect, Format);
}
else
{
e.Graphics.DrawString(mnuItem.Text, gv_songlist.Font, Brush3, DisplayRect, Format);
}
}
else
{
e.Graphics.DrawLine(cmPen, e.Bounds.Left, e.Bounds.Top, e.Bounds.Right, e.Bounds.Top);
}
}
catch
{ }
}
private void cm_MeasureItem(object sender, MeasureItemEventArgs e)
{
try
{
MenuItem mnuItem = (MenuItem)sender;
e.ItemHeight = (int)e.Graphics.MeasureString(Text, gv_songlist.Font).Height + 3;
e.ItemWidth = (int)e.Graphics.MeasureString(Text, gv_songlist.Font).Width + 3;
}
catch
{ }
}
显示:
Win32.POINT point = new Win32.POINT();
Win32.GetCursorPos(ref point);
Win32.SetForegroundWindow(this.Handle);
Win32.TrackPopupMenuEx(this.cm.Handle, 0x40, point.x, point.y, this.Handle, new Win32.TPMPARAMS());
----------------------
public class Win32
{
[DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
public static extern int SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "TrackPopupMenuEx")]
public static extern int TrackPopupMenuEx(
IntPtr hMenu,
int un,
int n1,
int n2,
IntPtr hWnd,
TPMPARAMS lpTPMParams
);
[StructLayout(LayoutKind.Sequential)]
public struct TPMPARAMS
{
public int cbSize;
public RECT rcExclude;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
public static extern int GetCursorPos(ref POINT lpPoint);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)