Hello Devs!
I have a picture and create several lines and shapes at runtime. It is a type of vertical organization chart. I need to create a way to zoom out and zoom in, so that it affects all the elements created in the picture. Can anyone give me a light. I would like to use the mouse scrooll.
I suspect you are going to have to use metafile graphics or some other vector format in order to accomplish what you want without a lot of scaled re-drawing.
Here's a demo that uses a pre-created "map" image and "zooms to" designated points within it.
BuildZoom is used to graphically define zoom points on the map. Those get saved in Zoom.txt, which can then be used by runs of ZoomIn, the "user program."
Not exactly what you asked for, but contains some techniques that might help. In your case you'd need to "draw" in metafile format first. That's not covered here but there are other threads and demos on doing that, assuming you need to do run time drawing from a database or something.
another solution is to create a memory DC, that you use to "draw" everything, this DC is later used to stretch into any picturebox and sizes.
you can use both GDI and GDI+ for this purpose, or even Direct2D, since it also allow you to stretch without needing to think about memory DC, and it has a bunch of drawing functions that are easy to use.
just a solution, not the best solution, it all depends on how much the OP want to do.
vector graphics is much better, but require more work.
I would go with Direct2D, that is fast and has different draw methods that are easy to work with, and can control dpi.
Here's a demo cobbled together from stuff I already had. I only used a scrollbar for zooming instead of adding the subclassing for the mousewheel. It also flickers when you drag the image, but at least the dragging is responsive. Plenty of room for polishing.
It also doesn't provide any interactivity in the image such as letting the user click on a box to change the caption, etc.
This demo builds up an "org chart" at runtime and then renders that as an EMF image. That EMF image is then presented for viewing with drag-to-move and zoom.
Hello dilettante!
I would like to thank all of you
here from the forum for helping me. In this example, is it possible to generate the rectangles dynamically, searching the data in a mysql table and building the graph vertically?
I understood Devs!
The example sent was very cool. Now ... where I configure not to overlap the rectangles. Example: Ball has Bouncy and Hard. If we had 3 more types directly below ...
So I did it like this:
In the CreatChart.bas module, but the rectangles overlap
With .AddChild("Balls")
.AddChild "Bouncy"
.AddChild "Hard"
.AddChild "A"
.AddChild "B"
.AddChild "C"
Sure, but then the dragging is jerky. I think the answer might be to use Render instead of PaintPicture. Just ran out of interest at the time to play with that.
Sure, but then the dragging is jerky. I think the answer might be to use Render instead of PaintPicture. Just ran out of interest at the time to play with that.
Is is done perfectly here. But perhaps in a older computer it may be a problem.
It seems the "usable compromise" is just causing a Refresh because you're changing the AutoRedraw Mode.
You should get the same effect just leaving .AutoRedraw set to True, and doing a .Refresh where you are setting it to false.
Mouse Movement has a higher priority than Control redrawing, so you get jerky movements with changes to a drawing that are caused by rapid mouse movement if your machine's drawing speed is slow.
So, doing a refresh after drawing makes the drawing appear more responsive when dragging, since essentially you will be refreshing the control as fast as is possible, rather than delaying the draw to process MouseMove events.
Last edited by passel; Jul 7th, 2020 at 08:38 PM.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
Also, for dilettante's example, I like to see the zoom happen when you move the thumb on the scrollbar, so I would add the code from the vsbZoom_Change to a vsbZoom_Scroll() sub, or put the code in its own sub and call it from both.
Personally, since it is only two executable lines, I would just duplicate the code in each, rather than add the overhead of another sub call.
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
I fixed a few bugs and added some extensions to my MakeEMF class. I no longer needed a RECT class anyway (turns out I didn't choose to store the RECT as a ChartNode property) so that was replaced by a UDT here instead.
I didn't match your colors, I just picked some close ones.
Hopefully you can get the idea by reading the code.
There seem to be some GDI object/handle leaks. I fixed a few I found and re-posted the attachment.
In any case be sure to scrutinize any code carefully before taking it to use and committing it to production.
Last edited by dilettante; Jul 15th, 2020 at 01:15 PM.
Thank for share your knowlege and teache me.
I would very much like to delve into graphic api. Although vb6 is in decline, but I like it too much. You would have an indication for me to migrate to these graphic apis. Or even a book to guide my learning?
I already thank you immensely.
Hello !
How would I go about searching names dynamically in a database?
Let's say that each line below the President, I consider a level.
Let's say I have 3 to 5 levels. Could you give me an example?
Just throwing out an idea, maybe each row might have a "Level" column. Then I'd think about adding an "ID" column if not already present. Then add a "Parent" column that contains the ID of the parent's row (or Null for the root row of the tree).
Then you could SELECT rows WHERE Level and/or Parent or ORDER BY them.
Might get messy depending on the sort of edits you need to do. Is a row a person or a position/role? If people change roles maybe each role row should have a foreign key into a People table.