Results 1 to 2 of 2

Thread: VB.NET, Problem with the Fonts Rotation

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Location
    Toronto, Canada
    Posts
    1

    VB.NET, Problem with the Fonts Rotation

    Having VB.NET problem. Please help.

    Running the following code:

    Function CreateRotatedFont(ByVal fontname As String, ByVal angleInDegrees As Integer) As Font
    Dim lf As New LogFont()

    ' Create graphics object for the form.
    Dim g As Graphics = Me.CreateGraphics()

    ' Scale a 12 point font for current screen DPI.
    lf.Height = Fix(-16.0F * g.DpiY / DPISETTING)

    ' Convert rotation angle to tenths of degrees.
    lf.Escapement = angleInDegrees * 10

    ' Orientation is the same as
    ' Escapement in mobile platforms.
    lf.Orientation = lf.Escapement

    lf.Width = 0
    lf.Weight = 0
    lf.Italic = 0
    lf.Underline = 0
    lf.StrikeOut = 0
    lf.CharSet = LogFontCharSet.Default
    lf.OutPrecision = LogFontPrecision.Default
    lf.ClipPrecision = LogFontClipPrecision.Default
    lf.Quality = LogFontQuality.ClearType
    lf.PitchAndFamily = LogFontPitchAndFamily.Default
    lf.FaceName = fontname

    Try
    Return System.Drawing.Font.FromLogFont(lf)
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally
    ' Explicitly dispose any drawing objects created.
    g.Dispose()
    End Try
    End Function

    When executing the line:
    Return System.Drawing.Font.FromLogFont(lf)

    I am getting the following exception:
    "No PInvoke conversion exists for value passed to Object-typed parameter."

    Does anybody know how to solve this problem?

    Thank you very much in advance.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB.NET, Problem with the Fonts Rotation

    Try casting lf as an Object before passing it to the method. I don't know if it will work but it's worth a try.

    Also, how have you defined your LogFont type? The way you're instantiating it looks like it's a class. It's supposed to be a structure, which may have a bearing.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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