Click here to Skip to main content
15,915,818 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Archive or backup Pin
DaveAuld15-Jul-10 4:10
professionalDaveAuld15-Jul-10 4:10 
Questionhow to use winsock to exchange data in 2 diferent exe Pin
zhiyuan1613-Jul-10 18:39
zhiyuan1613-Jul-10 18:39 
AnswerRe: how to use winsock to exchange data in 2 diferent exe Pin
Eddy Vluggen14-Jul-10 3:07
professionalEddy Vluggen14-Jul-10 3:07 
AnswerRe: how to use winsock to exchange data in 2 diferent exe Pin
Аslam Iqbal14-Jul-10 9:01
professionalАslam Iqbal14-Jul-10 9:01 
Questioncolumntype checkbox does not chech Pin
Ebube13-Jul-10 5:42
Ebube13-Jul-10 5:42 
AnswerRe: columntype checkbox does not chech Pin
Scubapro14-Jul-10 0:55
Scubapro14-Jul-10 0:55 
GeneralRe: columntype checkbox does not chech Pin
Ebube14-Jul-10 4:43
Ebube14-Jul-10 4:43 
QuestionRTF IMAGE INSERTION Pin
djdrew12-Jul-10 5:35
djdrew12-Jul-10 5:35 
I am using the following borrowed code to insert an image into an RTF, as that aspect of RTF seemed way beyond me

[code]Public Sub InsertImage(ByVal _image As Image)
Dim _rtf As New StringBuilder()
' Append the RTF header
_rtf.Append(RTF_HEADER)
' Create the font table using the RichTextBox's current font and append
' it to the RTF string
_rtf.Append(GetFontTable(Me.Font))
' Create the image control string and append it to the RTF string
_rtf.Append(GetImagePrefix(_image))
' Create the Windows Metafile and append its bytes in HEX format
_rtf.Append(GetRtfImage(_image))
' Close the RTF image control string
_rtf.Append(RTF_IMAGE_POST)
Me.SelectedRtf = _rtf.ToString()
End Sub
Private Function GetImagePrefix(ByVal _image As Image) As String
Dim _rtf As New StringBuilder()
' Calculate the current width of the image in (0.01)mm
Dim picw As Integer = CType(Math.Round((_image.Width / xDpi) * HMM_PER_INCH), Integer)
' Calculate the current height of the image in (0.01)mm
Dim pich As Integer = CType(Math.Round((_image.Height / yDpi) * HMM_PER_INCH), Integer)
' Calculate the target width of the image in twips
Dim picwgoal As Integer = CType(Math.Round((_image.Width / xDpi) * TWIPS_PER_INCH), Integer)
' Calculate the target height of the image in twips
Dim pichgoal As Integer = CType(Math.Round((_image.Height / yDpi) * TWIPS_PER_INCH), Integer)

' Append values to RTF string
_rtf.Append("{\pict\wmetafile8")
_rtf.Append("\picw")
_rtf.Append(picw)
_rtf.Append("\pich")
_rtf.Append(pich)
_rtf.Append("\picwgoal")
_rtf.Append(picwgoal)
_rtf.Append("\pichgoal")
_rtf.Append(picw)
_rtf.Append(" ")
Return _rtf.ToString()
End Function
<DllImportAttribute("gdiplus.dll")> _
Private Shared Function GdipEmfToWmfBits(ByVal _hEmf As IntPtr, ByVal _bufferSize As UInt32, ByVal _buffer As Byte(), ByVal _mappingMode As Integer, ByVal _flags As EmfToWmfBitsFlags) As UInt32
End Function
''' <summary>
''' Wraps the image in an Enhanced Metafile by drawing the image onto the
''' graphics context, then converts the Enhanced Metafile to a Windows
''' Metafile, and finally appends the bits of the Windows Metafile in HEX
''' to a string and returns the string.
''' </summary>
''' <param name="_image"></param>
''' <returns>
''' A string containing the bits of a Windows Metafile in HEX
''' </returns>
Private Function GetRtfImage(ByVal _image As Image) As String
Dim _rtf As StringBuilder = Nothing
' Used to store the enhanced metafile
Dim _stream As MemoryStream = Nothing
' Used to create the metafile and draw the image
Dim _graphics As Graphics = Nothing
' The enhanced metafile
Dim _metaFile As Metafile = Nothing
' Handle to the device context used to create the metafile
Dim _hdc As IntPtr
Try
_rtf = New StringBuilder()
_stream = New MemoryStream()
' Get a graphics context from the RichTextBox
Using _graphics1 As Graphics = Me.CreateGraphics()
' Get the device context from the graphics context
_hdc = _graphics1.GetHdc()
' Create a new Enhanced Metafile from the device context
_metaFile = New Metafile(_stream, _hdc)
' Release the device context
_graphics1.ReleaseHdc(_hdc)
End Using
' Get a graphics context from the Enhanced Metafile
Using _graphics1 As Graphics = Graphics.FromImage(_metaFile)
' Draw the image on the Enhanced Metafile
_graphics1.DrawImage(_image, New Rectangle(0, 0, _image.Width, _image.Height))
End Using
' Get the handle of the Enhanced Metafile
Dim _hEmf As IntPtr = _metaFile.GetHenhmetafile()
' A call to EmfToWmfBits with a null buffer return the size of the
' buffer need to store the WMF bits. Use this to get the buffer
' size.
Dim _bufferSize As UInt32 = GdipEmfToWmfBits(_hEmf, 0, Nothing, MM_ANISOTROPIC, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault)
' Create an array to hold the bits
Dim _buffer As Byte() = New Byte(CInt(_bufferSize)) {}
' A call to EmfToWmfBits with a valid buffer copies the bits into the
' buffer an returns the number of bits in the WMF.
Dim _convertedSize As UInt32 = GdipEmfToWmfBits(_hEmf, _bufferSize, _buffer, MM_ANISOTROPIC, EmfToWmfBitsFlags.EmfToWmfBitsFlagsDefault)
For i As Integer = 0 To _buffer.Length - 1
' Append the bits to the RTF string
_rtf.Append([String].Format("{0:X2}", _buffer(i)))
Next
Return _rtf.ToString()
Finally
If _graphics IsNot Nothing Then
_graphics.Dispose()
End If
If _metaFile IsNot Nothing Then
_metaFile.Dispose()
End If
If _stream IsNot Nothing Then
_stream.Close()
End If
End Try
End Function
[/code]

