Solved

Richtextbox and images

Posted on 2000-02-18
15
1,020 Views
Last Modified: 2007-10-18
Hello...you gotta read this carefully to understand:)

When I paste an Image from the clipboard I want to add somekind of Identifyer to it, like an index.
I dont want to use the Richtextbox1.oleobjects.add , , ,
I want it directly from the clipboard.

All pasted Images are countable using the Richtextbox.oleobjects.count method.
But as I said, I want to be able to know all the pasted Images Item properties. So that I can use the Richtextbox.oleobjects.item(?) command.

Once again, I know how to add an object and that I can use the .item method with them. But I need to be able to use it with pasted images aswell..

Thanx! /Dan
0
Comment
Question by:neo24
  • 8
  • 6
15 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2536348
If I understand your question, you have an image on the clipboard and you want to paste it into a RichTextBox and have the RichTextBox.OleObjects.Item work...

Here's how:

Copy an image to the clipboard and the execute the following statements:

     Debug.Print RichTextBox1.OLEObjects.Count
     RichTextBox1.SetFocus
     SendKeys "^v"
     Debug.Print RichTextBox1.OLEObjects.Count


Notice that before the sendkeys the number of OLEObjects in the richtextbox goes to the DEBUG window and is 0... After the sendkeys, the count is 1.

Hope this helps!


Cheers!
0
 

Author Comment

by:neo24
ID: 2536604
hmm...
I want be able to get somekind of index when I click on the pasted image.
or just be able to use OLEObjects.Item.index(?).remove.
Not to confuse with the oleobjects.clear
event.

Thank you anyways:)

/Dan
0
 
LVL 6

Expert Comment

by:Marine
ID: 2536619
Can you place these paste images into an array they you can access it probably as you like it.
0
 

Author Comment

by:neo24
ID: 2536626
Show me how!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2537103
I get what you're trying to do... You are trying to identify the graphic that you are clicking on in the RichText Control, YES???

The problem is, you can't do that... And here's why:

When you add an image to the RTF by either pasting or doing an .Add, the system assigns an Item under the OLEObjects property of the RichTextBox. Let's we add two images. They become:

    richtextbox1.OLEObjects.Item(0)

                -and-

    richtextbox1.OLEObjects.Item(1)

The reason you cant identify which one of these you have clicked on is becase OLEObjects only has the following properties:  Add, Clear, Count, Item, and Remove... There IS NO INDEX PROPERTY and the only event that fires when you click on the image is the CLICK EVENT... Which does not set any variable specifying which image was clicked.

I have an Idea how to get around this, but it will take some time to code.

Tell me if I'm on the right track...  If I am on the right track, I hope you will be more generous with the points when I post the code...


Cheers!

     
0
 

Author Comment

by:neo24
ID: 2537805
You are defenetly on the right track!

0
 

Author Comment

by:neo24
ID: 2537808
Adjusted points to 175
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:neo24
ID: 2537821
I thought of something,
when I paste a picture I can always know which Item it is, cause it starts with oleobjects.item(0). At the moment of pasting, I can also assign a key to the image. RTF.Oleobjects.Item(0).Key="Whatever" . Maybe this can help you out. And I will give you more points, you can have them all.
0
 
LVL 14

Accepted Solution

by:
mcrider earned 170 total points
ID: 2537853
The problem with your idea is that you still don't know when you've clicked on one of the images... BUT...HERE YOU GO!

This is a full example program.

1) Create a new project and add a RichTextBox and 2 command buttons to FORM1.

2) Add the following code to the DECLARATIONS SECTION of FORM1:

'-------------------------------------------------------------------------------
    Private Sub Command1_Click()
        RTFaddObj
    End Sub
    Private Sub Command2_Click()
        RTFdelObj
    End Sub
    Private Sub Form_Load()
        'INITIALIZE THE RTF CLICK ROUTINES FOR RichTextBox1
        RTFInitClick RichTextBox1
        Command1.Caption = "Insert Obj"
        Command2.Caption = "Delete Obj"
    End Sub
    Private Sub RichTextBox1_Click()
        Dim iVal As Long
        Dim jVal As Long
       
        On Error Resume Next
        RTFobjClicked = -1
        iVal = UBound(RTFobjInfo)
        If Err > 0 Or RTFobject.SelLength <> 1 Then Exit Sub
        For jVal = 0 To iVal
            If RTFobjInfo(jVal) = RTFobject.SelStart Then
                RTFobjClicked = jVal
                Debug.Print "THIS IS " & CStr(RTFobjClicked)
            End If
        Next jVal
    End Sub
    Private Sub RichTextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case 86 And Shift = 2, 45 And Shift = 1 'CTL-V or SHIFT-INS Paste
                RTFaddObj
            Case 46 And Shift = 0 'DELETE Key
                RTFdelObj
            Case 8 And Shift = 0 'BACKSPACE Key
                RTFdelObj True
        End Select
    End Sub
