ISstyle 可用,不适用于字体
我有两个下拉列表(DropFont,DropFontSize)和一个文本框(txtSample),一个用于字体名称,另一个用于字体大小,现在如果我从下拉列表中选择字体名称,文本框中的文本应随所需的字体名称和大小。但是当我更改某些字体时,它给出错误,指出该字体不支持“常规”。
所以我一直在尝试修改如下所示,但现在它给我错误,字体属性是只读的。
这是我的代码:
Try
' Compose the font style.
Dim font_style As FontStyle = FontStyle.Regular
If Bold.Checked Then font_style = font_style Or FontStyle.Bold
If Italic.Checked Then font_style = font_style Or FontStyle.Italic
If Underline.Checked Then font_style = font_style Or FontStyle.Underline
If StrikeOut.Checked Then font_style = font_style Or FontStyle.Strikeout
' Get the font size.
Dim font_size As Single = 8
Try
font_size = Single.Parse(DropFontSize.SelectedValue)
Catch ex As Exception
End Try
' Get the font family name.
Dim family_name As String = "Times New Roman"
If Not (DropFont.SelectedItem Is Nothing) Then
family_name = DropFont.SelectedItem.ToString
End If
' Make the new font.
Dim new_font As New Font(family_name, font_size, font_style)
Catch
End Try
现在设置字体如下:
txtsample.font=new_font// getting error stating that font property is read-only.
I have two drop down lists(DropFont,DropFontSize) and a textbox(txtSample) one for font name and the other for font size and now if I select the font name from the drop down list the text in the text box should change with the desired font name and size.But when I change some fonts it gives me error stating that the font dosen't support "Regular".
So I have been trying to modify as shown below but now it gives me error that font property is read-only.
Here is my code:
Try
' Compose the font style.
Dim font_style As FontStyle = FontStyle.Regular
If Bold.Checked Then font_style = font_style Or FontStyle.Bold
If Italic.Checked Then font_style = font_style Or FontStyle.Italic
If Underline.Checked Then font_style = font_style Or FontStyle.Underline
If StrikeOut.Checked Then font_style = font_style Or FontStyle.Strikeout
' Get the font size.
Dim font_size As Single = 8
Try
font_size = Single.Parse(DropFontSize.SelectedValue)
Catch ex As Exception
End Try
' Get the font family name.
Dim family_name As String = "Times New Roman"
If Not (DropFont.SelectedItem Is Nothing) Then
family_name = DropFont.SelectedItem.ToString
End If
' Make the new font.
Dim new_font As New Font(family_name, font_size, font_style)
Catch
End Try
Now setting the font like this:
txtsample.font=new_font// getting error stating that font property is read-only.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
CSS
或WebControl.Font
属性。您无法更改(替换)字体属性(因为它是只读的)。如果你想绘制图像,请使用 CSSbackground
属性。Use
CSS
orWebControl.Font
properties. You can't change(replace) the font property (as it is read only). If you want to draw an image then use CSSbackground
property.