Re: The use of scale when making af 2D plot
- From: Nigo <nikolajkyndbyholm@xxxxxxxxx>
- Date: Thu, 27 Sep 2007 17:58:28 -0000
On Sep 27, 6:35 pm, Mike Williams <gagam...@xxxxxxxxxxx> wrote:
On 27 Sep, 15:44, Nigo <nikolajkyndbyh...@xxxxxxxxx> wrote:
I'm trying to draw a simple 2D graph (tried
MSChart and it doesn't do the trick for me)
using simple line-commands. The graph is
470x470 pixels and has top left corner in
(104,24) pixels on my form. I thought pixels
would be nice to use as scalemode as its
supposed to work on many different screen
res. even down to 600x800 (!)
The Scalemode doesn't really matter. Just use whatever scale units
suit your purposes you best. All that really matters is that your
graph is at your desired aspect ratio and that the logical size of
your graph is such that it fits inside the client area of your Form
and that the Form itself fits inside the available screen area after
taking into account the size and position of the user's taskbar and
other similar bars. This is all very easy to check in code. The actual
pixel size of the graph is normally a secondary consideration.
However, in your specific case you are unlikely to run into problems
if you do make the graph exactly 470 x 470 pixels unless your code is
ever likely to be run on a 640 x 480 display (very unusual these
days). The best way would be to draw your graph in a VB Picture Box of
a suitable size and you will be able to place that PictureBox at any
suitable location on your Form. I'm not sure whether you want the
borders of the Picture Box to show, but the following code should size
it correctly for you regardless. The code currently creates a
borderless picbox and positions it at location 104, 24 on the Form and
then sizes it to your required pixel size and then sets up its Scale
property so that there it has a Scale size of 470 x 10 scale units
with coordinate (0, 0) being at the bottom left corner and with
increasing positive values of y moving upwards on the graph. I haven't
yet included any code to either position or size your Form itself
because I'm not sure what else you are displaying on it, but it will
be very easy to add that code later.
Anyway, try the following example and post back if you have any
problems with it. Just paste the code into a VB Form containing a
Picture Box. The code contains enough comments to enable you to see
how it works and it will work fine unless your user is running at 640
x 480 (highly uinlikely) or at 800 x 600 with an unusually large
taskbar (again, highly unlikely). But if you're worried about those
possibilities then it is very easy to amend the code to deal with
them.
Mike
Option Explicit
Private Sub Form_Load()
Dim xB As Long, yB As Long
Me.ScaleMode = vbPixels
With Picture1
.AutoRedraw = True
.BackColor = vbWhite
.BorderStyle = vbBSNone ' if you want no border
.ScaleMode = vbPixels
.Move 104, 24 ' desired position on Form
' find the size of the borders (if any)
xB = .Width - .ScaleWidth
yB = .Height - .ScaleHeight
' set the pixel size of the client picbox area
.Width = 470 + xB
.Height = 470 + yB
' set the scale to 470, 10 with reversed y coords
Picture1.Scale (0, 0)-(470, -10)
' set the origin so that y = 0 is at the bottom
.ScaleTop = 10
End With
' draw some test stuff
Picture1.Line (0, 0)-(470, 10), vbGreen
Picture1.Circle (0, 0), 10, vbRed
Picture1.Circle (470, 10), 10, vbBlue
End Sub
Absolutely fantastic! Thank you very much :-)
.
- References:
- The use of scale when making af 2D plot
- From: Nigo
- Re: The use of scale when making af 2D plot
- From: Mike Williams
- The use of scale when making af 2D plot
- Prev by Date: Re: The use of scale when making af 2D plot
- Next by Date: How to disable Start menu or prevent it to open?
- Previous by thread: Re: The use of scale when making af 2D plot
- Next by thread: How to disable Start menu or prevent it to open?
- Index(es):
Relevant Pages
|