gpt4 book ai didi

c# - FlowLayoutPanel 中文本框的自动宽度

转载 作者:行者123 更新时间:2023-11-30 16:59:19 25 4
gpt4 key购买 nike

在 FlowLayoutPanel 中,我有一个标签和一个并排的文本框。当我更改 FlowLayoutPanel 的宽度时,我还希望更改文本框的宽度。这可能吗?

控件是这样放置的:

[ FLOWLAYOUTPANEL [标签] [文本框] ]

编辑:根据 Jay Stratemeyer 和 Hans Passant 的代码和建议,我能够拥有一个标签和一个可以调整其宽度并自动换行的文本框。这是代码:

    Private Sub FlowLayoutPanel1_Resize(sender As Object, e As System.EventArgs) Handles FlowLayoutPanel1.Resize
Dim new_width As Integer = FlowLayoutPanel1.ClientSize.Width - LabelControl1.Width - LabelControl1.Margin.Left - LabelControl1.Margin.Right - TextBox1.Margin.Left - TextBox1.Margin.Right

If new_width > Me.TextBox1.MinimumSize.Width Then
Me.TextBox1.Width = new_width
End If
End Sub

最佳答案

public Form1()
{
InitializeComponent();
this.Load +=new EventHandler(Form1_Load);
}

public int MyFlowPanelOriginalSize { get; set; }
public int MyFlowPanelNewSize { get; set; }
public int DifferenceInSizeOfPanel { get; set; }

private void Form1_Load(object sender, EventArgs e)
{
MyFlowPanelOriginalSize = MyFlowPanel.Width;
MyFlowPanel.Resize += new EventHandler(MyFlowPanel_Resize);
DifferenceInSizeOfPanel = 0;
}



void MyFlowPanel_Resize(object sender, EventArgs e)
{
MyFlowPanelNewSize = MyFlowPanel.Width;
DifferenceInSizeOfPanel = MyFlowPanelNewSize - MyFlowPanelOriginalSize;
var TextBoxDifference = MyTextBox.Width + DifferenceInSizeOfPanel;
MyTextBox.Width = TextBoxDifference;
MyFlowPanelOriginalSize = MyFlowPanel.Width;
}

关于c# - FlowLayoutPanel 中文本框的自动宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23812544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com