vb.net 教程 12-6 webbrowser 文本编辑器 2

vb.net 教程 12-6 webbrowser 文本编辑器 2,第1张

概述编辑使用到的代码: '拷贝 Private Sub tsbCopy_Click(sender As Object, e As EventArgs) Handles tsbCopy.Click wbBlog.Document.ExecCommand(HTML_COMMAND_TEXT_COPY, False, "") End Sub '粘贴 P

编辑使用到的代码:

    '拷贝    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,"")        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,"")    End Sub

    '斜体    Private Sub tsbItalic_Click(sender As Object,e As EventArgs) Handles tsbItalic.Click        wbBlog.document.ExecCommand(HTML_COMMAND_ITAliC,"")    End Sub

    '下划线    Private Sub tsbUnderline_Click(sender As Object,e As EventArgs) Handles tsbUnderline.Click        wbBlog.document.ExecCommand(HTML_COMMAND_UNDERliNE,"")    End Sub

    '左对齐    Private Sub tsbleft_Click(sender As Object,e As EventArgs) Handles tsbleft.Click        wbBlog.document.ExecCommand(HTML_COMMAND_JUSTIFY_left,"")    End Sub

    '中间对齐    Private Sub tsbCenter_Click(sender As Object,e As EventArgs) Handles tsbCenter.Click        wbBlog.document.ExecCommand(HTML_COMMAND_JUSTIFY_CENTER,"")    End Sub

    '右对齐    Private Sub tsbRight_Click(sender As Object,e As EventArgs) Handles tsbRight.Click        wbBlog.document.ExecCommand(HTML_COMMAND_JUSTIFY_RIGHT,"")    End Sub

    '两端对齐    Private Sub tsbJustifyFull_Click(sender As Object,e As EventArgs) Handles tsbJustifyFull.Click        wbBlog.document.ExecCommand(HTML_COMMAND_JUSTIFY_FulL,"")    End Sub

    '剪切    Private Sub tsbCut_Click(sender As Object,e As EventArgs) Handles tsbCut.Click        wbBlog.document.ExecCommand(HTML_COMMAND_TEXT_CUT,"")    End Sub

    '撤销    Private Sub tsbUndo_Click(sender As Object,e As EventArgs) Handles tsbUndo.Click        wbBlog.document.ExecCommand(HTML_COMMAND_TEXT_UNDO,"")    End Sub

    '重做    Private Sub tsbRedo_Click(sender As Object,e As EventArgs) Handles tsbRedo.Click        wbBlog.document.ExecCommand(HTML_COMMAND_TEXT_REDO,"")    End Sub

    '清除样式    Private Sub tsbClear_Click(sender As Object,e As EventArgs) Handles tsbClear.Click        wbBlog.document.ExecCommand(HTML_COMMAND_REMOVE_FORMAT,"")    End Sub

    '修改字体    Private Sub tscFont_SelectedindexChanged(sender As Object,e As EventArgs) Handles tscFont.SelectedindexChanged        wbBlog.document.ExecCommand(HTML_COMMAND_Font_name,tscFont.Text)    End Sub

    '修改字号    Private Sub tscFontSize_SelectedindexChanged(sender As Object,e As EventArgs) Handles tscFontSize.SelectedindexChanged        wbBlog.document.ExecCommand(HTML_COMMAND_Font_SIZE,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,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,imgpath)    End Sub


运行效果:

由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。

学习更多vb.net知识,请参看 vb.net 教程 目录

总结

以上是内存溢出为你收集整理的vb.net 教程 12-6 webbrowser 文本编辑器 2全部内容,希望文章能够帮你解决vb.net 教程 12-6 webbrowser 文本编辑器 2所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1282964.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存