Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

[VB2010]- RichTextBox - working with images

$
0
0
i did these code for trying Align the image with text:
Code:

Imports System.Runtime.InteropServices.ComTypes
Imports System.Runtime.InteropServices

Public Class Form1

    Private Structure _RICHEDIT_IMAGE_PARAMETERS
        Dim xWidth As Long
        Dim xHeight As Long
        Dim Ascent As Long
        Dim Type As Long
        Dim pwszAlternateText As String
        Dim pIStream As IStream
    End Structure

    Private Const WM_USER = &H400
    Private Const EM_INSERTIMAGE = (WM_USER + 314)
    Private Const TA_BASELINE = 24
    Private Const TA_BOTTOM = 8
    Private Const TA_CENTER = 6
    Private Const TA_LEFT = 0
    Private Const TA_MASK = (TA_BASELINE + TA_CENTER + TA_UPDATECP)
    Private Const TA_NOUPDATECP = 0
    Private Const TA_RIGHT = 2
    Private Const TA_TOP = 0
    Private Const TA_UPDATECP = 1


    Dim Para As _RICHEDIT_IMAGE_PARAMETERS

    <DllImport("user32", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
                                    ByVal msg As Integer, _
                                    ByVal wParam As Integer, _
                                    ByRef lParam As _RICHEDIT_IMAGE_PARAMETERS) As Integer
    End Function

    <DllImport("user32", CharSet:=CharSet.Auto)> _
    Private Shared Function SendMessage(ByVal hWnd As HandleRef, _
                                    ByVal msg As Integer, _
                                    ByVal wParam As Integer, _
                                    ByVal lParam As Integer) As Boolean
    End Function

    'alignment
    'TA_BASELINE - Align the image relative to the text baseline.
    'TA_BOTTOM - Align the bottom of the image at the bottom of the text line.
    'TA_TOP-Align the top of the image at the top of the text line

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Clipboard.SetImage(PictureBox1.Image)
        RichTextBox1.Paste()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        With Para
            .Ascent = 0
            .Type = TA_BOTTOM
        End With
        SendMessage(New HandleRef(RichTextBox1, RichTextBox1.Handle), _
                                  EM_INSERTIMAGE, _
                                  0, _
                                  Para)
    End Sub

End Class

seems to be ignored:(
can anyone advice me?

Viewing all articles
Browse latest Browse all 168

Trending Articles