-
vb.net 教程 12-6 webbrowser 文本编辑器 2
版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
编辑使用到的代码:
'拷贝
Private Sub tsbCopy_Click(sender As Object, e As EventArgs) Handles tsbCopy.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_COPY, False, "")
End Sub
'粘贴
Private Sub tsbPaste_Click(sender As Object, e As EventArgs) Handles tsbPaste.Click
' wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_PASTE, False, "")
wbBlog.Focus()
SendKeys.Send("^v")
End Sub
注意:粘贴命令Paste似乎没有作用,这里用了直接发送键盘命令粘贴的方法的方法。
'粗体
Private Sub tsbBold_Click(sender As Object, e As EventArgs) Handles tsbBold.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_BOLD, False, "")
End Sub
'斜体
Private Sub tsbItalic_Click(sender As Object, e As EventArgs) Handles tsbItalic.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_ITALIC, False, "")
End Sub
'下划线
Private Sub tsbUnderline_Click(sender As Object, e As EventArgs) Handles tsbUnderline.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_UNDERLINE, False, "")
End Sub
'左对齐
Private Sub tsbLeft_Click(sender As Object, e As EventArgs) Handles tsbLeft.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_JUSTIFY_LEFT, False, "")
End Sub
'中间对齐
Private Sub tsbCenter_Click(sender As Object, e As EventArgs) Handles tsbCenter.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_JUSTIFY_CENTER, False, "")
End Sub
'右对齐
Private Sub tsbRight_Click(sender As Object, e As EventArgs) Handles tsbRight.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_JUSTIFY_RIGHT, False, "")
End Sub
'两端对齐
Private Sub tsbJustifyFull_Click(sender As Object, e As EventArgs) Handles tsbJustifyFull.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_JUSTIFY_FULL, False, "")
End Sub
'剪切
Private Sub tsbCut_Click(sender As Object, e As EventArgs) Handles tsbCut.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_CUT, False, "")
End Sub
'撤销
Private Sub tsbUndo_Click(sender As Object, e As EventArgs) Handles tsbUndo.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_UNDO, False, "")
End Sub
'重做
Private Sub tsbRedo_Click(sender As Object, e As EventArgs) Handles tsbRedo.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_REDO, False, "")
End Sub
'清除样式
Private Sub tsbClear_Click(sender As Object, e As EventArgs) Handles tsbClear.Click
wbBlog.Document.ExecCommand(HTML_COMMAND_REMOVE_FORMAT, False, "")
End Sub
'修改字体
Private Sub tscFont_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tscFont.SelectedIndexChanged
wbBlog.Document.ExecCommand(HTML_COMMAND_FONT_NAME, False, tscFont.Text)
End Sub
'修改字号
Private Sub tscFontSize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tscFontSize.SelectedIndexChanged
wbBlog.Document.ExecCommand(HTML_COMMAND_FONT_SIZE, False, tscFontSize.SelectedIndex + 1)
End Sub
'字体颜色
Private Sub tsbFontColor_Click(sender As Object, e As EventArgs) Handles tsbFontColor.Click
Dim fontcolor As Color
If cdColor.ShowDialog() = DialogResult.OK Then
fontcolor = cdColor.Color
Else
Exit Sub
End If
wbBlog.Document.ExecCommand(HTML_COMMAND_FORE_COLOR, False, System.Drawing.ColorTranslator.ToHtml(fontcolor))
End Sub
'背景颜色
Private Sub tsbBackColor_Click(sender As Object, e As EventArgs) Handles tsbBackColor.Click
Dim bgcolor As Color
If cdColor.ShowDialog() = DialogResult.OK Then
bgcolor = cdColor.Color
Else
Exit Sub
End If
wbBlog.Document.BackColor = bgcolor
End Sub
注意:ExecCommand命令BackColor修改的是文字背后的颜色,而不是我们希望的整个网页的背景色,这里直接修改WebBrowser.Document.BackColor
'插入图片
Private Sub tsbImage_Click(sender As Object, e As EventArgs) Handles tsbImage.Click
Dim imgpath As String
If ofDialog.ShowDialog = DialogResult.OK Then
imgpath = ofDialog.FileName
Else
Exit Sub
End If
wbBlog.Document.ExecCommand(HTML_COMMAND_INSERT_IMAGE, False, imgpath)
End Sub
运行效果:
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看 vb.net 教程 目录
————————————————
版权声明:本文为CSDN博主「VB.Net」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/uruseibest/article/details/77622920
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比