ContextMenuStrip 在 Windows 左上角呈现

发布于 2024-09-26 22:55:45 字数 130 浏览 14 评论 0原文

当我渲染 contextmenustrip 时,它会在我的电脑屏幕的左上角渲染。我有一个列表视图,其中包含 5-6 个项目,右键单击每个项目时,将显示上下文菜单条。此外,我还需要更改上下文菜单条的颜色,包括背景和文本。

提前致谢!

When i render contextmenustrip, it gets render at the top left of my PC Screen. I have a listview, which contains 5-6 items and on right click of each item, the context Menu strip gets displayed.Also i need to change the color of context menu strip including backgrounds and text as well.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-10-03 22:55:45

到目前为止,最简单的方法是将 ListView.ContextMenuStrip 属性设置为您的 CMS,然后一切都是自动的。您可以在设计器中执行此操作。

如果您出于某种原因需要自定义处理程序,例如检查是否单击了正确的项目,那么您可以使用如下代码调用 Show() 方法属性:

    private void listView1_MouseClick(object sender, MouseEventArgs e) {
        if (allowContextMenu(listView1.SelectedItems) {
            contextMenuStrip1.Show(listView1, e.Location);
        }
    }

By far the simplest way is to just set the ListView.ContextMenuStrip property to your CMS, everything is automatic then. You can do so in the designer.

If you need a custom handler for some reason, to check if the right item was clicked for example, then you can call the Show() method property with code like this:

    private void listView1_MouseClick(object sender, MouseEventArgs e) {
        if (allowContextMenu(listView1.SelectedItems) {
            contextMenuStrip1.Show(listView1, e.Location);
        }
    }
肥爪爪 2024-10-03 22:55:45

您尚未显示任何代码,但如果您没有调用将控件作为参数的 Show 重载,则您的 new Point(0, 0)显然通过会将菜单放在屏幕的左上角。

You haven't shown any code, but if you're not calling the Show overload that takes a control as a parameter, the new Point(0, 0) that your obviously passing will put the menu in the upper left of the screen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文