Results 1 to 15 of 15

Thread: [RESOLVED] Center screen - stupid problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Resolved [RESOLVED] Center screen - stupid problem

    Hi All.

    I have the monitor of LCD. So when I will use this following code then my form is not on a screen centrally but in a bottom of the right corner of my screen.

    VB Code:
    1. Option Explicit
    2.  
    3.   Private Sub CenterForm(pobjForm As Form)
    4.  
    5.            With pobjForm
    6.  
    7.                .Top = (Screen.Height) / 2
    8.  
    9.                .Left = (Screen.Width) / 2
    10.  
    11.           End With
    12.  
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16. CenterForm Me
    17.  
    18. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    19. '  Me.Top = (Screen.Height) / 2 ' here the same
    20. '  Me.Left = (Screen.Width) / 2
    21. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    22. End Sub

    How to make it correctly? Thanks in advance
    I know, I know, my English is bad, sorry .....

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Center screen - stupid problem

    Set .StartUpPosition to 2 - CenterScreen at design time.

    Or:
    VB Code:
    1. '...
    2. .Top = (Screen.Height - pobjForm.Height) / 2
    3. .Left = (Screen.Width - pobjForm.Width) / 2
    4. '...

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Center screen - stupid problem

    try:
    VB Code:
    1. obj.Top = (Screen.Height / 2) - (obj.Height / 2)
    2.     obj.Left = (Screen.Width / 2) - (obj.Width / 2)

  4. #4

  5. #5

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Center screen - stupid problem

    Quote Originally Posted by RhinoBull
    ... and finally:
    VB Code:
    1. Form1.Move (Screen.Width - Form1.Width) / 2, (Screen.Height - Form1.Height) / 2
    Whenever precision is not a concern (as in this case), we should use \ instead of /. This makes our programs a bit faster.

    VB Code:
    1. Form1.Move (Screen.Width - Form1.Width) \ 2, (Screen.Height - Form1.Height) \ 2

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7

  8. #8
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Center screen - stupid problem

    Quote Originally Posted by RhinoBull
    @gavio: you need to use form's full size and NOT scale size.
    Edited my post

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Center screen - stupid problem

    Quote Originally Posted by RhinoBull
    That's irrelevant, Pradeep - position/size are Integers anyway...
    That's why we should use \ instead of using / as the result would be same, but fast.

    I read somewhere that \ is the fastest and / the slowest in terms of arithmetic operators.


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Center screen - stupid problem

    Quote Originally Posted by RhinoBull
    If it is then it could be by 1/1000th of a nanosecond... so please...
    Actually I never meant how much we would gain or loose.

    I just meant that we should improve our programming habits. Most programmers tend to use the / everytime, whether they are dealing with precision digits or not.

    As a rule we should always consider \ instead of / unless precision is a big concern to us.

    Remember a bucket fills drop by drop


    Pradeep
    Last edited by Pradeep1210; Dec 10th, 2006 at 12:25 PM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: Center screen - stupid problem

    thanks guys, it fine works for me
    I know, I know, my English is bad, sorry .....

  13. #13

  14. #14
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] Center screen - stupid problem

    Ohh.. sorry. They tend to use / everytime instead of \.


    Pradeep


    Edited and corrected the post.
    Last edited by Pradeep1210; Dec 10th, 2006 at 12:26 PM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  15. #15

Posting Permissions

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



Click Here to Expand Forum to Full Width