sorry for so much code, anyway if i use that, the image is huge, here is a sample untouched image
i tried inserting the image with wordpad and copying the picw, pich, pichgoal, and picwgoal values from the wordpad generated RTF, but then the image looked almost squeezed together. i did notice the image hex values seemed quite different, i can't simply copy as the image itself will be different each run, I am at a loss, any help is appreciated
AnswerRe: RTF IMAGE INSERTION Pin
Dalek Dave13-Jul-10 4:14
professionalDalek Dave13-Jul-10 4:14 
AnswerRe: RTF IMAGE INSERTION Pin
The Man from U.N.C.L.E.13-Jul-10 6:54
The Man from U.N.C.L.E.13-Jul-10 6:54 
GeneralRe: RTF IMAGE INSERTION Pin
djdrew15-Jul-10 5:23
djdrew15-Jul-10 5:23 
Questionclick one treenode but it didn't response ,why Pin
sanyexian12-Jul-10 3:18
sanyexian12-Jul-10 3:18 
AnswerRe: click one treenode but it didn't response ,why Pin
Simon_Whale12-Jul-10 3:26
Simon_Whale12-Jul-10 3:26 
GeneralRe: click one treenode but it didn't response ,why Pin
sanyexian12-Jul-10 4:34
sanyexian12-Jul-10 4:34 
GeneralRe: click one treenode but it didn't response ,why Pin
Simon_Whale12-Jul-10 4:41
Simon_Whale12-Jul-10 4:41 
GeneralRe: click one treenode but it didn't response ,why Pin
sanyexian12-Jul-10 5:06
sanyexian12-Jul-10 5:06 
AnswerRe: click one treenode but it didn't response ,why Pin
Аslam Iqbal12-Jul-10 11:54
professionalАslam Iqbal12-Jul-10 11:54 
GeneralRe: click one treenode but it didn't response ,why Pin
sanyexian12-Jul-10 20:50
sanyexian12-Jul-10 20:50 
QuestionCopy data from one excel file to another excel file Pin
priyaahh12-Jul-10 0:49
priyaahh12-Jul-10 0:49 
AnswerRe: Copy data from one excel file to another excel file Pin
Syed Wayez Ahmed12-Jul-10 2:49
Syed Wayez Ahmed12-Jul-10 2:49 
GeneralRe: Copy data from one excel file to another excel file Pin
Syed Wayez Ahmed12-Jul-10 3:13
Syed Wayez Ahmed12-Jul-10 3:13 
GeneralRe: Copy data from one excel file to another excel file Pin
priyaahh12-Jul-10 5:22
priyaahh12-Jul-10 5:22 
AnswerRe: Copy data from one excel file to another excel file Pin
Sonhospa12-Jul-10 11:58
Sonhospa12-Jul-10 11:58 
GeneralRe: Copy data from one excel file to another excel file Pin
priyaahh12-Jul-10 18:32
priyaahh12-Jul-10 18:32 
GeneralRe: Copy data from one excel file to another excel file Pin
Syed Wayez Ahmed12-Jul-10 21:18
Syed Wayez Ahmed12-Jul-10 21:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.