Sizing a TextBox
Sizing a TextBox
Sizing a TextBox
Sizing a TextBox
Sizing a TextBox
Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox
Sizing a TextBox Sizing a TextBox
Sizing a TextBox
Go Back  Xtreme Visual Basic Talk > > > Sizing a TextBox


Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2018, 08:38 AM
leezinho leezinho is offline
Regular
 
Join Date: Jun 2009
Posts: 59
Default Sizing a TextBox


In my VB5 program I have a (Locked) TextBox that I use for a pop-up Help message.
The length of the message varies from about 200 to about 1500 characters.
I make the height of the box dependent on the width, to match the aspect ratio of the screen.
How can I set the width of the box to insure that the entire Help message is shown, but without too much blank space, _on any monitor_?
Reply With Quote
  #2  
Old 02-06-2018, 09:32 AM
Cerian Knight's Avatar
Cerian KnightSizing a TextBox Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,205
Default

I believe VB5 supports Me.TextWidth(strText). This comes in handy for on-the-fly fit calculations if the Form and TextBox share the same Font/Style/FontSize.

Here is some banter on the subject:
How to get Text Width - Visual Basic (Microsoft) Versions 5/6 - Tek-Tips
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').
Reply With Quote
  #3  
Old 02-06-2018, 09:02 PM
leezinho leezinho is offline
Regular
 
Join Date: Jun 2009
Posts: 59
Default

Thanks, Cerian Knight.
I hate to admit defeat on this problem,
but when I look at the contorsions I would have to go through to get a proportional TextBox,
it doesn't seem so bad to have a one-size-fits-all box with varying amounts of blank space.
I may revisit this problem when I have more time to invest in it.
Reply With Quote
  #4  
Old 02-08-2018, 07:10 AM
Daigon Ali Daigon Ali is offline
Regular
 
Join Date: Aug 2014
Location: London
Posts: 71
Default

Hi leezinho,

I was looking at maybe using the scrollbar to determine if all the text was visible and then resizing it until was.

With a normal TextBox you can have a vertical scrollbar, but this is visible all the time and just disabled when all the contents is visible. Also, there doesn't appear to be an easy way of determining if it is disabled or not.

However, if you used a RichTextBox then the vertical scrollbar automatically appears/disappears and this can be detected.

So, if you have a form with a RichTextBox and a CommandButton, add this declaration and function:
Code:
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_Style = (-16)
Private Const WS_HScroll As Long = &H200000

Function ScrollBarVisible(hWnd As Long) As Boolean
  Dim ws&, h As Boolean
  ws = GetWindowLong(hWnd, GWL_Style)
 ScrollBarVisible = ws And WS_HScroll
End Function
Then in the button's click event expand the RichTextBox until the scrollbar is no longer visible.
Code:
Private Sub Command1_Click()
Do While ScrollBarVisible(RichTextBox1.hWnd) = True
    With Me.RichTextBox1
        .Width = .Width + 10
        .Height = .Height + 10
    End With
Loop
End Sub
When you run this, fill the RichTextBox until the scrollbar appears, click the button and it should expand to fit the text.

Last edited by Daigon Ali; 02-08-2018 at 07:20 AM.
Reply With Quote
Reply

Tags
message, box, width, textbox, set, blank, screen, space, aspect, ratio, insure, match, monitor, shown, entire, _on, characters, locked, program, vb5, pop-up, length, height, dependent, sizing


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Sizing a TextBox
Sizing a TextBox
Sizing a TextBox Sizing a TextBox
Sizing a TextBox
Sizing a TextBox
Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox Sizing a TextBox
Sizing a TextBox
Sizing a TextBox
 
Sizing a TextBox
Sizing a TextBox
 
-->