dcsimg
Results 1 to 8 of 8

Thread: Grid

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Grid

    Hi

    How to convert below code to Vb.net . I am using 64bit . I don't want to use reference VisualBasic.Compatilbility

    With grd1

    .Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Width) - VB6.PixelsToTwipsX(pic1.Width) - 320)
    .Height = VB6.TwipsToPixelsY(VB6.PixelsToTwipsY(Height) - VB6.PixelsToTwipsY(.Top) - 500)
    End With

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,098

    Re: Grid

    Twips were a variable-size measurement, and how many twips were in a pixel depended on things outside of your program (such as DPI settings of the monitor), but 15 was a common value.

    In .Net the standard measurement is Pixels, so you should just use pixel values instead.

    This should produce the same results, or at least close to it:
    Code:
    With grd1
       .Width = Width - pic1.Width - 21
       .Height = Height - .Top - 33
    End With
    ...however this might not be the best way to do things, it may be better for you to use the Anchor properties of controls instead. There is a good explanation here: http://www.vbforums.com/showthread.p...matic-Resizing

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,413

    Re: Grid

    As far as I know, .NET no longer uses twips, but pixels ... so ...
    Code:
    .width = Width - pic1.Width - 320
    .Height = Height - 500
    Bottom line, you no longer need to the pixel -> twips -> translations ... but I'm not sure about the -320 and -500 now as I see those are applied after the twip calculations, so those are in twips, which means they need to be recalculated to new values for the new units.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Re: Grid

    Hi

    in my code there is -320in first line & -500 in second line

    In yours -21 & 33 why.

    Thanks

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,413

    Re: Grid

    Quote Originally Posted by Jagjit View Post
    Hi

    in my code there is -320in first line & -500 in second line

    In yours -21 & 33 why.

    Thanks

    This is why:

    Quote Originally Posted by si_the_geek View Post
    In .Net the standard measurement is Pixels, so you should just use pixel values instead.
    Quote Originally Posted by techgnome View Post
    I see those are applied after the twip calculations, so those are in twips, which means they need to be recalculated to new values for the new units.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,098

    Re: Grid

    I based 21 and 33 on the assumption of 15 twips per pixel: 320/15 is about 21, and 500/15 is about 33.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Re: Grid

    Hi si_the_geek

    In below line there is TwipsToPixelsX & PixelsToTwipsX. Wht is the difference.

    .Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Width) - VB6.PixelsToTwipsX(pic1.Width) - 320)

    according to your code i get values 488 , 697. Whereas in vb6 i get values 509,706


    Thanks
    Last edited by Jagjit; Aug 7th, 2019 at 09:02 AM.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,098

    Re: Grid

    TwipsToPixelsX converts a value in Twips to the equivalent value in Pixels.

    PixelsToTwipsX converts a value in Pixels to the equivalent value in Twips.


    As they do the opposite to each other, this line:
    Code:
    .Width = VB6.TwipsToPixelsX(VB6.PixelsToTwipsX(Width) - VB6.PixelsToTwipsX(pic1.Width) - 320)
    ...is a long-winded and slow way of doing this:
    Code:
    .Width = Width - pic1.Width - VB6.TwipsToPixelsX(320)

    Quote Originally Posted by Jagjit View Post
    according to your code i get values 488 , 697. Whereas in vb6 i get values 509,706
    That is the magic of Twips... we can only guess what values each computer will get (and the X values might be on a different scale to the Y values).

    What actually matters is how it looks, and that is easier to get right using the pixel values. Adjust the 21 and 33 so that it looks right to you - or just use Anchor as I suggested before.
    Last edited by si_the_geek; Aug 7th, 2019 at 09:09 AM.

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