This is the code I tried but does not work . .
Dim lab As New Label
lab.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, 0)
CodePudding user response:
Well, it does work. Did you add it to a form? Use Form.Controls.Add(Control)
You said "In one line", so...
Me.Controls.Add(New Label With {.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, 0), .Location = New Point(10, 10), .Text = "abcDEF"})
but here it is a bit more readable
Dim lab As New Label()
lab.Font = New System.Drawing.Font("Courier New", 8.25!, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, 0)
lab.Location = New Point(10, 10)
lab.Text = "abcDEF"
Me.Controls.Add(lab)