Results 1 to 4 of 4

Thread: Zooming in/out on WinForm

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Zooming in/out on WinForm

    Hi,

    It seems from what I research that it is not possible to zoom in/out of normal WinForm. So I am looking for maybe a clever method to implement some zoom in/out effect.

    My problem is that I have a userform with textboxes, datagridviews, labels, etc. When I use a overhead projector then some people sitting at the back can not see properly.

    How can I (temporary) make it bigger?


    Thanks

  2. #2
    Addicted Member Goggy's Avatar
    Join Date
    Oct 2017
    Posts
    196

    Re: Zooming in/out on WinForm

    Code:
    Public Class Form1
        Const ZoomFactor As Single = 2
    
        Private Sub Form1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
            Dim Zoom As Single
    
            If e.Delta > 0 Then
                Zoom = ZoomFactor
            Else
                Zoom = 1 / ZoomFactor
            End If
    
            Me.Scale(New SizeF(Zoom, Zoom))
        End Sub
    
    End Class
    Utterly useless, but always willing to help

    As a finishing touch god created the dutch

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Zooming in/out on WinForm

    Quote Originally Posted by Goggy View Post
    Code:
    Public Class Form1
        Const ZoomFactor As Single = 2
    
        Private Sub Form1_MouseWheel(sender As Object, e As MouseEventArgs) Handles Me.MouseWheel
            Dim Zoom As Single
    
            If e.Delta > 0 Then
                Zoom = ZoomFactor
            Else
                Zoom = 1 / ZoomFactor
            End If
    
            Me.Scale(New SizeF(Zoom, Zoom))
        End Sub
    
    End Class
    Hi Goggy, thank you for you reply. Not what I have in mind

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Zooming in/out on WinForm

    Assuming you use the form's default scaling mode (AutoScaleMode.Font) you only need change the font size. I suppose you want to keep the form centred too, in which case you could use a method like this:
    Code:
      Private Sub ScaleForm(scale As Single)
          Me.AutoScaleMode = Windows.Forms.AutoScaleMode.Font
          Me.Font = New Font(Me.Font.FontFamily, Me.Font.Size * scale)
          Me.Left += CInt(Me.Width * (1 - scale) / 2)
          Me.Top += CInt(Me.Height * (1 - scale) / 2)
       End Sub
    Or have I failed to read your mind correctly?

    BB

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