簡體   English   中英

如何使用C#在Winforms中設置菜單欄位置?

[英]How to set Menu bar location in Winforms using C#?

實際上,我設置FormBorderStyle = none 然后我在頂部添加一個面板,以添加最小化,還原和關閉按鈕 現在,我想在面板后面添加主菜單

我試圖在winform中為主菜單設置位置。 但是主菜單沒有屬性。

private void HomePage_Load(object sender, EventArgs e)
    {     
        int width = Screen.PrimaryScreen.Bounds.Width;
        int height = Screen.PrimaryScreen.Bounds.Height;
        this.Location = new Point(0, 0);
        this.Size = new Size(width, height-100);

        HeaderPanel.Location = new Point(0,0);    //minimize,restore,close panel
        HeaderPanel.Size = new Size(width, 20);

        lblClose.Location = new Point(width - 20, 0);
        lblMinimize.Location = new Point(width - 35, 0);

        MainMenu.Location = new Point(0,30); // Menu bar location. Error appear
    }

如何設置位置?

謝謝。

使用MenuStrip 它取代了MainMenu並且因為它繼承自Control ,所以具有Location屬性。

我找到了解決方案

轉到屬性->布局-> Dock = None ..

然后,我們可以將菜單欄移動到所需的位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM