For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > Can I draw a string on a form?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can I draw a string on a form?

2006-04-26, 7:56 am

Can I draw a string on a form?


Larry Serflaten

2006-04-26, 7:56 am


<Weblearner> wrote
> Can I draw a string on a form?


Yes you can.

It may be far easier, however, to just use the built-in Print command.

Private Sub Form_Paint()
Cls
Print "Hello World"
End Sub


<g>
LFS


Mike D Sutton

2006-04-26, 7:56 am

> Can I draw a string on a form?

Sure, use the Print command, or the TextOut()/DrawText() API calls. There
are other more specialised API calls that draw text depending on what you
want to do, however generally TextOut() is used for single line and
DrawText() is used to multi-line text output.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/


Norm Cook

2006-04-26, 7:56 am

Assuming that 'draw' means display,

Private Sub Form_Load()
Dim sMsg As String
'persist picture
AutoRedraw = True
sMsg = "Hello, I'm a string."
'center the message
CurrentX = (ScaleWidth - TextWidth(sMsg)) \ 2
CurrentY = (ScaleHeight - TextHeight(sMsg)) \ 2
'display
Print sMsg
End Sub

<Weblearner> wrote in message
news:O%23inI0SaGHA.3896@TK2MSFTNGP05.phx.gbl...
> Can I draw a string on a form?
>
>



2006-04-26, 7:56 am



> It may be far easier, however, to just use the built-in Print command.
>
> Private Sub Form_Paint()
> Cls
> Print "Hello World"
> End Sub


Hello, I didn't mention, but I need the exact location, it needs to be at
a certain x-y location on the form?
Thanks!


Mike D Sutton

2006-04-26, 7:56 am

> Hello, I didn't mention, but I need the exact location, it needs to be at
> a certain x-y location on the form?


For Print, use the .CurrentX and .CurrentY properties of the form.
For TextOut(), you specify the coordinates as part of the call.
For DrawText() it uses the .Left and .Top properties respectively of the
RECT structure you pass it.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://EDais.mvps.org/


2006-04-26, 7:56 am

> Private Sub Form_Load()
> Dim sMsg As String
> 'persist picture
> AutoRedraw = True
> sMsg = "Hello, I'm a string."
> 'center the message
> CurrentX = (ScaleWidth - TextWidth(sMsg)) \ 2
> CurrentY = (ScaleHeight - TextHeight(sMsg)) \ 2
> 'display
> Print sMsg
> End Sub


Yes, this is fine, thank you very much !


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com