[英]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.