suis


Hi everybody,

i am using a rich text box to display data ,

now my problem is, in my rich text box i used to diplay text string and some image object.

so i need to seperate these two text string and image object in the rich text box



is there any way to do this

help me..
regards

suis






Re: How to seperate data from the Rightextbox ?

Riquel Dong – MSFT


Hi Suis,

Based on your post, my understanding of your question is that you need to get the image from the richtextbox control.

In this scenario we need to use use interoperability with Win32 Clipboard API to resolve this problem. We use clipboard to copy image and then get image from the clipboard. For more information about how to extract the image from richtextbox control, Please visit: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1453484&SiteId=1. You can use RichTextBox.Text to get all text in the richtextbox control. Hope this helps.

Best regards,

Riquel






Re: How to seperate data from the Rightextbox ?

suis

Hi

Many thanks for u r comments and the link that u provided me,
i have abug in my code .

because i used this code in my button click event

RichTextBox2.LoadFile("E:\Rtf Path\11.rtf")

RichTextBox2.Copy()


If OpenClipboard(Me.Handle) Then

Dim aa As System.Drawing.Imaging.WmfPlaceableFileHeader

Dim MF As New Metafile(GetClipboardData(CF_ENHMETAFILE), True)

MF.Save("C:\MF.jpg", ImageFormat.Jpeg)

End If



but when it comes to this line : Dim MF As New Metafile(GetClipboardData(CF_ENHMETAFILE), True)

i am getting an Error Call : "Parameter is not valid "

any idea
regards
suis










Re: How to seperate data from the Rightextbox ?

Riquel Dong – MSFT

Hi Suis,

This method only works well when you first select a image object in the richtextbox control. Here is the code snippet about this method. I modify it from the above thread by adding CloseClipboard() API.

Code Block

Imports System.Drawing.Imaging

Imports System.Runtime.InteropServices

Public Class Form14

Public Const CF_ENHMETAFILE As Integer = 14

<DllImport("user32.dll", EntryPoint:="OpenClipboard", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function OpenClipboard(ByVal hWnd As IntPtr) As Boolean

End Function

<DllImport("user32.dll", EntryPoint:="GetClipboardData", SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _

Public Shared Function GetClipboardData(ByVal uFormat As Integer) As IntPtr

End Function

<DllImport("user32.dll")> Private Shared Function CloseClipboard() As Boolean

End Function

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

RichTextBox1.LoadFile("C:\testimg.rtf")

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

RichTextBox1.Copy()

If OpenClipboard(Me.Handle) Then

Try

Dim MF As New Metafile(GetClipboardData(CF_ENHMETAFILE), True)

MF.Save("C:\MF.bmp", ImageFormat.Bmp)

CloseClipboard()

Catch ex As Exception

MessageBox.Show(ex.Message + "You need to select a image object")

End Try

End If

End Sub

End Class

Best regards,

Riquel






Re: How to seperate data from the Rightextbox ?

suis


Hi Riquel,

So many thanks to u r post, u r code is working perfectly.

but there is a small problem i am facing , problem is i have a collection of .RTF document ( morethan 100 thousends) ,
so each.RTF document will contaning morethan one image object inside that .RTF document.

SO i need to find out a way to select a specific image object without using a mouse , and then save it. because i cant select morethan 100 thousends of .RTF document using a mouse.....

any idea to select that image object without using a mouse

please help me.

regards
suis








Re: How to seperate data from the Rightextbox ?

suis

Hi Riquel

Finally i have to save many thanks for u r coding.....

i really appriciate U R valuable code ,,,,,,,

many thanks to .MSDN forum..

i could manage to sort out my problem

regards
suis








Re: How to seperate data from the Rightextbox ?

nullstring

hi! could you convert this to C#

thank you so much!




Re: How to seperate data from the Rightextbox ?

suis

Hi ,

Here is the link to convert C# to vb OR vb to c#

http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

try u r self

good luck

regards
suis