簡體   English   中英

具有“Dock”調整大小功能的重疊面板

[英]Overlapping panels with "Dock" resize functionality

我已經為這個問題苦苦掙扎了幾天,這似乎有一個明顯的解決方案。 我如何放置一個面板,該面板保持 position 並調整大小,就像在表單中間停靠一樣,在填充 TableLayoutPanel 的其他面板上,而不會弄亂列/行跨度並放錯其他容器和控件?

我想避免開發自定義功能並使用基本的 Visual Studio 工具箱(歡迎擴展)。

為了更好地解釋我希望實現的目標,我提供了一個指向目標圖像的鏈接。

藍色是可動態調整大小的居中彈出面板。
綠色是從 TableLayoutPanel 的單元格 [1,1] 開始的 Image/BackgroundImage。
橙色是側邊菜單的下拉面板,也從單元格 [1,1] 開始。

所需表單布局的圖像

所以...我找到了解決方案。 我想我需要承認我必須自己編寫調整大小的 function。
我是新來的,所以我不知道回答自己的問題是否是經典,但是就這樣吧。

對於Orange面板,鑒於它是 Anchored Top,Left:

private double panel1WidthRatio, panel1HeightRatio; // Global variables for maintaining ratio.

    private void ParentForm_ResizeBegin(object sender, EventArgs e)
    {
        double p1w = this.side_panel.Size.Width;    // Grab the panels' dimensions
        double p1h = this.side_panel.Size.Height;   // as soon as the user begins to resize
        double fw = this.Size.Width;                // in order to store
        double fh = this.Size.Height;               // the Panel to Form
        panel1WidthRatio = p1w / fw;                // dimension ratios.
        panel1HeightRatio = p1h / fh;
    }

    private void ParentForm_SizeChanged(object sender, EventArgs e)
    {
        double formWidth = this.Size.Width;         // As soon as a new size is set
        double formHeight = this.Size.Height;       // resize the panel using the earlier ratio.
        this.side_panel.Size = new Size((int)(formWidth * panel1WidthRatio), (int)(formHeight * panel1HeightRatio));
    }

對於藍色面板,沒有錨點,只需替換:

this.side_panel.Size = new Size((int)(formWidth * panel1WidthRatio), (int)(formHeight * panel1HeightRatio));

和:

        this.middle_panel.Size = new Size((int)(formWidth * panel2WidthRatio), (int)(formHeight * panel2HeightRatio));
        this.middle_panel.Location = new System.Drawing.Point(this.Size.Width/4-9, this.Size.Height/4-24);

常量 (9,24) 考慮了窗體的框架和邊框,以便正確地將面板重新定位在中心。

暫無
暫無

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

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