dcsimg
Results 1 to 12 of 12

Thread: LINE()-() on UserControl

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    722

    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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    722

    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.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    722

    Re: LINE()-() on UserControl

    Quote Originally Posted by LaVolpe View Post
    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.

  6. #6
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,556

    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



  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: LINE()-() on UserControl

    Quote Originally Posted by flyguille View Post
    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?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,476

    Re: LINE()-() on UserControl

    Quote Originally Posted by LaVolpe View Post
    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 640350 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>

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    722

    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?

  10. #10
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: LINE()-() on UserControl

    Quote Originally Posted by flyguille View Post
    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    722

    Re: LINE()-() on UserControl

    Quote Originally Posted by LaVolpe View Post
    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.

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width