Can someone show me the .Paint code to draw a rectangle on a canvas that is drawn with 20 pixels gap at the top and to the left and right; and that is sized to the width of the canvas area?
I am just not getting my head around the widths and deltas, so an example that does this will help massively.
[quote=186375:@Phil Corley]Thanks that works, but for my education can you tell me why this doesn’t work (ie. it doesn’t draw to the width of the canvas it is on)…
Dim r As New RectShape
r.Width = g.Width
r.Height = 100
r.FillColor = RGB(0, 200, 0)
g.DrawObject(r, 20, 20)
[/quote]
But according to the documentation it shouldn’t. The help says “The optional parameters DeltaX and DeltaY are offsets from the top-left corner of the Graphics object to the top-left corner of the Object.”
my experience is that Obj2D shapes always draw from the center.
And they consume more overhead if all you need are simple lines, rectangles, or ovals (circle)
Dave - so if all I need to draw is boxes, lines and text on a canvas, what should I use? I thought RectShape was the way to do the boxes, but still learning so there may be a better way?
DrawLine
DrawRect
DrawOval
FillRect
FillOval
there is also a polygon method , but I don’t recall it off the top of my head
These are much faster that the Obj2d, and remember one IMPORTANT THING (especially if you come from a VB background)… The XOJO Canvas is NON-PERSISTENT, unlike the VB PictureBox
Use the Obj2d if you have complex shapes (bezier curves, etc)
The Object2D classes are nice if you need to implement scaling and rotation of your objects. These things are incredibly hard to do (not impossible though) with the standard graphics class. If you’re going to do rotation of text you’ll almost always have to use Object2D unless you go through a plugin.
Thanks Bob - hopefully I won’t need the Object2D stuff as the needs are simple - produce a simple report on screen and also be able to print it off; so I am assuming I will be able to reuse the code to display to a canvas in a window and also to route to a printer canvas. He hopes
If you develop for Target Win32 than Object2D is something you should use for some stuff like RoundRect (esp. if they are small) you will see a difference from the render engine. But they sure have more overhead and are slower.
Also be aware that the graphics objects have different resolutions so you’ll have to do the internal math for display versus print.
FWIW, we have a set of reporting classes that helps simplify some of this. BKeeney Shorts is set of reporting classes that allows you to render to screen, printer, html, and PDF (using the MBS DynaPDF plugin). It doesn’t have a GUI designer and it’s strength is that you get to control everything. It’s drawback is that you get to control everything. More information at http://www.bkeeney.com/allproducts/bkeeney-shorts/