Link to home
Start Free TrialLog in
Avatar of TheFunkSoulBrother
TheFunkSoulBrother

asked on

VBA: Drawing in a form || Mouseevent in report

I'm developing an Access2000 application and I need either to DRAW RECTANGLES IN A FORM (by VBA) or to CATCH MOUSEEVENTS (specificly the mouse coordinates) IN A REPORT (by VBA)

I managed to draw rectangles in a report and I managed to get the mouse coordinated in a form, but I need both, drawing rectangles and getting mouse coordinated - either in a form or in a report.

By the way: How can the X and Y coordinates of MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) be converted to Pixel?
ASKER CERTIFIED SOLUTION
Avatar of thenelson
thenelson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello,

As Nelson said, you can't get the mouse move events on a report. What's more you can't draw or create rectangles on forms. Nelson's suggestion of CreateControl() works only in design mode, so that it's probably useless in your case.

When I need to "create" a rectangle or a line on a form dynamically, I create it at design time and set its "Visible" property to false. I then make it visible through code when needed.

As for pixels and twips, I confess that I usually get lazy and simply use 15 twips = 1 pixel, this corresponding to the default 96 pixel/inch resolution. Formally, you would have to ask Windows what the current metrics are, using Nelson's link, or this one which seems a little less complex:

http://www.applecore99.com/api/api012.asp

Also note that all mouse events coordinates are relative to the object, (0,0) being the top left corner of the object. You can use a control's .Top and .Left properties to convert them to coordinates relative to the form. If you need absolute screen coordinates, it gets complex again, as you need  more API calls to get the form's position on the screen.

Good luck
(°v°)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TheFunkSoulBrother
TheFunkSoulBrother

ASKER

Thanks very much,
I think it will work fine whith the CreateControl method, if it's possible to assign eventhandlers to a so created control.

Specificly I'd need to assign a Click() eventhandler to the ctRect
Well. The CreateControl method is available only in design view. So you can adjust all properties, including the strings for the event handlers. Use "=SomeFunction()" or "[Event procedure]" to call a VB handler. The handlers can of course be written through code as well, which is exactly what some of the control wizards do.

But again, there is no way to create any control on a form in form view. If you need a rectangle to pop-up as a response to some user interaction, that rectangle must exist beforehand.

Cheers!
(°v°)
In my case it doesn't matter that CreateControl is only available in design view because I always redraw the whole form - so first, I open the form in design view, create rectangles an add eventhandlers, then I save the form, close it and open it in normal view.

Thanks a lot!
Glad to help.