Re: Resize form problem

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Mike,

I have tried what you suggested but it doesn't work out the way I want
it.
There are basically three functions that I need done.
First of all the function LoadDemoDetails which reads the records from
the recordset
into the DemoDetails() As typDetails.

Private Type typDetails
dCat As String
dDOE As Date
dDOI As Date
dType As String
dLastXStart As Long
dLastXEnd As Long
dLastY As Long
End Type

I placed it in the Resize Event like:

'only perform LoadDemoDetails the first time
If bLoaded = False Then
Call LoadDemoDetails
End If

It also identifies the space between the earliest and the latest date
in the recordset:

rs2.MoveFirst
AreaStart = rs2.Fields("doe") - 25
rs2.MoveLast
AreaEnd = rs2.Fields("doe") + 25
TimeDiff = AreaEnd - AreaStart

And depending on this gap the way the dates are displayed on top of the
form:

If (TimeDiff > 1) Then ' More than a day
MarkerFormat = "Short Date"
Else ' Less than a day
MarkerFormat = "dd-mm-yy" '"Short Time"
End If

The second function is to draw some vertical lines as sort of grid
between the images and to display the date at the top of the line:

For LoopMarkers = 0 To NumMarkers - 1
'Work out marker string and position
MarkerString = Format$(AreaStart + ((LoopMarkers / (NumMarkers -
1)) _
* TimeDiff), MarkerFormat)
MarkerPos = ((LoopMarkers / (NumMarkers - 1)) _
* (Me.ScaleWidth - (PixelsValLeft + PixelsValRight))) +
PixelsValLeft

If Not LoopMarkers = 0 Then 'don't draw the first line
If Not LoopMarkers = 7 Then 'don't draw the last line

'Draw marker line
OldStyle = Me.DrawStyle
Me.DrawStyle = vbDot
Me.Line (MarkerPos, TextHeight("A") +
MarkerTop)-(MarkerPos, _
Me.ScaleHeight), vb3DShadow
Me.DrawStyle = OldStyle

'Draw marker string
Me.CurrentX = MarkerPos - (TextWidth(MarkerString) \ 2)
Me.CurrentY = MarkerTop
Me.Print MarkerString
End If
End If
Next LoopMarkers

I placed that in the Resize Event as well.
The third part is to draw the icons (images) and the corresponding text
beneath them.

'else draw the images with corresponding text
If bLoaded = True Then
For I = 1 To UBound(DemoDetails)
Call DrawArea(DemoDetails(I))
Next
End If

This is the DrawArea function:

Private Sub DrawArea(ByRef inDetails As typDetails)

Dim b As Box
Dim TextSize As Long

' This does fall within the visible time frame
If ((inDetails.dDOE < AreaStart) Or _
(inDetails.dDOE > AreaEnd)) Then Exit Sub

' Calculate area coordinates
XStart = ((inDetails.dDOE - AreaStart) / (AreaEnd - AreaStart)) *
Me.ScaleWidth
xEnd = ((inDetails.dDOE - AreaStart) / (AreaEnd - AreaStart)) *
Me.ScaleWidth
XStart = XStart + PixelsValLeft

XLastStart = XStart
XLastEnd = xEnd

TextSize = Me.TextWidth(CStr(inDetails.dCat))

'gebruik het gehele formulier
YStart = Me.Top
YLast = Me.Top + Me.Height

' Draw area and text
CurrentDate = Now()

AddNewPictureBox Me.ilsIcons.ListImages(2).Picture, XStart, YStart
+ 500, inDetails.dDOE 'Me.Height / 2
sColor = 1

Me.CurrentX = XStart - (TextWidth(inDetails.dType) / 2)
Me.CurrentY = YStart + 1200
Me.Print CStr(inDetails.dType)
Me.CurrentX = XStart - (TextWidth(inDetails.dType) / 2)
Me.CurrentY = YStart + 1400
Me.Print CStr(inDetails.dCat)

End Sub

Now the problems I have is where to place what code.
When the form is maximized I get multiple images.
The dates at the top of the vertical lines are all the same.

Please need some serious help here....

Marco


Mike Williams schreef:

"vonClausowitz" <vonclausowitz@xxxxxxxxx> wrote in message
news:1155837707.960548.38310@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

The recordset is no problem but it would be better if it
didn't everytime. The problem is I don't know how else
to do it.

Just read the recordset once (in your Form Load event) and hold the data in
some variables of a suitable type that you have declared in your Form's
General (Declarations) section, so that they can be accessed by all the
routines in your Form. You should only read the data again if it is likely
to have changed. Your drawing code (and any other code) can then access the
variables, which will be very, very much faster.

