Displaying text on a screen/form

Dragonspank

Member
Licensed User
Ok, haven't done any basic programming since days of Commodore64 basic.
Dumb question:
How do you print text on the screen/form? Say for example that I had a variable named "tries" that I wanted to display in the bottom left hand corner.And a percentage in the right hand corner.
Any help greatly appreciated.
:sign0085:
 

Cableguy

Expert
Licensed User
You have several ways to Write on the screen, the most coomon is a lable, wich the user has no action on...
You can also use a textbox, but it is changeable by the user, and it's main purpose is to allow the imput of value or text...
The "last" option is to write directly on the form with DrawString...
U just have to decide what is best for your app...
 

Leginus

Member
Licensed User
If you look in the help section of Basic4ppc it will give you a section Called Main Help. Under here you will find Controls and under here Form as an object and it will give you the properties that are available.

The reason I mention this is not to be condscending, but for the simple fact that I think the this is a good help file as it does actually give real examples.

Anyway to display text on a form it is with your variable it would be
DrawString (String, FontSize, X1,Y1,X2,Y2, (R,G,B | Color Constant))

e.g.

sub App_Start()
dim Tries
Tries="Tries Text"

Form1.DrawString (Tries,0, 320, 0, 320, 80, 0, 0, 255)
End Sub
 

Dragonspank

Member
Licensed User
Need a liitle more info on the allowed values for x1.x2,y1,y2.
I have a square screen 240 x 240.
Also, if I did have a statement such as:

Form7.DrawString (Tries,9, 200, 320, 50, 155, 0, 0, 255)

And the variable Tries was equal to 1 the first time through. Next time through it is equal to 2. But when it is displayed the 2nd time it writes the "2" right overtop(overlapping) of the "1" and it is then impossible to tell what the number is supposed to be. Could I not just write a DrawString statement to erase the old value with blank spaces and then rewrite the new value? (I have tried and no avail with--- Form7.DrawString (" ",9, 200, 320, 50, 155, 0, 0, 255))
:sign0085::sign0161:
 

klaus

Expert
Licensed User
If your text is always at the same position you should use a Label control.
Position the control at the place you want in the Form Designer or by code.
By code it would be
Sub App_Start
Label1.Left=0
Labe1.Top=210
End Sub
These are the coordinates of the upper left corner of the control.

If your control is already on the right position in the Designer no need to do it by code. In the Designer you can display a default text or make it empty.

Then in your code you set
Label1.Text=Tries
This displays the value of your variable Tries on the Label without overlapping characters.

I joined a small example.
With the Button you increase a number by one and display it in the Label.

Klaus
Switzerland
 

Attachments

Leginus

Member
Licensed User
If there is no particular reason to draw direct to the screen, then a label would be you best option. see atached file
 

Cableguy

Expert
Licensed User
When workin with drawstring, to write on the same place 2 or more diferent strings...
before writing the new string, re-write the previous, with the color set to match the background, thus making it invisible...
There is also a method to erase a part of the screen...
Search trought the forelayer bit of the help file...
 
Last edited:

klaus

Expert
Licensed User
You can set the Color of the label the same as the color of the Form or the color of the image, no transparency.
With DrawString you can use FDrawString to draw on the ForeLayer, the Forelayer can be set to transparent with SetTransparentColor
Example:
Sub App_Start
SetTransparentColor (cWhite)
Form1.ForeLayer = True
Form1.Show
End Sub

But in your case the transparency of the Forelayer will not help, the problem of overlaying the texts remains. Still the best way will remain the Label with a background color similar to the image.

Klaus
Switzerland
 
Last edited:

klaus

Expert
Licensed User
To draw the string on the Form there is a solution with libraries, it's not the easyest way but it works.
The solution is to copy the part of the Form image where the string should be, in a bitmap object.
Then every time, before you draw a new string, copy back the stored original partial image.
Joined a test program.

Hope this helps you.

Best regards
Klaus
Switzerland
 

RandomCoder

Well-Known Member
Licensed User
This may be a little late in the game but you could use FErase to remove the previous number.
You only need to remove the area occupied by the number.
Using this along with FDrawString should work.

Regards,
RandomCoder
 
Top