How can I add borders to label in Windows Forms?

后端 未结 5 1531
误落风尘
误落风尘 2021-01-19 04:32

I\'m trying to create a form with white label inside, that when I click on something the form will disappear and only show the label. So far I tried to put the TransparencyK

5条回答
  •  臣服心动
    2021-01-19 05:07

    If anyone is still looking, here is what I did (mostly copied from this site)

    Create a new class, CustomLabel.cs for instance. Here's an example:

    public class CustomLabel : Label
        {
            protected override void OnPaint(PaintEventArgs e)
               {
                 base.OnPaint(e);
                 ControlPaint.DrawBorder(e.Graphics, ClientRectangle,
                                              Color.Red, 5, ButtonBorderStyle.Solid,
                                              Color.Red, 5, ButtonBorderStyle.Solid,
                                              Color.Red, 5, ButtonBorderStyle.Solid,
                                              Color.Red, 5, ButtonBorderStyle.Solid);
               } 
        }
    

    You can then use it like this:

                Form newForm = new Form();
    
                CustomLabel newLabel = new CustomLabel();
                newForm.Controls.Add(newLabel);
    
                newLabel.BackColor = Color.Black;
                newLabel.Font = new System.Drawing.Font("Microsoft Arial", 18F,
                FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
                newLabel.ForeColor = Color.Crimson;
                newLabel.Text = "Some text on a topmost transparent form window";
    
                newForm.Show();
                newForm.TopMost = true;
    
                newLabel.AutoSize = true;
                newLabel.Location = new Point(230, 375);
    

提交回复
热议问题