Results 1 to 11 of 11

Thread: Converting Dialog Units into Pixels

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Converting Dialog Units into Pixels

    No, doesn't seem to.

    Have a go, put a label on the form and use my functions to try and place it as they have it on the form.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Converting Dialog Units into Pixels

    Quote Originally Posted by Ideas Man
    No, doesn't seem to.

    Have a go, put a label on the form and use my functions to try and place it as they have it on the form.

    Looks OK to me.

    (I didn't know what the font for that label was supposed to be so i took a very rough guess)...

    VB Code:
    1. Public Class DialogUnits
    2.  
    3.     Private Declare Function GetDialogBaseUnits Lib "user32" () As Integer
    4.  
    5.     Private _Width As Integer
    6.     Private _Height As Integer
    7.  
    8.     Public Sub New()
    9.         Call CalculateDialogUnits()
    10.     End Sub
    11.  
    12.     Public ReadOnly Property Width() As Integer
    13.         Get
    14.             Return _Width
    15.         End Get
    16.     End Property
    17.  
    18.     Public ReadOnly Property Height() As Integer
    19.         Get
    20.             Return _Height
    21.         End Get
    22.     End Property
    23.  
    24.     Public Function GetHeightInPixels(ByVal dialogUnits As Integer) As Integer
    25.         Return (_Height * dialogUnits) \ 8
    26.     End Function
    27.  
    28.     Public Function GetWidthInPixels(ByVal dialogUnits As Integer) As Integer
    29.         Return (_Width * dialogUnits) \ 4
    30.     End Function
    31.  
    32.     Public ReadOnly Property Size() As SizeF
    33.         Get
    34.             Return New SizeF(_Width, _Height)
    35.         End Get
    36.     End Property
    37.  
    38.     Private Sub CalculateDialogUnits()
    39.         Dim DialogUnits As Long = GetDialogBaseUnits
    40.  
    41.         _Width = LongManipulation.GetLoWord(DialogUnits)
    42.         _Height = LongManipulation.GetHiWord(DialogUnits)
    43.     End Sub
    44.  
    45. End Class
    46.  
    47.  
    48. Public Class LongManipulation
    49.  
    50.     Public Shared Function GetLoWord(ByVal sourceLong As Long) As Integer
    51.         Return CType(sourceLong And &HFFFF&, Integer)
    52.     End Function
    53.  
    54.     Public Shared Function GetHiWord(ByVal sourceLong As Long) As Integer
    55.         Return CType((sourceLong >> 16) And &HFFFF&, Integer)
    56.     End Function
    57.  
    58.     Public Shared Function IntegersToLong(ByVal hiWord As Integer, ByVal loWord As Integer) As Long
    59.         Return (hiWord << 16) Or loWord
    60.     End Function
    61.  
    62. End Class
    Attached Images Attached Images  
    I don't live here any more.

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Converting Dialog Units into Pixels

    Here's the code for the button...

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim du As DialogUnits = New DialogUnits
    4.  
    5.         With Label1
    6.             .Location = New Point(du.GetWidthInPixels(115), du.GetHeightInPixels(8))
    7.             .Size = New Size(du.GetWidthInPixels(195), du.GetHeightInPixels(24))
    8.         End With
    9.  
    10.         Me.Size = New Size(du.GetWidthInPixels(317), du.GetHeightInPixels(193))
    11.  
    12.     End Sub
    I don't live here any more.

  4. #4

    Thread Starter
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: Converting Dialog Units into Pixels

    Nah, see that's too big. Compare the form when you click the button to the picture or any wizard in Windows such as the New Connection Wizard in Windows XP. The inner area is bigger than the entire form for the wizard.

    Which makes me think that the numbers are supposed to be some decimal number, not whole integers because when you divide by 4 and 8 for width and height respectivly, you get like 1 & 2 (or 2 & 1, one or the other) which is too big, and when you set it to the size of the dialog units, it's too small.

    BTW, the title font is Verdana size 12, Bold.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

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