版权声明:本文为博主原创文章,转载请在显著位置标明本文出处以及作者网名,未经作者允许不得用于商业目的。
编辑使用到的代码:
'拷贝
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版权协议,转载请附上原文出处链接及本声明。