Solved

Is there a way to Edit or Open a Picture control at Runtime?

Posted on 2004-04-23
5
391 Views
Last Modified: 2013-12-26
In VB6: When I select Project / Components, go to the Insertable Objects tab, and tick "Bitmap Image" (MSPAINT.exe), then click on the "Picture" icon on the Palette & draw one on my Form...

At Design Time, I can right-click that Picture control and select Edit, and voila!  I can draw free-form right in the picture!  Or I can right-click and Open to bring up MSPAINT and edit it with all the Paint features, and when I close, the changes are copied back to the form.  That's great, but...

Question:
How do I do that at RUNTIME?

I want to include a little drawable area in my form, at least with freeform drawing and ability to enter and position your own text.  I can handle saving and loading that bitmap to/from a file at the appropriate times.

But how do I talk to that MSPAINT.EXE invocation that seems to be loaded??

Or is there another Control or OCX that would let me do that?

Thanks in advance if you can help!
0
Comment
Question by:nicthu
  • 3
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10899472
Just add a PictureBox to your form and use this code to allow the user to draw on it:

Option Explicit

Dim lastX As Single
Dim lastY As Single
Dim mouseIsDown As Boolean

Private Sub Form_Load()
    Picture1.AutoRedraw = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        lastX = X
        lastY = Y
        mouseIsDown = True
    End If
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If mouseIsDown Then
        Picture1.Line (lastX, lastY)-(X, Y)
        lastX = X
        lastY = Y
    End If
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    mouseIsDown = False
End Sub
0
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 125 total points
ID: 10902320
I don't know if you can do that by inserting the Bitmap Image directly, but I know this'll work.

Insert an OLE control.  Tell it to create a Bitmap image (or any other type of object you might want to do this with).  Then, at run-time:

ole1.DoVerb -1 'edit in-frame, if supported; otherwise, open in new window
ole1.DoVerb -2 'open in own window

0
 
LVL 1

Author Comment

by:nicthu
ID: 10905178
Which OLE control do I insert?
Or where do I find such an OLE control?
0
 
LVL 1

Author Comment

by:nicthu
ID: 10905660
Nevermind, I found it on the Palette!

Awesome -- you get the points, dude!

p.s.  Is there another DoVerb for "Save current object to a file"?
0
 
LVL 1

Author Comment

by:nicthu
ID: 10908033
Nevermind again, I found the ReadFromFile and SaveToFile methods!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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