ISstyle 可用,不适用于字体

发布于 2024-12-11 10:22:47 字数 1538 浏览 0 评论 0原文

我有两个下拉列表(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金兰素衣 2024-12-18 10:22:47

使用 CSSWebControl.Font 属性。您无法更改(替换)字体属性(因为它是只读的)。如果你想绘制图像,请使用 CSS background 属性。

Use CSS or WebControl.Font properties. You can't change(replace) the font property (as it is read only). If you want to draw an image then use CSS background property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文