Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Rich textbox

Rich textbox

Scheduled Pinned Locked Moved Visual Basic
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    V 2
    wrote on last edited by
    #1

    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...

    J 1 Reply Last reply
    0
    • V V 2

      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...

      J Offline
      J Offline
      John Ad
      wrote on last edited by
      #2

      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

      V 1 Reply Last reply
      0
      • J John Ad

        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

        V Offline
        V Offline
        V 2
        wrote on last edited by
        #3

        Thanks for your response How can i call the Api function GetScrollRange and can i also set width using this function??? if yes then how??

        Unless u don't give ur hundred percent whatever u r doing till there is no result of ur work...

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups