Private Sub mnuFont_Click()
' Set Cancel to True.
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set the Flags property.
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
' Display the Font dialog box.
CommonDialog1.ShowFont
' Set text properties according to user's
' selections.
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
RichTextBox1.ForeColor = CommonDialog1.Color
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
控件有RichTextBox和CommonDialog,但是使用之后报错“未找到方法和数据成员”,我查了一下MSDN,我怀疑还得加个叫做font 有个叫做Font Dialog Box的控件,但又找不到这个控件,请VB高手帮助我
VB CommonDialog控件 ShowFont的问题
答案:2 悬赏:80 手机版
解决时间 2021-03-12 05:08
- 提问者网友:留有余香
- 2021-03-11 08:56
最佳答案
- 五星知识达人网友:我住北渡口
- 2021-03-11 09:29
Private Sub Command1_Click()
' Set Cancel to True.
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set the Flags property.
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
' Display the Font dialog box.
CommonDialog1.ShowFont
' Set text properties according to user's
' selections.
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
'RichTextBox1.ForeColor = CommonDialog1.Color'RichTextBox没有属性可以更改其默认前景色
RichTextBox1.SelColor = CommonDialog1.Color'改变已选取文字的颜色,注意必须先选定部分文字,再调用这个过程才能看到效果
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
======================================================================
由于Color'RichTextBox没有属性可以更改其默认前景色,可采用以下方法变通:
Private Sub SetDefaultForeColor(color)
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelColor = color
RichTextBox1.SelStart = 0
End Sub
' Set Cancel to True.
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set the Flags property.
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
' Display the Font dialog box.
CommonDialog1.ShowFont
' Set text properties according to user's
' selections.
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
'RichTextBox1.ForeColor = CommonDialog1.Color'RichTextBox没有属性可以更改其默认前景色
RichTextBox1.SelColor = CommonDialog1.Color'改变已选取文字的颜色,注意必须先选定部分文字,再调用这个过程才能看到效果
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
======================================================================
由于Color'RichTextBox没有属性可以更改其默认前景色,可采用以下方法变通:
Private Sub SetDefaultForeColor(color)
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelColor = color
RichTextBox1.SelStart = 0
End Sub
全部回答
- 1楼网友:第四晚心情
- 2021-03-11 09:48
你需要先添加此控件:
工程-部件-勾选 “Microsoft Common Dialog 6.0 ”确定,然后在窗体上添加此控件这段代码就可以正常运行了。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