Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Move & resize a Picture control at run-time

Status
Not open for further replies.

MarcMellor

Programmer
Jan 12, 2002
34
US
I am a science teacher trying to design an educational assessment program using VB6 (Pro). My Visual Basic is entirely self-taught.
I currently have a Picture control inside a Rich TextBox control into which I am able to copy diagrams at run-time. This works fine and the Picture control automatically resizes to the correct dimensions of the original diagram.
My problem are these -
- I need to be able to reposition the diagram at run time using the mouse in exactly the same way as it can be done at design-time.
- I need those handle-bars to appear when it is selected so that when the corner handle-bar is moved, the diagram is re-sized maintaining its horizontal to vertical proportions, and when the side or top handle bars are moved, the diagram is resized in the vertical or horizontal directions respectively with these proportions not maintained.
- As the diagram will be stored in a database I may need a way of recording the current top, left, width and height properties with it in the database so that when it is recalled , it is correctly positioned and dimensioned (or will this happen automatically?)
- I also need to have the background to the diagram invisible so that typing in the Rich TextBox underneath it can be seen.
I'm sure this can be done (it works at design-time) but the best I have managed so far is for the Picture control to be moved where it seems to feel like!
Any help with this would be greatly appreciated, especially as I seem to be generating new ideas (with their inevitable problems) substantially faster than I am solving old ones.
 
There are a few api's that you can use to resize the control like in design time. It is not an automatic thing to my knowledge. Anytime I do something like that, I write the code to support the resizing.

Making a picture box to have a transparent background involves several api calls. The image control supports transparency straight out of VB, so that my be a better way to go. Although I'm not sure how that will interact with your rich text box control.

Getting the dimensions of a control should be easy. Use the top, left, width, and height properties of the control and save them to your database.
 
My, a reply already! Thanks VBGuyUsingVCp
Unfortunately "Rank Amateur" was not one of the choices available to me as a personal description and "Programmer" is wishful thinking on my part! I'm afraid I don't even know what an "api" is. My problem is I don't know how to write the code needed. I presume that as you move the mouse pointer around the form, VB keeps tabs on its X and Y position. Then variables for these can be fixed in the MouseDown_Click event and from this, there is a way of relating the mouse position to the current Top and Left position of the Picture control and then ...... and here I start to get lost!
 
Hi,

API stands for Application Programmers Interface (I believe). It is the backbone for programming in Windows. Most of your VB code is really API call behind the scenes at one level or another. They are very powerful and usefull. However they were really designed with C++ in mind, since almost all API documentation is in C++.

You are right that VB provides several mouse events that keep track of the mouse pointer relative to the control it is over. To simply move the control you may want to use the drag mode property given by VB. Look up drag mode and you should find some helpful documentation. Even still, you have to do alot of relative math to get it to move like you want. For instance, you would need to keep track of the point the mouse was first clicked and it's relative position to the container (which is the rich text box in your case) and also keep track of the relative end position and some other points. Then you will have to add code in the object that it is drop on when you move it.

To resize can call for other objects that need to keep track of the position of the mouse plus a host of relative points, because the resize handles will probably be different controls with differents events of its own.

I will try to dig up some old code that I have or see if there is simple way to do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top