Danile Vetelor
Danile Vetelor

Reputation: 21

How to change TextBox.text font style to Italic

I have a textbox control called tb_remarks and tried to make texts written in tb_remarks using:

tb_remark.Font.Italic = True, but I am getting a read only exception.

Note: I don't want to change the control's property using Windows Forms Designer

Upvotes: 2

Views: 4343

Answers (2)

Vivek S.
Vivek S.

Reputation: 21915

You should initialize a new style for the font as per Control.Font Property and assign italic-style:

Imports System.Drawing

tb_remarks.Font = New Font(Font, FontStyle.Italic)

Upvotes: 4

Tim Schmelter
Tim Schmelter

Reputation: 460158

Use the Font-constructor and assign it to the textbox:

Dim font = New Font(tb_remark.Font, FontStyle.Italic)
tb_remark.Font = font

By passing the old Font you use all other properties as prototype.

Upvotes: 4

Related Questions