Regarding your drawing, I would personally do it in the Resize event in your
specific case. A lot of people here don't like using Autoredraw on Forms
(mostly because a Form's autoredraw memory bitmap is always the same size as
the display, regardless of the size of the Form). However, I like Autoredraw
and I would suggest that you use it. If I were you I would set your Form's
Autoredraw property to True in the Form's Load event and I would transfer
all the code from your Paint event into the Resize event (leaving no code at
all in the Paint event). It should then work okay.

Just a couple of points of the rest of your code while I'm at it. I see
you're loading an image into the Picture property of a Picture Box and then
resizing the Picture box to fit using the code:

.Width = .ScaleX(.Picture.Width, vbHimetric, .ScaleMode)

That code will only work correctly (or almost correctly, because it doesn't
take into account the borders if it has any) if the ScaleMode of the Picture
Box is the same as the ScaleMode of the Form, because the Picture Box Width
property is always in the units used by its container (the Form) whereas in
the code you are performing the conversion using the ScaleMode of the
Picture Box, which might be different (depending on what else you are doing
in code I haven't seen). To fix that you should change the code to:

.Width = .ScaleX(.Picture.Width, vbHimetric, .Container.ScaleMode)

The above will work correctly (again apart from a small difference due to
the border thickness). You can easily add code to take the border thickness
into account as well, but I haven't mentioned it here because there is a
very much easier way of sizing the picture box so that the picture exactly
fits. All you need to do is set the Picture Box Autosize property to True
before you load the picture. The picture box will then automatically resize
itself to the picture. That is of course if you really do want to adjust the
size of the picture box to fit the picture (as you are currently doing). In
many cases (and perhaps in your case) it is better to set the Picture Box to
a specific size and then stretch or reduce the picture so that it fits. Have
a look at the PaintPicture method. A lot depends on exactly what you are
putting into the picture box, but it is something you might like to
consider, if not for now then perhaps for the future.

One more point is that it appears you are drawing your data at such a size
that the entire drawing fits into the Form, whatever size it is. Is that
actually what you are doing? If so then you're going to have problems with
small sizes for various reasons, particularly with fonts. If you want to
draw stuff at a reduced size then you really should also reduce the size of
the fonts (within reason, of course). Alternatively, perhaps you might like
to forget about resizing the drawing and instead take up Larry's suggestion
of drawing it at full scale regardless of the size of the Form and
displaying it in a "scrollable" container.

Also, take note of what Ken has said about the dots per inch (or twips per
pixel) settings. Whatever application you create it is always worth using
the control panel display applet to set your machine to a different dpi
setting than the one you normally use (which normally requires a restart)
and running it again to see how it behaves. Some XP machines with specific
graphics cards won't actually perform the dpi change properly in the same
way that many others do, so I personally always keep an old Win98 machine
(or a WinXP machine which will properly perform the dpi change) on hand to
check these things out on. You'd be surprised at how many problems it can
pick up for you.

Mike Williams
MVP Visual Basic

.



Relevant Pages

  • Re: Custom ScaleMode setting problem
    ... It sets up a picture box in the way that you require. ... In this way you can draw the finished graph at any physical location and size you require, opaquely or transparently, and you can draw it to the printer in a way that takes full advantage of the printer's high resolution. ... Private pOffsetX As Single, pOffsetY As Single ...
    (microsoft.public.vb.general.discussion)
  • Re: lines dont stay on form...
    ... Personally for such jobs I would draw ... On way to achieve what you're after and still use your existing "picture ... Private xCentre As Single, yCentre As Single ... Private Sub Label1_DblClick ...
    (microsoft.public.vb.general.discussion)
  • Re: Unknown pointer problem between Visual Basic and C
    ... Draw into a picture area. ... except drawing from Visual Basic (HDC seems to be wrong). ... I send to the "Visual Basic wrapper" built in C, dimensions and DC pointer ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Where to file one defgeneric for two classes and two packages
    ... Suppose I want to draw pictures and lines on a display. ... I just apply the draw method, but for lines, I may want to specify the ... Presumably your picture and line objects keep track of their own ... This is the kind of situation I envision calling a generic function ...
    (comp.lang.lisp)
  • Re: redraw pictureboxes in image????
    ... own suggested method to perform this job (a Picture Box containing two ... As for your current specific problem, use a Label to hold the "number in the ... at their defaults if you wish) and set its ToolTipText to whatever you want. ... Draw your line between the images using the VB Line method (type the word ...
    (microsoft.public.vb.general.discussion)