|
-
Mar 7th, 2003, 08:38 AM
#1
Thread Starter
Frenzied Member
Right justify text in list box?
It seems difficult to right justify text in a text box.
Does anybody have some clues? I think I could write the code with a few hints.
Is there some way to get the length of a string in twips or some unit other than characters?
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 7th, 2003, 08:42 AM
#2
Junior Member
Set the textbox property 'Alignment' to "Right Justify".
The arrow shot by the archer may, or may not, kill a single person. However, stratagems devised by a wise man, can kill even babes in the womb.
-
Mar 7th, 2003, 08:48 AM
#3
Addicted Member
But he said listbox in the title.
-
Mar 7th, 2003, 08:48 AM
#4
Fanatic Member
Right justify text in list box?
The Listbox does not have a right justify the texbox does .which one do you want?if its the textbox then look at the answer give by Guile
-
Mar 7th, 2003, 08:51 AM
#5
Junior Member
I paid more attention to the post, then the title. <Shrug>
The arrow shot by the archer may, or may not, kill a single person. However, stratagems devised by a wise man, can kill even babes in the womb.
-
Mar 7th, 2003, 08:52 AM
#6
PowerPoster
your thread subject asks about a list box and the body of your quesiton asks about a text box. you need to decide which one you want to know about because they are not the same. If you really want to know about a text box, then as Guile.NET has stated, it is trivial.
if you want to know about a list box, then (1) there is probably some way to do it through subclassing and/or API calls, but I don't know how, or (2) you can fake it by using a fixed width font such as courier and then putting a variable number of spaces onto the front of each item to make them all come out the same length
-
Mar 7th, 2003, 08:58 AM
#7
Addicted Member
Guv's abilities are well enough known to lead me to think it's a typo, cuz I'm quite sure he knows how to justify in a text box.
-
Mar 7th, 2003, 09:06 AM
#8
Junior Member
Without even knowing Guv, or his abilities, I'm thinking the same thing.
In fact, I didn't even realise there _was_ a mistake, I just assumed he is new to VB, and wasn't aware of the property value.
That being said... no, I don't know how to Right Justify text in a List Box. =)
The arrow shot by the archer may, or may not, kill a single person. However, stratagems devised by a wise man, can kill even babes in the womb.
-
Mar 7th, 2003, 09:07 AM
#9
Thread Starter
Frenzied Member
Sorry about the typo. It is a list box that I want to right justify.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 7th, 2003, 09:49 AM
#10
create a new project and add a listbox to it..
put this code in and run the project. You should be
able to work with this.
VB Code:
Option Explicit
Private Sub Form_Load()
List1.AddItem "TESTING"
List1.AddItem "ANOTHER ITEM"
List1.AddItem "YET ANOTHER ITEM"
RightAlignListBox List1
End Sub
Public Sub RightAlignListBox(lstBox As ListBox)
Dim lTextSizePix As Long
Dim lSpaceSizePix As Long
Dim lSizeNeeded As Long
Dim i As Integer
'MAY NEED TO CHANGE THIS VALUE TO ACCOMODATE SMALL GAPS ON THE RIGHT SIDE,
'EITHER TOO MUCH SPACE OR NOT ENOUGH SPACE. 50 WORKED WELL FOR ME
Const Variable_Difference = 50
lSpaceSizePix = Printer.TextWidth(" ")
For i = 0 To lstBox.ListCount - 1
lTextSizePix = Printer.TextWidth(lstBox.List(i))
lSizeNeeded = ((lstBox.Width * Screen.TwipsPerPixelX) - lTextSizePix) - Variable_Difference
lSizeNeeded = lSizeNeeded / lSpaceSizePix
lstBox.List(i) = Space(lSizeNeeded) & lstBox.List(i)
Next
End Sub
Private Sub List1_DblClick()
Dim strItem As String
strItem = Trim(List1.List(List1.ListIndex))
MsgBox "Text: " & strItem & vbCrLf & "Length: " & Len(strItem)
End Sub
-
Mar 9th, 2003, 11:15 AM
#11
Thread Starter
Frenzied Member
Kleinma: Your code looks reasonable. I will try it and experiment a bit.
Printer.TextWidth Function looks like the key to this task.
Thanx !!
If all else fails, I will try simulating a List Box using a Text Box. which might be the easiest way to go.
I want to avoid changing to a change to a Text Box because there is some tricky logic associated with my current List Box. I am using it to simulate a LIFO Stack. The last Item is at the bottom at a fixed height on the Form, with the Top moving as items are added.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
-
Mar 9th, 2003, 12:41 PM
#12
Originally posted by Guv
Kleinma: Your code looks reasonable. I will try it and experiment a bit.
Printer.TextWidth Function looks like the key to this task.
Thanx !!
If all else fails, I will try simulating a List Box using a Text Box. which might be the easiest way to go.
I want to avoid changing to a change to a Text Box because there is some tricky logic associated with my current List Box. I am using it to simulate a LIFO Stack. The last Item is at the bottom at a fixed height on the Form, with the Top moving as items are added.
make sure you set the forms scalemode to pixel as well..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|