none
RichTextBox ignores ZoomFactor changes

    General discussion

  • Hi

    This is a post just to document something that I have just spent an hour trying to find a solution for. It may help others who have this issue.

    I use a RichTextBox in a project. The RTB responds as expected to Ctrl-Mouse Wheel, zooming in/out, and is just what is wanted.

    I added a Button to Reset the RTB text to the project default. It cycles through the characters in the RTB and sets the FontFamily and Size to the defaults, keeping the styles as is. This routine also resets the RTB.ZoomFactor to 1.0F.

    Here is where is became somewhat strange. It would work once, but then completely ignore the zoomfactor reset from then on. It would work on rerunning the application once and then, as before, ignore any other resets.

    The solution turned out to be very simple, despite taking so long to find.

    Here is the code used. The BOLD line is the addition that made it work. Without that line, then the zoomfactor at the end of the Sub is just plainly ignored.

    Private Sub RefreshLogFont()
       With RichTextBox2
           .ZoomFactor = 2.0F
           For i As Integer = 0 To .TextLength
               .Select(i, 1)
               .SelectionFont = New Font(My.Settings.LogFont.FontFamily, My.Settings.LogFont.SizeInPoints, .SelectionFont.Style)
           Next
           .ZoomFactor = 1.0F
       End With
       StatusTextAdd("Log text changed by user")
    End Sub
    

    I would imagine this is a bug.


    Regards Les, Livingston, Scotland

    Wednesday, May 03, 2017 9:31 PM