-
Hi,
I'm having a bit of trouble positioning. Could you help me?
I've made a function that displays fractions in the form:
6
--- (as opposed to 6/7)
7
The fractions will appear in a Picturebox, and I'll be calling the function many times throughout my project.
However the text before the fraction can change, so I can't hardcode the position of the fractions. I've posted my function below with an example of a call from Command1. How can I have it so that the bottom part (in the above example '7'), is always directly under the top part '6'?
Thanks!
---------
Private Sub Command1_Click()
Dim number As Integer
Dim number2 As Integer
Randomize
number = Int(Rnd * 200)
number2 = Int(Rnd * 200)
Picture1.Cls
Picture1.FontSize = 14
'this text can change
Picture1.Print "And the answer is: ";
Picture1.Print WriteUnderline(number, number2)
End Sub
Public Function WriteUnderline(X As Integer, y As Integer) As String
Picture1.Font.Underline = True
Picture1.Print X;
Picture1.Font.Underline = False
'don't know how to do this part - just took a wild guess.
Picture1.CurrentX = TextHeight(X)
Picture1.CurrentY = TextWidth(X)
Picture1.Print y;
End Function
-
hmm
I did not try to understand too much from what you were saying... But what immediately pooped into my head is
what not create to picture boxes very close to each other
one for the text the other one devoted to the fraction
Or just put the text in a label next to the picture box
?!
-
The actual keypoints to remember are the CurrentX and CurrentY properties. Use these to set the X and Y position of the text.
-
Thanks for the help.
HeSaidJoe, your code has put me on the right track, but (tell me if I'm wrong) it assumes that the integer, 'number', will always be on the first line of the Picturebox.
Your code, Picture1.CurrentY = TextHeight(X) * 1.5, takes the height of 'number', multiplies it by 1.5, and positions 'number2'. But what if 'number' is placed half way down the Picturebox? Number2 will still be placed around the second line, whereas I want it to appear directly under 'number'.
This is an example of what I'm looking for:
---------------------------------------------
| |
| number |
| ------- |
| number2 |
| number |
| ------- |
| number2 |
| |
| |
---------------------------------------------
No matter where number is, number2 appears directly under.
One way I was thinking for the Y coordinate was (I'll worry about X coordinate later):
Find the distance from the base of 'number' to the top of Picture1. - e.g it might be 5, 340, 26...or whatever....and that's where currentY for number2 would be.
I thought it would be something like:
Picture1.CurrentY = Picture1.Height - (Picture1.Height - TextHeight(X))
but it didn't work.
Any ideas on this one, please?
-
My diagram in previous post is screwed up. Don't know why. Basically number2 is always under number:
number
------
number2