I have the following code in C# (.NET Framework 3.5)
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required
// for Windows Forms designer support.
//
Label myControl = new Label();
myControl.Text = "TEXT";
myControl.FlatStyle = FlatStyle.System;
myControl.AutoSize = true;
myControl.BorderStyle = BorderStyle.FixedSingle;
myControl.Padding = new Padding(0);
myControl.Margin = new Padding(0);
this.Controls.Add(myControl);
InitializeComponent();
}
}
Which should display a label with the text enclose by a border, like this:
------
|TEXT|
------
Instead, I get this:
--------
|TEXT |
--------
And I don't know why... My objective is to be able to have multiple labels without space between them, like this:
-----------
|TEXT|TEXT|
-----------
Am I missing something? Thanks in advance!
For clarification, I need to have NO SPACE between the text and the border.
FlowLayoutPanel
here msdn.microsoft.com/en-us/library/…, seems like it has what you're looking for – FixingmyControl.FlatStyle = FlatStyle.Standard;
No need for the Padding or Margins, that's for relationships with other controls. – VriesmyControl.FlatStyle = FlatStyle.Standard
I get the TEXT centered in the label, still with space between the TEXT and the border :( @Aeon the solution you linked trims the last character (i.e.: I get TEX) – KetonuriaGraphics.DrawString()
, unless you want to have all the events from a label. – Wombat