Re: Displaying images on form...
- From: "Co" <vonclausowitz@xxxxxxxxx>
- Date: 22 Oct 2006 00:33:41 -0700
Mike,
your code works in a new project but when I try it in my form it still
is not right.
The circle is way too small and placed somewhere bottom right on the
form.
Marco
Mike Williams schreef:
"Co" <vonclausowitz@xxxxxxxxx> wrote in message
news:1161431715.576196.287360@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi All, I'm trying to display some images on a form in circle.
But since the forms width is bigger then the height the circle
is not round but more of an egg.
The shape of your circle has got nothing to do with the relationship between
the width and the height of your Form. Your code as it stands isn't actually
getting the positions entirely correct, but it is close to being correct.
Also it is not making any adjustments to the radius in an attempt to follow
the aspect ratio of the Form, so it should result in a circular shape, at
least as far as the radius at any point is always the same logical size
(inches, twips, points or whatever ScaleMode you are using). This means that
because Windows uses the same number of "pixels per logical inch" for both
the vertical and the horizontal directions then the radius at any point will
also always have the same "number of pixels" value as the radius at any
other point. So far, so good.
However, the pixels themselves are not necessarily "square" when measured
with a ruler. On some monitors the pixels will be square, and on other
monitors they will not be. And on many machines the "shape" of a pixel will
vary, depending on the current screen area (800 x 600, 1024 x 768, etc,
etc). This is a particular problem on the new "wide screen" monitors,
especially when you are not running the display at the monitor's native
hardware resolution. My own windscreen laptop for example has a native
hardware resolution (screen area) of 1280 x 800 pixels (a ratio of 1.6:1).
When I run it at 1280 x 800 the individual pixels are approximately square.
However, when I run it at 800 x 60 pixels (my own preferred size) or at 1024
x 768 pixels the pixels are quite a bit wider than they are high (because
the actual display has an aspect ratio of 1.6:1 whereas both of those
resolutions have the typical "Windows" ratio of 1.33:1. So, at 1280 x 800
pixels on my own laptop a circle is a circle (it looks like a circle on the
display) whereas at 800 x 600 and 1024 x 768 a circle looks more like an
ellipse (wider than it is high). There is nothing you can do in code to
correct this, because there is no way of knowing the actual physical aspect
ratio of the screen and you cannot therefore compare it to the aspect ratio
of the "pixel area" (800 x 600 or whatever). You can load up all of the
available screen resolutions and your code can make some intelligent guesses
as to what the physical aspect ratio of the screen might be, but you can
never be certain that you have got it right.
For more information on a subject directly related to this stuff have a look
at all messages in the recent thread "screen size" in this newsgroup. In the
meantime, here is your own code, modified slightly so as to position the
dots correctly (your own code was separating them slightly too much and
drawing the last dot on top of the first). When you run the code (on a Form
containing a Command Button) and click the button you should see twelve very
small circles describing a larger circle, each one with an associated
number. If the pixels on your own machine currently happen to be "square"
then the circle will be a fairly accurate circle when you measure the
display with a rule. Otherwise, if your screen pixels are not currently
square, the circle will actually measure as though it was an ellipse.
If this is a real problem to you for any specific reason then you can
display a small window allowing your user to manually resize the window
until it is exactly square (as measured with a rule against the display)
Your code can then check the height and width of the window and set up a
"ratio" variable acfordingly. The rest of your code can then use that ratio
when it draws things rectangles and circles and other things so that their
aspect ratio when measured with a rule against the screen appears to be
correct (a circle look exactly like a circle, for example). This is usually
overkill for most purposes though. After all, people who run machines at
resolutions where their pixels are not "square" are used to things being
slightly distorted on the display and they normally don't have a problem
with it.
Anyway, here's the modified code (pasted in below). Paste it into a VB Form
containing a Command Button. Incidentally, when you post code yourself I
would advise you to post it in such a way that it will run by simply copying
it from the newsgroup message and pasting it into a VB Form containing the
appropriate controls. In that way you will get the best chance of receiving
a response. Yours did not do that, partly because the code was not complete
and partly because some of the lines were "hard wrapped" by whatever it is
you are using to post your messages. When you include your code in a
newsgroup message first of all break any long lines (longer than your "hard
wrap" position) using the standard "space and underscore" method. Then start
a new VB project and copy the code from your own message and paste it into
the Form. If it does not run at your end then it won't run at this end
either!
Mike
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub GetBoxLocations( _
ByVal inNumPoints As Long, ByVal inRadius As Long, _
Optional ByVal inXOff As Long = 0, _
Optional ByVal inYOff As Long = 0, _
Optional ByVal inOffsetRotation As Long = 0)
Dim LoopPts As Long
Dim Radians As Double
Const Pi As Double = 3.14159
Const TwoPi As Double = Pi * 2
If (inNumPoints > 0) Then ' Allocate return array
ReDim boxlocation(0 To inNumPoints - 1) As POINTAPI
For LoopPts = 0 To inNumPoints - 1
Radians = TwoPi * (LoopPts / inNumPoints _
+ inOffsetRotation / 360)
boxlocation(LoopPts).x = (Cos(Radians) * inRadius) _
+ inXOff
boxlocation(LoopPts).y = (Sin(Radians) * inRadius) _
+ inYOff
Circle (boxlocation(LoopPts).x, _
boxlocation(LoopPts).y), 2, vbBlue
Print Format(LoopPts)
Next LoopPts
End If
End Sub
Private Sub Command1_Click()
Me.ScaleMode = vbPixels
Dim x As Long, y As Long
x = Me.ScaleWidth / 2
y = Me.ScaleHeight / 2
GetBoxLocations 12, y * 0.7, x, y, 0
End Sub
Private Sub Form_Load()
Me.WindowState = vbMaximized
End Sub
.
- Follow-Ups:
- Re: Displaying images on form...
- From: Larry Serflaten
- Re: Displaying images on form...
- References:
- Displaying images on form...
- From: Co
- Re: Displaying images on form...
- From: Mike Williams
- Displaying images on form...
- Prev by Date: Re: Using multiple UDT's?
- Next by Date: Re: Not = versus <>
- Previous by thread: Re: Displaying images on form...
- Next by thread: Re: Displaying images on form...
- Index(es):