'-------------------------------------------------------------------------------



3) Add a MODULE to your project and put the following code in the DECLARATIONS SECTION of the MODULE:

'-------------------------------------------------------------------------------
    Public RTFobjInfo() As Long
    Public RTFobjClicked As Long
    Public RTFobject As Object
    Public RTFSubRunning As Boolean
    Sub RTFInitClick(RichTextBoxObject As Object, Optional EndInit As Boolean)
        RTFobjClicked = -1
        RTFSubRunning = False
        If EndInit = False Then
            Set RTFobject = RichTextBoxObject
        Else
            Set RTFobject = Nothing
        End If
    End Sub
    Sub RTFaddObj()
        Dim iVal As Long
        Dim jVal As Long
       
        On Error Resume Next
        If RTFSubRunning = True Then Exit Sub
       
        iVal = UBound(RTFobjInfo)
        If Err = 0 Then
            iVal = iVal + 1
        Else
            ReDim RTFobjInfo(0) As Long
            iVal = 0
        End If
        ReDim Preserve RTFobjInfo(iVal) As Long
        RTFobjInfo(iVal) = RTFobject.SelStart
        For jVal = LBound(RTFobjInfo) To iVal - 1
            If RTFobjInfo(iVal) <= RTFobjInfo(jVal) Then
                RTFobjInfo(jVal) = RTFobjInfo(jVal) + 1
            End If
        Next jVal
        QNumSort RTFobjInfo
        RTFSubRunning = True
        RTFobject.SetFocus
        SendKeys "^v", True
        RTFSubRunning = False
    End Sub
    Sub RTFdelObj(Optional UseBS As Boolean)
        Dim iVal As Long
        Dim jVal As Long
       
        On Error Resume Next
        If RTFSubRunning = True Then Exit Sub
        fSwitch = False
        iVal = UBound(RTFobjInfo)
        If Err > 0 Or RTFobjClicked = -1 Then Exit Sub
        For jVal = RTFobjClicked To iVal - 1
            RTFobjInfo(jVal) = RTFobjInfo(jVal + 1) - 1
        Next jVal
        ReDim Preserve RTFobjInfo(iVal - 1) As Long
        RTFobject.SetFocus
        RTFSubRunning = True
        If UseBS = True Then
            SendKeys "{BS}", True
        Else
            SendKeys "{DEL}", True
        End If
        RTFSubRunning = False
        RTFobjClicked = -1
    End Sub
    Sub QNumSort(InArray As Variant)
        'THIS FUNCTION SORTS A NUMERIC ARRAY
        Dim lLoop1 As Long
        Dim lLoop2 As Long
        Dim tBuf As Variant
        For lLoop1 = UBound(InArray) To LBound(InArray) Step -1
            For lLoop2 = LBound(InArray) + 1 To lLoop1
                If InArray(lLoop2 - 1) > InArray(lLoop2) Then
                    tBuf = InArray(lLoop2 - 1)
                    InArray(lLoop2 - 1) = InArray(lLoop2)
                    InArray(lLoop2) = tBuf
                End If
            Next lLoop2
        Next lLoop1
    End Sub

'-------------------------------------------------------------------------------



4) Run the program.

5) Copy a picture onto the clipboard from another application.

6) Click the "Insert Obj" button to paste the image into the richtextbox... Do this a couple more times, so there about 2 or 3 pictures in the richtextbox.

7) Now, click on a picture and watch the debug window... When you click on a picture the messagebox in the RichTextbox CLICK EVENT will fire and display the index number of the image. This is the index number you wanted.

8) Click on a picture and then click the "Delete Obj" button.  The selected picture will go away, and the image indexes will be reordered.  Once you have deleted a picture, repeat step 7 to see that the correct numbers show up in the debug window.

This example should do everything you wanted...  I even included code so that the user can paste an image into the richtextbox by copying the image to the clipboard and pressing CTL-V in the richtextbox.

This was ALOT of work!  Hope this works for you...



Cheers!

0
 
LVL 14

Expert Comment

by:mcrider
ID: 2537859
RE: Step 7... I said messagebox, I meant Debug.Print



Cheers!
0
 

Author Comment

by:neo24
ID: 2537893
Hey man Thanx. I will e-mail you and tell you how to get even more points. My friend is gonna give you 200 points aswell for this.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2537896
neo24,

Just open a new question in this category with the title "FOR MCRIDER ONLY" and I will answer it...

Thanks for the points! Glad I could help!


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2537898
By the way, don't forget to mention this question Q.10297532 when you open the new question... ;-)


Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2539471
Neo24,

Is Geo24 and Neo24 the same person? There has been a complaint... See http://www.experts-exchange.com/jsp/qShow.jsp?ta=commspt&qid=10298051  

If they are not the same person, I would go to the above thread and defend myself...

Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2576943
Neo24, Are you still there?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now