Results 1 to 3 of 3

Thread: [RESOLVED] Mimic functionality (Font scaling)

  1. #1

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Resolved [RESOLVED] Mimic functionality (Font scaling)

    I'm trying to mimic some functionality in the program below:
    http://www.contactplus.com/products/...gfreeclock.htm
    *scroll down. it's the "Big Free Clock" link*

    Developer has made it stretch the font depending on size of form, and also allows user to increase/decrease font with context menu.

    I have not been able to replicate this using only the Font properties. How is this being done, and how can I achieve the same functionality?

    Thanks.

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Mimic functionality (Font scaling)

    I'm not sure if it will scale proportionally or not, but couldn't you handle the form's or control's onresize event, and increase the pixel size of the font to the difference between the size of the form before resized and after (would also make it smaller)?

    Justin
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Mimic functionality (Font scaling)

    Here's what I found:
    Works a treat!

    vb.net Code:
    1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    2.         If MilitaryFormat Then
    3.             CurrentTime = System.DateTime.Now.ToString("HH:mm:ss")
    4.         Else
    5.             CurrentTime = System.DateTime.Now.ToString("hh:mm:ss t")
    6.         End If
    7.         ' Get the target area.
    8.         Dim target As New Rectangle(20, 20, Me.ClientSize.Width - 45, Me.ClientSize.Height - (DayLabel.Height + 30))
    9.  
    10.         ' Make the text in a GraphicsPath
    11.         ' at approximately the desired height.
    12.         Dim the_font As New Font("Arial", _
    13.             target.Height, FontStyle.Bold, GraphicsUnit.Pixel)
    14.  
    15.         ' Make the StringFormat.
    16.         Dim sf As New StringFormat
    17.         sf.Alignment = StringAlignment.Center
    18.         sf.LineAlignment = StringAlignment.Center
    19.  
    20.         ' Add the text to the GraphicsPath.
    21.         Dim text_path As New GraphicsPath
    22.         text_path.AddString(CurrentTime, _
    23.             the_font.FontFamily, CInt(FontStyle.Bold), _
    24.             target.Height, New PointF(0, 0), sf)
    25.  
    26.         ' Make a transformation to map
    27.         ' (xmin, ymin)-(xmax, ymax) onto
    28.         ' the target area.
    29.         Dim text_rectf As RectangleF = text_path.GetBounds()
    30.         Dim target_pts() As PointF = { _
    31.             New PointF(target.Left, target.Top), _
    32.             New PointF(target.Right, target.Top), _
    33.             New PointF(target.Left, target.Bottom) _
    34.         }
    35.         e.Graphics.Transform = New Matrix(text_rectf, target_pts)
    36.  
    37.         ' Draw the text.
    38.         e.Graphics.Clear(Me.BackColor)
    39.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
    40.         e.Graphics.FillPath(Brushes.White, text_path)
    41.         e.Graphics.DrawPath(Pens.White, text_path)
    42.  
    43.         ' Reset the transform.
    44.         e.Graphics.ResetTransform()
    45.  
    46.         ' Draw the bounding rectangle.
    47.         'e.Graphics.DrawRectangle(Pens.Red, target)
    48.  
    49.         ' Cleanup.
    50.         text_path.Dispose()
    51.         sf.Dispose()
    52.         the_font.Dispose()
    53.  
    54.     End Sub

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