Solved

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

Posted on 2004-04-23
5
389 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

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

Join & Write a Comment

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now