Rich textbox
-
Hi How can i set the richtextbox height according to the text height when i don't know the font size i have only rtf text
Unless u don't give ur hundred percent whatever u r doing till there is no result of ur work...
Hi, The scrollbars maximum position value changes with the amount of text in the control. Therefore if we could get the value of that we could adjust our height accordingly. So here is a little function that I did up. I haven't tested it extensively yet but as far as I can tell it works just fine for me. It uses the API function GetScrollRange and constant SB_VERT. These should be available in the API Viewer but if not they are in the winuser.h file. Also the scrollbars property may have to be set vertical. Please refer to the below mentioned code:
Public Sub AdjustHeight(ByVal rtfRichEdit As RichTextLib.RichTextBox, ByVal lpMinHeight As Long) Dim lpMax As Long ' Max scroll position Dim lpMin As Long ' Min scroll position ' get the scroll range GetScrollRange rtfRichEdit.hwnd, SB_VERT, lpMin, lpMax ' It may not be necessary to subtract the lpMin value from lpMax because I can't think of anytime that lpMin would be anything but 0... but just in case.... If ((lpMax - lpMin) * Screen.TwipsPerPixelY < lpMinHeight) Then ' This allows you to set a minimum height for your control rtfRichEdit.Height = lpMinHeight Else ' Else the control height should be equal to the text height - the max scroll value. rtfRichEdit.Height = (lpMax - lpMin) * Screen.TwipsPerPixelY End If End Sub
I hope this would be helpful.John Adams ComponentOne LLC. www.componentone.com
-
Hi, The scrollbars maximum position value changes with the amount of text in the control. Therefore if we could get the value of that we could adjust our height accordingly. So here is a little function that I did up. I haven't tested it extensively yet but as far as I can tell it works just fine for me. It uses the API function GetScrollRange and constant SB_VERT. These should be available in the API Viewer but if not they are in the winuser.h file. Also the scrollbars property may have to be set vertical. Please refer to the below mentioned code:
Public Sub AdjustHeight(ByVal rtfRichEdit As RichTextLib.RichTextBox, ByVal lpMinHeight As Long) Dim lpMax As Long ' Max scroll position Dim lpMin As Long ' Min scroll position ' get the scroll range GetScrollRange rtfRichEdit.hwnd, SB_VERT, lpMin, lpMax ' It may not be necessary to subtract the lpMin value from lpMax because I can't think of anytime that lpMin would be anything but 0... but just in case.... If ((lpMax - lpMin) * Screen.TwipsPerPixelY < lpMinHeight) Then ' This allows you to set a minimum height for your control rtfRichEdit.Height = lpMinHeight Else ' Else the control height should be equal to the text height - the max scroll value. rtfRichEdit.Height = (lpMax - lpMin) * Screen.TwipsPerPixelY End If End Sub
I hope this would be helpful.John Adams ComponentOne LLC. www.componentone.com