Re: Different resizing behaviour on 120 dpi screen

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



"Jack" <replyto@it> wrote in message news:ua9ApyrbIHA.6024@xxxxxxxxxxxxxxxxxxxxxxx

Imagine a form with 2 picture boxes together occupying
100% form's client area. One pcture box occupies 40%
and second one 60% of the forms'width. Now, in form
resize event I have the following line of code:
picPad.Move 0, 0, 0.4 * Me.ScaleWidth, Me.ScaleHeight
picMain.Move picPad.width, 0, 0.6 * Me.ScaleWidth, Me.ScaleHeight
That is not the case under 120 dpi if I do as described in
my original post.

Right. Firstly, you haven't told us whether these picture boxes have borders or not, and whether or not you want all four borders on both picture boxes to be fully displayed. Also, you've told us what is NOT happening, but it would be more instructive if you told us what IS happening. We would then have a much better idea of what your problem is. Do you mean the resizing is sometimes not happening at all, or that it is a lot different than your expected output, or perhaps that it is just a pixel or so out? Details, details. The devil is in the details. The OS cannot actually display a window of any sort on the screen that is anything other than a whole pixel value, whereas VB will calculate and store a window's Width (or Height) property using whatever value you assign to it, which may or may not be a whole pixel value. As a simple example, if you are running at the standard 96 dpi (15 twips per pixel) setting and you assign the value 1000 to the Width property of a Picture Box on a Form that has its ScaleMode set to vbTwips (the default) then VB will create a picture box that is actually 67 pixels wide. However, it will store its Width as exactly 1000 (twips). And if you then change the Form's ScaleMode property to vbPixels and you ask VB to tell you the width of the Picture Box VB will return the value 66.666 (the devil's number!). The Picture Box is not actually 66.666 pixels wide though. It is really 67 pixels wide, as you will see if you use the API to ask for the width of that window or if you check it with an ons screen pixel counter or whatever. These little rounding errors often occur, but are easily dealt with. Also, you can easily accidentally compound the error by calculating two separate Widths (one for each PictureBox as you are doing) using two separate calculations. It would be far better to calculate the width of just one of the picture boxes and then make the width of the other picturebox exactly sufficient so that it occupies whatever is left.

Personally I would advise that you use a ScaleMode of pixels for your Form and that you use a Long as the data type for the result of your calculation. In that way when you perform the calculation for the width of one of the picture boxes and assign that Long value to the PictureBox you will end up with a picture box which has a clearly defined width in its Width property that is actually exactly the same as the "real width" of the PictureBox as it appears on the display and also exactly the same as the width that would be reported if you asked the API to check its size. Then you assign whatever is left to the Width of the other PictureBox. You should then get pixel perfect alignment under all conditions. You will not of course usually end up with (in your case) one PictureBox that is 40 per cent of the width of the Form and another that is exactly 60 per cent, because that condition is not actually possible except when those exact relationships would result in a precise whole pixel value for both picture boxes, which is rarely going to be the case. For example, if the scalewidth of your Form happens to be 100 pixels then you would get exactly what you are after, but if the ScaleWidth is 101 pixels then it is not possible for one picture box to take up exactly 40% of the available display area of your Form and for the other to take up exactly 60%. It just isn't possible. But if you do it correctly you will always end up with the two Picture Boxes taking up an approximate 40 / 60 relationship with each other, and you will always end up with the combined width of them being exactly the same as the width of the client area of your Form.

Anyway, try the following code. It works fine for me under all conditions at both 96 dpi and 120 dpi and also at a few various different dpi setting which I tried.

Mike

Private Sub Form_Resize()
Dim wide As Long, high As Long, pwide As Long
ScaleMode = vbPixels
wide = Me.ScaleWidth: high = Me.ScaleHeight
pwide = wide * 0.4
picPad.Move 0, 0, _
pwide, high
picMain.Move pwide, 0, _
wide - pwide, high
End Sub



.



Relevant Pages

  • Re: Forcing a form to perfectly fit its background image
    ... assuming the picture is always smaller than the screen. ... If the resolution of the camera when you took the picture was 1600 x 1200 for example and you display that picture at its full "pixel size" on a typical monitor running at a typical 96 pixels per logical inch then the picture will have a "size" of 16.7 x 12.5 logical inches. ... So, as you can see, displaying or printing a picture "pixel for pixel" will produce a picture whose size depends on the size of each pixel in the output device. ...
    (comp.lang.basic.visual.misc)
  • Re: Question regarding VB6
    ... your drawings without going into the complexity of using the various region ... point in the main picture box and you would have an identically shaped ... In Windows of course you still specify the values 0 to 255 for each of the rgb components regardless of the colour depth of the system, and Windows will use the nearest colour it can, but on 16 bit colour depth systems every pixel will be one of the 65536 colours that it can actually display. ... As I mentioned earlier, on 16 bit systems the red and blue components will normally be one of 32 possible values, and the green component will be one of 64 possible values. ...
    (comp.lang.basic.visual.misc)
  • Re: Question regarding VB6
    ... your drawings without going into the complexity of using the various region ... point in the main picture box and you would have an identically shaped ... In Windows of course you still specify the values 0 to 255 for each of the rgb components regardless of the colour depth of the system, and Windows will use the nearest colour it can, but on 16 bit colour depth systems every pixel will be one of the 65536 colours that it can actually display. ... As I mentioned earlier, on 16 bit systems the red and blue components will normally be one of 32 possible values, and the green component will be one of 64 possible values. ...
    (comp.lang.basic.visual.misc)
  • Re: Will F1 be on BBC HD?
    ... much sharper picture than a lower-resolution one. ... good quality HD display fed a good quality HD signal is far ... sharper than a good quality SD display fed a good quality SD ... they think you get a 1:1 pixel mapping, ...
    (rec.autos.sport.f1)
  • Re: Alpha blending
    ... > Simple example hacked from another example shows how to take one picture ... > and alpha overlay onto another using the alphablend API. ... > picture boxes should contain a picture. ... seemed to do alpha blending one pixel at a time. ...
    (microsoft.public.vb.general.discussion)