由于之前已经对Webbrowser控件有了很好的认识,实际本节更多的是调用document.ExecCommand方法。 设计界面:
使用到的常量:
Private Const HTML_COMMAND_BolD = "Bold" '加粗 Private Const HTML_COMMAND_UNDERliNE = "Underline" '下划线 Private Const HTML_COMMAND_ITAliC = "Italic" '斜体 Private Const HTML_COMMAND_SUBSCRIPT = "Subscript" '下标 Private Const HTML_COMMAND_SUPERSCRIPT = "Superscript" '上标 Private Const HTML_COMMAND_STRIKE_THROUGH = "StrikeThrough" '删除线 Private Const HTML_COMMAND_Font_name = "Fontname" '字体 Private Const HTML_COMMAND_Font_SIZE = "FontSize" '字号 Private Const HTML_COMMAND_FORE_color = "Forecolor" '字体前景色 Private Const HTML_COMMAND_BACK_color = "Backcolor" '字体背景色 Private Const HTML_COMMAND_INSERT_FORMAT_BLOCK = "FormatBlock" '加粗 Private Const HTML_COMMAND_REMOVE_FORMAT = "RemoveFormat" '清除样式 Private Const HTML_COMMAND_JUSTIFY_left = "Justifyleft" '文本左对齐 Private Const HTML_COMMAND_JUSTIFY_CENTER = "JustifyCenter" '文本中间对齐 Private Const HTML_COMMAND_JUSTIFY_RIGHT = "JustifyRight" '文本右对齐 Private Const HTML_COMMAND_JUSTIFY_FulL = "JustifyFull" '文本两端对齐 Private Const HTML_COMMAND_INDENT = "Indent" '增大缩进量 Private Const HTML_COMMAND_OUTDENT = "Outdent" '减小缩进量 Private Const HTML_COMMAND_INSERT_liNE = "InsertHorizontalRule" '插入分割符 Private Const HTML_COMMAND_INSERT_List = "Insert{0}List" ' replace with (Un)Ordered 插入项目符号或项目编号 Private Const HTML_COMMAND_INSERT_IMAGE = "Insertimage" '插入图像 Private Const HTML_COMMAND_INSERT_link = "Createlink" '插入链接 Private Const HTML_COMMAND_REMOVE_link = "Unlink" '移除链接 Private Const HTML_COMMAND_TEXT_CUT = "Cut" '剪切 Private Const HTML_COMMAND_TEXT_copY = "copy" '复制 Private Const HTML_COMMAND_TEXT_PASTE = "Paste" '粘贴 Private Const HTML_COMMAND_TEXT_DELETE = "Delete" '删除 Private Const HTML_COMMAND_TEXT_UNDO = "Undo" '撤销 Private Const HTML_COMMAND_TEXT_REDO = "Redo" '恢复 Private Const HTML_COMMAND_TEXT_SELECT_ALL = "SelectAll" '全选 Private Const HTML_COMMAND_TEXT_UNSELECT = "Unselect" '取消选择 Private Const HTML_COMMAND_TEXT_PRINT = "Print" ' 打印 Private Const HTML_COMMAND_EDITMODE = "EditMode" ' 编辑模式 Private Const HTML_COMMAND_broWSEMODE = "browseMode" ' 浏览模式 Private Const HTML_COMMAND_OVERWRITE = "OverWrite" '转换插入、覆写模式
窗体载入时设置字体和字号
Private Sub frmBlog_Load(sender As Object,e As EventArgs) Handles Me.Load Dim linkhtm As String = "about:blank" 'Application.StartupPath & "\vIEw.htm" wbBlog.Url = New Uri(linkhtm) wbBlog.document.ExecCommand("EditMode",False,"") '设置为可编辑模式 Call setFontname() Call setFontSize() End Sub ' 设置字体 Private Sub setFontname() Dim computerFont As New System.Drawing.Text.InstalledFontCollection For Each Font_family As FontFamily In computerFont.FamilIEs If Font_family.IsstyleAvailable(FontStyle.Regular) Then tscFont.Items.Add(Font_family.name) End If Next tscFont.Selectedindex = 0 End Sub '设置字号 Private Sub setFontSize() tscFontSize.Items.Add("一号字") tscFontSize.Items.Add("二号字") tscFontSize.Items.Add("三号字") tscFontSize.Items.Add("四号字") tscFontSize.Items.Add("五号字") tscFontSize.Items.Add("六号字") tscFontSize.Items.Add("七号字") tscFontSize.Selectedindex = 0 End Sub
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
总结以上是内存溢出为你收集整理的vb.net 教程 12-6 webbrowser 文本编辑器 1全部内容,希望文章能够帮你解决vb.net 教程 12-6 webbrowser 文本编辑器 1所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)