שתף באמצעות


Change font appearance in label or message box

Question

Friday, October 12, 2012 4:27 PM

I use labels and message boxes to give the User information. There are situations where I would like to add underlining or bold type or color within a sentence in the message  for emphasis.

I can't find any information on the subject other than a previous post that suggested building a custom message box. The only problem I see there is that the text I put in the custom message box would be held on labels and, I can' find any information indicating if this can be done or not.

Any suggestions?

sirmilt

All replies (7)

Friday, October 12, 2012 4:52 PM | 1 vote

Milt,

As for labels, you might consider Dev Express. The following isn't much to go on but it will show you how it works by supporting HTML:

http://documentation.devexpress.com/#WindowsForms/DevExpressXtraEditorsLabelControl_AllowHtmlStringtopic

You can get those free here:

https://www.devexpress.com/Products/Free/NetOffer/

I don't know of a message box that supports it (including Dev's), but you could use that label and create a form that you show modally which includes the Dev label. It wouldn't be difficult really.

Please call me Frank :)


Friday, October 12, 2012 5:25 PM

a label has a Font property where you can set the Font, Font Size and Bold,Italic, etc

and it has a ForeColor property where you can set the Font Color

are those not working for you?

as an example create an app with 2 Forms.On Form1 put a button, on Form2 put a label. In the code for Form1:

Public Class Form1    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        Dim frm2 As New Form2        frm2.ShowDialog()    End SubEnd Class

The code for Form2:

Public Class Form2    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Label1.Text = "this is to change font properties"        Label1.Font = New Font("Arial", 16, FontStyle.Bold Or FontStyle.Underline)        Label1.ForeColor = Color.Red    End SubEnd Class

“This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.”


Friday, October 12, 2012 5:56 PM

Instead of using a MessageBox you could use a Dialog form

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dialog1.Show()

    End Sub

End Class
Imports System.Windows.Forms

Public Class Dialog1

    Private Sub Dialog1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.TopMost = True
        Label1.Text = "This is to change font properties"
        Label1.Font = New Font("Arial", 16, FontStyle.Underline)
        Label1.ForeColor = Color.Red
        Me.Width = Label1.Width + 30
    End Sub

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

    End Sub
End Class

You've taught me everything I know but not everything you know.


Friday, October 12, 2012 6:57 PM

Thank you all for the quick responses.

Obviously, I didn't explain my situation very well, let me try a different scenario.

I want to fill the label a sentence like this "If the situation is Yes then do this. If the situation is No then do that"

Looks simple enough but I can't figure out how to program the underline and bold within the string statement.

sirmilt


Friday, October 12, 2012 7:11 PM

Thank you all for the quick responses.

Obviously, I didn't explain my situation very well, let me try a different scenario.

I want to fill the label a sentence like this "If the situation is Yes then do this. If the situation is No then do that"

Looks simple enough but I can't figure out how to program the underline and bold within the string statement.

sirmilt

Please call me Frank :)


Friday, October 12, 2012 7:34 PM

 within a sentence in the message  for emphasis.

my apologies, Milt

you did say "within" a sentence - I missed the within

the only out-of-the-box control you would be able to do this in is a RichtextBox

if you want to use a label, you'd need a third party control as Frank showed

or you could get really adventurous and create a custom label yourself

“This forum post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.”


Friday, October 12, 2012 8:04 PM

I decided on the Dialog box solution, Its a little more effort but gives me what I want.

I'm never used the RichTextBox but am going towork with it and hopefully I'll end up with the  solution that I want.

sirmilt