|
-
Jan 2nd, 2001, 08:48 AM
#1
Thread Starter
Member
Hi!
This should be pretty easy question! All I want to know is
how to write text on picturebox. I know how to do it in
Delphi but I have never tried doing it in VB. Please help!
Thanx in advance for any answer.
Celery
VB6 Pro SP3 - Academic Licence
-
Jan 2nd, 2001, 09:52 AM
#2
Fanatic Member
Hi,
I think this is what you are looking for...
Code:
Option Explicit
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
Private Sub Picture1_Paint()
Dim lRet As Long
Dim s As String
s = "HELLO WORLD!"
lRet = TextOut(Picture1.hdc, 5, 5, s, Len(s))
End Sub
Just make sure you put this code in the Paint event of the PictureBox or else the text will be erased the next time the PictureBox is redrawn.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Jan 2nd, 2001, 11:24 AM
#3
Thread Starter
Member
Isn't there any easier way to do this???
Celery
VB6 Pro SP3 - Academic Licence
-
Jan 2nd, 2001, 11:42 AM
#4
Fanatic Member
Alternatively you can use the Print method, however I don't recommend it.
Code:
Private Sub Picture1_Paint()
Picture1.Print "HELLO WORLD!"
End Sub
Once again make sure the code is in the Paint Event
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Jan 2nd, 2001, 12:43 PM
#5
PowerPoster
TextOut is not that hard... please dont use the Print command Ill explain the same with more comments:
Code:
'Add this to the declares-section of your form:
Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" _
(ByVal hdc As Long, ByVal x As Long, ByVal y As Long, _
ByVal lpString As String, ByVal nCount As Long) As Long
'And this in the button where you want to draw
'the text (Replace Picture1, the coordinates
'and the text to fit your needs):
TextOut Picture1.hdc, 5, 10, "Hello World", Len("Hello World")
'Alternatively you can use a variable, makes
'code easier and better understanding:
Dim Temp as String
Temp = "Hello World"
TextOut Picture1.hdc, 5, 10, Temp, Len(Temp)
-
Jan 2nd, 2001, 01:02 PM
#6
Fanatic Member
If you use the TextOut (or the evil Print function) in a command button you will have to make sure that you redraw the text in the Paint event, else you will lose the drawn text when the PictureBox is repainted.
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
-
Jan 2nd, 2001, 01:19 PM
#7
PowerPoster
Excepting if you set AutoRedraw of the PictureBox to true, but then make sure you refresh the box to show
its changed contents:
Code:
TextOut Picture1.hdc, [...]
Picture1.Refresh
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
|