【问题标题】:How do I position a ContextMenuStrip underneath a link label?如何在链接标签下方放置 ContextMenuStrip?
【发布时间】:2014-02-10 09:02:01
【问题描述】:

我的表单有一个链接标签 llInventory 和 ContextMenuStrip cmsInventory。当我在链接标签上左键单击时,上下文菜单条应在链接标签的正下方打开。所以我写了代码来定位 contextMenuStrip 但它仍然显示在屏幕的左上角,这是代码

        private void llInventory_MouseClick(object sender, MouseEventArgs e)
    {
         if (e.Button == MouseButtons.Left)
        {
           // llInventory.BackColor = Color.Blue;
            //llInventory.ForeColor = Control.
            Point p = new Point(this.llInventory.Location.X, this.llInventory.Location.Y + llInventory.Height);
            cmsInventory.PointToScreen(p);
            cmsInventory.Show();
        }
    }

我该如何解决这个问题?

【问题讨论】:

    标签: c# winforms


    【解决方案1】:

    你应该使用这个Show(Point)方法:

    cmsInventory.Show(cmsInventory.PointToScreen(p));
    

    或者您可以使用Show(Control, Point) 重载来相对于指定控件位置定位上下文菜单条。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 2015-09-22
      • 1970-01-01
      • 2019-10-21
      • 2017-10-14
      相关资源
      最近更新 更多