Results 1 to 7 of 7

Thread: getting the titleBar height

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    getting the titleBar height

    can someone just double-check my code? cuz it seems to be working almost fine except its one pixel off for some reason
    VB Code:
    1. Public ReadOnly Property TitleBarHeight(ByVal bStyle As FormBorderStyle) As Integer
    2.         Get
    3.            Select Case bStyle
    4.                 Case FormBorderStyle.Fixed3D
    5.                     Return SystemInformation.CaptionHeight + _
    6.                                   2 * SystemInformation.Border3DSize.Height
    7.  
    8.  
    9.                 Case FormBorderStyle.Sizable, FormBorderStyle.FixedSingle, FormBorderStyle.FixedDialog
    10.                     Return SystemInformation.CaptionHeight + _
    11.                              2 * SystemInformation.Border3DSize.Height
    12.  
    13.  
    14.  
    15.                 Case FormBorderStyle.FixedToolWindow, FormBorderStyle.SizableToolWindow
    16.                     Return SystemInformation.ToolWindowCaptionHeight + _
    17.                              2 * SystemInformation.Border3DSize.Height
    18.  
    19.                 Case FormBorderStyle.None
    20.                     Return 0
    21.             End Select
    22.         End Get
    23.     End Property
    The first case switch returns a value 1 pixel less than the actual value, and the second case statement returns 1 pixel more than the actual value. I think I'm using the right stuff, why isn't it working correctly?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    hmm this seems to be working fine, except I dont know where the +1 at end comes from
    I noticed that sizable forms are 1 pixel bigger

    VB Code:
    1. Public ReadOnly Property TitleBarHeight(ByVal bStyle As FormBorderStyle) As Integer
    2.         Get
    3.             Dim border, height As Integer
    4.  
    5.             If bStyle = FormBorderStyle.SizableToolWindow OrElse _
    6.               bStyle = FormBorderStyle.Sizable Then
    7.                 border = 1
    8.             End If
    9.  
    10.  
    11.             Select Case bStyle
    12.                 Case FormBorderStyle.Fixed3D
    13.                     height = SystemInformation.CaptionHeight
    14.                     border += 2 * SystemInformation.Border3DSize.Height
    15.  
    16.                 Case FormBorderStyle.Sizable, _
    17.                      FormBorderStyle.FixedSingle, _
    18.                      FormBorderStyle.FixedDialog
    19.  
    20.                     height = SystemInformation.CaptionHeight
    21.                     border += 2 * SystemInformation.BorderSize.Height
    22.  
    23.  
    24.                 Case FormBorderStyle.FixedToolWindow, _
    25.                      FormBorderStyle.SizableToolWindow
    26.  
    27.                     height = SystemInformation.ToolWindowCaptionHeight
    28.                     border += 2 * SystemInformation.BorderSize.Height
    29.  
    30.                 Case FormBorderStyle.None
    31.                     Return 0
    32.             End Select
    33.  
    34.             Return height + border + 1
    35.         End Get
    36.     End Property
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    I haven't tried this. I just thought this might do the trick, regardsless of FormBorderStyle.

    VB Code:
    1. TitleHeight = Me.Height - Me.ClientSize-Height

    As far as I know, the Height is the actual height of the entire form/control, where ClientSize.Height is the height available to the user. Hence I think that the difference between the two must be the titlebar height. If the form has no border the height would return 0.

    I hope this is of any help...
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by pax
    Hi.

    I haven't tried this. I just thought this might do the trick, regardsless of FormBorderStyle.

    VB Code:
    1. TitleHeight = Me.Height - Me.ClientSize-Height

    As far as I know, the Height is the actual height of the entire form/control, where ClientSize.Height is the height available to the user. Hence I think that the difference between the two must be the titlebar height. If the form has no border the height would return 0.

    I hope this is of any help...
    that's what I've always been using, but apprently it doesnt give you the correct height (I get a screenshot of the form and measure the titlebar in pixels using msPaint and it appears to be a different value when I use that code. But so far my code is working correctly )

    edit: plus I think there was another problem with that. I think when I had a main menu then clientSize would become smaller and therefore I would get a value that was way off for the titlebar
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Originally posted by MrPolite
    that's what I've always been using, but apprently it doesnt give you the correct height (I get a screenshot of the form and measure the titlebar in pixels using msPaint and it appears to be a different value when I use that code. But so far my code is working correctly )
    Strange...perhaps it has something to do with visual styles...




    edit: plus I think there was another problem with that. I think when I had a main menu then clientSize would become smaller and therefore I would get a value that was way off for the titlebar
    Right, didn't think of that...

    hmm, perhaps the GetTitleBarInfo API could do the trick.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Forget this post...things went wrong...
    Last edited by pax; Feb 27th, 2004 at 06:31 AM.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by pax
    Forget this post...things went wrong...
    heheh ok

    umm API? well you can do it with .NET and apparently that code works fine, so why the heck not
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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