如何将照片添加到richtextbox,然后从那里将其保存为rtf文件. [英] how can i add a photo to richtextbox and from there i want to save it a rtf file.

查看:73
本文介绍了如何将照片添加到richtextbox,然后从那里将其保存为rtf文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


   私有Sub lblsave_Click(发送者为对象,e作为EventArgs)处理lblsave.Click

        '//保存新数据

       如果MsgBox(您是否要永久保存.",MsgBoxStyle.YesNo,"Save")= MsgBoxResult.是
            MsgBox(已保存",MsgBoxStyle.Information)


            saveToday.Write(vbCrLf& vbCrLf& dtp.Text& vbCrLf& vbCrLf&感觉:"& cbf.Text& vbCrLf&天气:"& cbw.Text& vbCrLf& vbCrLf& txtmain.Text & vbCrLf& vbCrLf& " _____________________________________________________________________')
            saveToday.Close()

       其他
            txtmain.Focus()
       如果结束

   结束Sub


    Private Sub lblsave_Click(sender As Object, e As EventArgs) Handles lblsave.Click

        '// to save new data

        If MsgBox("Do you want to save it permanently.", MsgBoxStyle.YesNo, "Save") = MsgBoxResult.Yes Then
            MsgBox("Saved", MsgBoxStyle.Information)


            saveToday.Write(vbCrLf & vbCrLf & dtp.Text & vbCrLf & vbCrLf & "Feelings :" & cbf.Text & vbCrLf & "Weather :" & cbw.Text & vbCrLf & vbCrLf & txtmain.Text & vbCrLf & vbCrLf & "_____________________________________________________________________")
            saveToday.Close()

        Else
            txtmain.Focus()
        End If

    End Sub

推荐答案

Hi

以下代码显示了一种实现方法.

Here is code to show one way to do it.

此示例将打开Form1,其中包含一些文本,然后是图片,然后是其他文本.您需要编辑Path变量和文件名来测试此代码.

This example will open Form1 with some text, followed by a picture and then some more text. You would need to edit the Path variable and the filenames to test this code.

有两个按钮,一个按钮仅清除RTB,另一个按钮重新加载已保存的RTF文件.

There are two buttons, one just clears the RTB the other reloads the saved RTF file.

Option Strict On
Option Explicit On
Public Class Form1
    ' edit this line for a Path to an image
    Dim Path As String = "C:\Users\Les\Desktop\Dice 2\"

    ' edit this line for an image filename
    Dim img As Image = Image.FromFile(Path & "11.png")
    Private Sub Form1_Load(sender As System.Object, e As EventArgs) Handles MyBase.Load
        RichTextBox1.AppendText("This is a complete illusion" & vbCrLf)

        Dim current As IDataObject = Clipboard.GetDataObject
        Clipboard.SetImage(img)
        RichTextBox1.Paste()
        Clipboard.SetDataObject(current)
        RichTextBox1.AppendText(vbCrLf & "This, on the other hand; isn't!")

        ' save the RTF to file in same path as image
        ' change to suit (change below as well)
        RichTextBox1.SaveFile(Path & "DummyRTF.rtf", RichTextBoxStreamType.RichText)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' this button click will erase everything in the RTB
        RichTextBox1.Clear()
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        ' this button click will reload from saved file (should result in exactly the same contents)
        RichTextBox1.LoadFile(Path & "DummyRTF.rtf", RichTextBoxStreamType.RichText)
    End Sub
End Class


这篇关于如何将照片添加到richtextbox,然后从那里将其保存为rtf文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