Reputation: 1063
The text of the label is written programmatically:
public Form1()
{
InitializeComponent();
label.Text = data from database;
}
Upvotes: 1
Views: 957
Reputation: 12739
You could set the Dock
property each of the controls. Depending on your layout you can set each of them to DockStyle.Left
and set the AutoSize
property of the label to true. If you can't dock them as is, you can put them inside of a panel and dock inside of the panel. When inside of the panel you can also take advantage of the Fill style of docking (which would also work outside of the panel, but depending on the rest of the controls in your layout it could screw them up. Inside of a panel you can set the label to DockStyle.Left
and the TextBox to DockStyle.Fill
(to take up the rest of the space)
Upvotes: 1
Reputation: 941465
Set the label's MaximumSize.Width property so it cannot overlap the TextBox. If you don't have enough space vertically then also set the MaximumSize.Height property. You then should also consider setting AutoEllipsis to True so that it is obvious to the user that the text got truncated, a tooltip shows the full text.
An easy way to determine the proper values for MaximumSize is to temporarily turn AutoSize off. Adjust the label size to the maximum size that doesn't overlap anything. Copy/paste the Size into AutoSize. Or leave it off.
Upvotes: 0