-
Jun 13th, 2019, 09:22 AM
#1
Thread Starter
Fanatic Member
LINE()-() on UserControl
Somebody can explainme why this code draws incorrect border size up/left?
New User Control -> Scale default as twips. ScreenperpixelX =ScreenperpixelY = 15 (screen is 1366x768). FLAT (no border), and autoredraw=true
I mean , is suppose tht LINE () - (x2,y2),,BF where x2 & y2 is the last position to be painted.
and that scalewidth , scaleheight = THE SIZE.
So, the last position that is in a matrix that starts from ZERO, is scalewidth-1 and scaleheight-1
so, what is wrong? why it paints nothing on bottom right, and a single line in top left.
or if you change the Default_VarBorderWidth = 15 (the pixel size in twips), it paints two row/columns in top left, and 1 column in bottom , right? WHYYYYYYYY!!!!!!
I observed this behaviour also in pixel scale, so it is not like a conversion thing.
In all my usercontrols I have to deal with it, changing the formulas.
Code:
Option Explicit
Option Compare Binary
Private Const Default_VarBorderWidth = 5
Private VarBorderWidth As Integer
Private Const Default_VarBorderColor = &HFFFFFF
Private VarBorderColor As OLE_COLOR
Private VarBackColor As OLE_COLOR
Private VarPicture As StdPicture
Private VarProgressBarLeftMargin As Integer
Private VarProgressBarRightMargin As Integer
Private VarProgressBarTopMargin As Integer
Private VarProgressBarBottomMargin As Integer
Private VarProgressBarBorderWidth As Integer
Private VarProgressBarHeight As Integer
Private VarProgressBarBorderColor As OLE_COLOR
Private VarProgressBarBackColor As OLE_COLOR
Private VarProgressBarForeColor As OLE_COLOR
Private VarTextColor As OLE_COLOR
Private VarFont As Font
Private Sub UserControl_Initialize()
VarBorderWidth = Default_VarBorderWidth
VarBorderColor = Default_VarBorderColor
End Sub
Private Sub UserControl_Resize()
Call Redraw
End Sub
Private Sub Redraw()
If VarPicture Is Nothing Then
UserControl.BackColor = VarBackColor
Else
UserControl.PaintPicture VarPicture, VarBorderWidth, VarBorderWidth, UserControl.ScaleWidth - VarBorderWidth * 2, ScaleHeight - VarBorderWidth * 2
End If
' Arriba.
Line (0, 0)-(UserControl.ScaleWidth - 1, VarBorderWidth - 1), VarBorderColor, BF
' Izquierda.
Line (0, 0)-(VarBorderWidth - 1, UserControl.ScaleHeight - 1), VarBorderColor, BF
' Abajo.
Line (0, UserControl.ScaleHeight - VarBorderWidth)-(UserControl.ScaleWidth - 1, UserControl.ScaleHeight - 1), VarBorderColor, BF
' Derecha.
Line (UserControl.ScaleWidth - VarBorderWidth, 0)-(UserControl.ScaleWidth - 1, UserControl.ScaleHeight - 1), VarBorderColor, BF
End Sub
Last edited by flyguille; Jun 13th, 2019 at 09:27 AM.
-
Jun 13th, 2019, 05:27 PM
#2
Re: LINE()-() on UserControl
UC scalemode is twips? Change border width to twips, i.e., TwipsPerPixelX*5
Also in your Line commands, you can't subtract 1 if scalemode is twips, you need to subtract TwipsPerPixelX
Last, in your Redraw function, simply setting the backcolor to the same color does nothing. Try resizing your UC larger and see what I mean. Either call CLS or draw a filled rectangle to clear the control's canvas.
-
Jun 13th, 2019, 06:59 PM
#3
Thread Starter
Fanatic Member
Re: LINE()-() on UserControl
ok, checked that it is rounding the X & Y position when going from twips to pixels. If the pixel width is 15, up to 7 twips it stays the same column/row, if x=8 twips it rounds to the next column/row.
thanks, so was a conversion thing.
-
Jun 13th, 2019, 07:54 PM
#4
Re: LINE()-() on UserControl
I'd call it a scale thing vs conversion. If your UC scalemode was pixels, you'd get what you were after.
P.S. You don't need to draw 4 lines and using BF when drawing a horizontal/vertical line really has no purpose. To draw a rectangle without filling it...
Code:
Line (0, 0)-(ScaleWidth - Screen.TwipsPerPixelX, ScaleHeight - Screen.TwipsPerPixelY), VarBorderColor, B
-
Jun 13th, 2019, 08:25 PM
#5
Thread Starter
Fanatic Member
Re: LINE()-() on UserControl
Originally Posted by LaVolpe
I'd call it a scale thing vs conversion. If your UC scalemode was pixels, you'd get what you were after.
P.S. You don't need to draw 4 lines and using BF when drawing a horizontal/vertical line really has no purpose. To draw a rectangle without filling it...
Code:
Line (0, 0)-(ScaleWidth - Screen.TwipsPerPixelX, ScaleHeight - Screen.TwipsPerPixelY), VarBorderColor, B
yup, I know from the 80's the ,B thing, in others controls when the scale was PIXELs, I did the ,B, inside a loop, so if the border is 4 pixels width it loops 4 times with the ,B
But now, I did this method because I am wanting on purpose to do it in twips. Ofcourse I cound loop with STEP twipsperpixelx, but that will be like working correctly only if twipsperpixelX = twipsperpixelY
I mean, the usual....
for x=0 to borderwidth-1
line(x,x)-(w-1-x,h-1-x),color,b
next x
that is the usual in pixel mode.
Last edited by flyguille; Jun 13th, 2019 at 08:39 PM.
-
Jun 13th, 2019, 08:44 PM
#6
Re: LINE()-() on UserControl
You can use Shape control to draw the border, e.g.
Code:
Private Sub Redraw()
If VarPicture Is Nothing Then
UserControl.BackColor = VarBackColor
Else
UserControl.PaintPicture VarPicture, VarBorderWidth, VarBorderWidth, UserControl.ScaleWidth - VarBorderWidth * 2, ScaleHeight - VarBorderWidth * 2
End If
Shape1.Move CInt(Shape1.BorderWidth / 2) * Screen.TwipsPerPixelX, _
CInt(Shape1.BorderWidth / 2) * Screen.TwipsPerPixelY, _
UserControl.ScaleWidth - (Shape1.BorderWidth - 1) * Screen.TwipsPerPixelX, _
UserControl.ScaleHeight - (Shape1.BorderWidth - 1) * Screen.TwipsPerPixelY
End Sub
-
Jun 14th, 2019, 05:53 AM
#7
Re: LINE()-() on UserControl
Originally Posted by flyguille
But now, I did this method because I am wanting on purpose to do it in twips. Ofcourse I cound loop with STEP twipsperpixelx, but that will be like working correctly only if twipsperpixelX = twipsperpixelY
I don't think you will find monitors in the wild with non-square pixels?
-
Jun 14th, 2019, 06:00 AM
#8
Re: LINE()-() on UserControl
Originally Posted by LaVolpe
I don't think you will find monitors in the wild with non-square pixels?
The next major advancement in display adapter technology was the Enhanced Graphics Adapter (EGA), which brought you a stunning 16 colors in a 640×350 grid with an aspect ratio of 1.83:1 . . . clearly remember those days and "the insanity of planar video modes".
But VB6 probably received EGA support as a legacy from previous versions as by '98 EGAs were next to extinct.
cheers,
</wqw>
-
Jun 15th, 2019, 01:33 PM
#9
Thread Starter
Fanatic Member
Re: LINE()-() on UserControl
well, the UserControl is already done, kicking and live!, done in twips.
I mean, the idea is that objects defined in twips will be the same in metric regardless of the pixel pitch?, right?. I mean if the pixels are physically smaller, window will have a smaller twipsperpixelXY number , right?
-
Jun 15th, 2019, 01:53 PM
#10
Re: LINE()-() on UserControl
Originally Posted by flyguille
I mean, the idea is that objects defined in twips will be the same in metric regardless of the pixel pitch?, right?. I mean if the pixels are physically smaller, window will have a smaller twipsperpixelXY number , right?
Only applies if the application is DPI-aware else app is virtualized to 96 DPI (100%) regardless of actual DPI and twips is always 15
Another way of looking at it: The greater the DPI, more pixels on the screen and twips per pixel value is smaller.
A calculation for proof of concept: TwipsPerPixel = 1440 / 96 = 15; 96 is 100% DPI
When DPI increased to 125%, then TwipsPerPixel = 1440 / (96 * 1.25) = 12
-
Jun 15th, 2019, 02:03 PM
#11
Thread Starter
Fanatic Member
Re: LINE()-() on UserControl
Originally Posted by LaVolpe
Only applies if the application is DPI-aware else app is virtualized to 96 DPI (100%) regardless of actual DPI and twips is always 15
Another way of looking at it: The greater the DPI, more pixels on the screen and twips per pixel value is smaller.
A calculation for proof of concept: TwipsPerPixel = 1440 / 96 = 15; 96 is 100% DPI
When DPI increased to 125%, then TwipsPerPixel = 1440 / (96 * 1.25) = 12
Wait, vb6 are not dpi aware apps?, I have to move it to 4K because now the esports are using like 27" courved monitors, others are using ultra wide form factors, that makes my app to look wrong.
So, previously, I switched all forms to twips, but the usercontrols remained all its internal scale in pixels and its internals (all its internal drawing properties).
But, what I think was happening before, is that the FORMs were in pixels scale, but the FRAME objects can't do PIXELs scale, they works in twips always, so that mismatch ruined all the skins in the past.
when I move to ALL in twips, except the internals of usercontrols, it improved a lot.
-
Jun 15th, 2019, 02:05 PM
#12
Re: LINE()-() on UserControl
VB6 is DPI aware for the most part. To allow the app to scale to the system DPI, a manifest is needed for modern O/S. You can find lots of information on this site if you search for key term: DPI awareness
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|