Hi @Rishabh aggarwal , Welcome to Microsoft Q&A, You can use borderline and flowlayoutpanel to achieve your needs. Then put the label in it. The simplified code is as follows:
using System.Windows.Forms;
namespace _11_10_x
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeCustomComponents();
}
private void InitializeCustomComponents()
{
//Create panel
Controls.Add(new Panel
{
BorderStyle = BorderStyle.None,
Dock = DockStyle.Fill,
Controls =
{
// top border
new Label
{
BackColor = System.Drawing.Color.Black,
Dock = DockStyle.Top,
Height = 1
},
// FlowLayoutPanel
new FlowLayoutPanel
{
Dock = DockStyle.Top,
Height = 30,
FlowDirection = FlowDirection.LeftToRight,
Padding = new Padding(10),
Controls =
{
// tag 1
new Label
{
Text = "Label 1",
Anchor = AnchorStyles.Top
},
// tag 2
new Label
{
Text = "Label 2",
Anchor = AnchorStyles.Top
},
// tag 3
new Label
{
Text = "Tag 3",
Anchor = AnchorStyles.Top
}
}
},
// bottom border
new Label
{
BackColor = System.Drawing.Color.Black,
Dock = DockStyle.Top,
Height = 3
}
}
});
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.