Results 1 to 10 of 10

Thread: I need Code for Centering Forms with different Screen Resolutions

  1. #1

    Thread Starter
    Lively Member flint's Avatar
    Join Date
    Oct 2000
    Posts
    67
    1. Does anyone have the code for centering forms on screens with different resolutions?

    2. I could still use some help on scrolling code as well
    http://<br /> <a rel="nofollow" hre...4942</a><br />

    Flint

  2. #2
    Guest

    Talking

    formabc.Top = (Screen.Height - Me.Height) / 2
    formabc.Left = (Screen.Width - Me.Width) / 2


    Hope it help

  3. #3
    Lively Member
    Join Date
    Jul 1999
    Posts
    77

    Question Isn't there a Property???

    I thought in VB6 and above have a property which u can set the start location of the window. I can't remember the property.

    I would check for u but I'm at school <:).

    -Justin

  4. #4
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    me.StartupPosition = 2
    Chemically Formulated As:
    Dr. Nitro

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    I use a module with the following subroutine
    Code:
    Public Sub Center(frmMe As Form)
       ' center the form
       
       frmMe.Top = (Screen.Height - frmMe.Height) / 2
       frmMe.Left = (Screen.Width - frmMe.Width) / 2
       
    End Sub
    and in my Form_Load subroutine I have the line
    Code:
    Center Me
    BTW, dragonyian, your answer is true only when formabc and Me are the same form.

  6. #6
    Guest

    Talking

    Ya, i saw it when i posted it.. i think that will work... by the way, can anypone help me with this

    y = 0.01
    do while y <1
    y = y*10
    loop
    text1.text = y

    i wonder why the answer is 9.99 but not 1


  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Are you using a floating point for y?
    That would cause someoperations to get inexact...
    now why don't you keep this on this thread
    http://forums.vb-world.net/showthrea...threadid=35076
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8

    Thread Starter
    Lively Member flint's Avatar
    Join Date
    Oct 2000
    Posts
    67

    SUB-TITLE: Y varible math

    Thanx ccoder. That's what I was lookin for!

    I will try your suggestion nitro.

    Dragonyian: The
    Code:
    do while y <1
    does not allow the y varible to become 1. Your code continues to multiply y(0.01) * 10 until the value of y = .99

    take .99 * 10 and you get 9.99

    hope this helps

    Flint

    A man will pay $2 for a $1 item he wants. A woman will pay $1 for a $2 item that she doesn't want.

  9. #9
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Smile A slight twist on ccoder's code...

    I like ccoder's code, but using the move method lets you take care of top, left, width, and height all in one call.

    Using a With statement saves a little processing time.
    Code:
    Public Sub CenterForm(frmIn As Form)
        ' Purpose: Centers form on screen
        '   Usage: CenterForm(Me)
        '    Note: Usually put in Form_Load or Form_Activate events
        
        With frmIn
            .Move (Screen.Width - .Width) / 2, (Screen.Height - .Height) / 2
        End With
        
    End Sub
    Dragonian, try this instead
    Code:
        y = 0.01
        
        Do While y <= 1
            y = y * 10
        Loop
        
        text1.Text = y
    Hope that helps!
    ~seaweed

  10. #10

    Thread Starter
    Lively Member flint's Avatar
    Join Date
    Oct 2000
    Posts
    67
    Thank you seaweed. (Somehow I never thought I'd say that...lol)

    I will certainly give your code a go.

    Of course, I expect my code to be running on a minimum of PII 300mhz or better.

    Hmmmm....I wonder If I need to include any ocx files in the installation because the app will primarily be used on laptops. Trial and Error shall tell.

    Flint

    Experience is often what you get when you were
    expecting something else.

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