Monte Cristo33

Dear friends,

I am converting from VB 5 to VB 2005 Express, and things are as not as straightforward as I expected.

I am doing a simple text editor program where the user can change the font Type, style, size and alignment in an input text box. However, none of the old code still work.

what would be the VB 2005 equivalent of the following VB5 code:
Private Sub cmdArial_Click()
txtInput.FontName = "Arial"
End Sub

Private Sub cmdBold_Click()
txtInput.Font.Bold = True
End sub

Private Sub cmdCenter_Click()
txtInput.alignment = 1
End Sub

Private Sub optFont10_click()
txtInput.fontSize =10
End Sub

Any light you can shed would be really appreciated.

Thanks in anticipation.

MC



Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Tall Dude

Here is some code that may help.

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Me.TextBox1.Font = New System.Drawing.Font("Arial", 9.75!, _

System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

Me.TextBox1.TextAlign = HorizontalAlignment.Right

End Sub






Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Monte Cristo33

Tall Dude,

Thanks for your reply.

I've since managed to tackle the font type:

Private Sub cmdArial_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdArial.Click

' Create a new Font object Name and Size are required.

Dim fArial As New System.Drawing.Font("Arial", 10)

' Assign the font to the control

Me.txtInput.Font = fArial

Me.txtFont.Text = "Arial"

End Sub

However, I'm still stuck on the style, size and alignment. These three are actuated separately by different buttons and need separate blocks of code each.

What am I missing

Thanks.

MC





Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Tall Dude

Public Class Form1

Private Sub cmdArial_Click(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles cmdArial.Click

' Create a new Font object Name and Size are required.

Dim fArial As New System.Drawing.Font("Arial", 10)

' Assign the font to the control

Me.TxtInput.Font = fArial

Me.TxtFont.Text = "Arial"

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button2.Click

Me.TxtInput.Font = New System.Drawing.Font(Me.TxtInput.Font, _

Me.TxtInput.Font.Style Or FontStyle.Bold)

End Sub

End Class






Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Tall Dude

Also see Nobugz and my posts here:

https://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1048698&SiteID=1

(Talks about some styles not available in some fonts.)






Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Monte Cristo33

Hi Tall Dude,

thanks again for you help and patience. I got the font style to work now. How do I tackle the font size and alignment

MC





Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Tall Dude

Please post a new thread asking a more specific alignment question.

For font size:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles Button1.Click

Dim SwitchToThisSize As Single = 33.0!

Textbox1.Font = New Font(Textbox1.Font.FontFamily, _

SwitchToThisSize, Textbox1.Font.Style)

End Sub

End Class






Re: Visual Basic Express Edition How to code Font Type, Style, size and alignment properties in VB 2005 Express

Monte Cristo33

will do. Thanks for all your help so far.

MC