Measure String inside RichTextBox Control

后端 未结 6 1018
刺人心
刺人心 2020-12-19 02:44

Can somebody please explain how I would go about measuring the string inside a richtextbox control so that the I can automatically resize the richtextbox control according t

6条回答
  •  太阳男子
    2020-12-19 03:17

    Put the following code in the ContentsResized event:

    Private Sub rtb_ContentsResized(ByVal sender As Object, ByVal e As System.Windows.Forms.ContentsResizedEventArgs) Handles txtQuestion.ContentsResized
            Dim h = e.NewRectangle.Height, w = e.NewRectangle.Width
            h = Math.Max(h, sender.Font.Height)
            h = Math.Min(h, Me.ClientSize.Height - 10 - sender.Top)
            h += sender.Height - sender.ClientSize.Height + 1
            sender.Height = h
    End Sub
    

提交回复
热议问题