簡體   English   中英

調整表單大小時出現問題 - c#winforms

[英]Problem while resizing a form - c# winforms

我有一個包含(除其他外)聊天選項的表單。 我有2個richtextbox和一個用於發送消息的按鈕。

表格

我希望當我調整表單大小時,消息框將變得更大(或更小),輸入框和按鈕將向下(或向上)移動,因此它們將保留在消息框下。

這是我寫的代碼:

    private void MainForm_SizeChanged(object sender, EventArgs e)
    {
        Rectangle screenRectangle = RectangleToScreen(ClientRectangle);

        int titleHeight = screenRectangle.Top - Top;

        int chatCurrentHeight = richTextBox2.Height;
        int chatNewHeight=Height-titleHeight - richTextBox1.Height - button1.Height - 100;
        richTextBox2.Height = chatNewHeight;
        int heightDiffernce = chatNewHeight - chatCurrentHeight;

        richTextBox1.Location = new Point(richTextBox1.Location.X, richTextBox1.Location.Y+heightDiffernce);
        button1.Location = new Point(button1.Location.X, button1.Location.Y+heightDiffernce);
    }

*** richtextbox1是輸入框,richtextbox2是消息框。

它可以工作,但是當窗口變得非常小時(在消息框的大小幾乎為0之后)以及當我最小化窗口時它會中斷:輸入框和按鈕消失。

我該如何解決?

我同意Idle_Mind。 使用tablelayoutpanel。

我會使用兩個表布局面板。 1.你的主要容器2.一個用於你的消息和輸入

然后,使用包含“消息”控件的行上的表格布局面板的“百分比”屬性。

也許,80%的消息,20%,您的輸入。 然后,停靠兩個richtextbox,以便它們伸展和縮小。

暫無
暫無

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

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