erase text on form 
Author Message
 erase text on form

Dear all
I am doing the following to print text on a form:

a$="ABCDEFGH"
Me.CurrentX=100
Me.CurrentY=100
Me.Print a$

How can I erase this text and replace it with "abc".
I thought I can simply use
Me.CurrentX=100
Me.CurrentY=100
Me.Print Space$(len(a$))
and then
Me.CurrentX=100
Me.CurrentY=100
Me.Print "abc"

but this doesnt't work. Printing spaces do not erase the text that was
printed previously.
I know I can use Me.Cls to clear the whole form but that would also erase
other things I have on the form.
So how can I just erase a certain area on the form, some text that I have
printed previously and needs to be overwritten later. I don't want to use
labels, if possible.

Regards and Merry Christmas
Peter



Mon, 13 Jun 2011 05:34:19 GMT  
 erase text on form

<cut>

Quote:
> So how can I just erase a certain area on the form, some text that I have
> printed previously and needs to be overwritten later.

You could try something like this:
Me.CurrentX = 100
Me.CurrentY = 100
Me.ForeColor = Me.BackColor
Me.Print a$
Me.CurrentX = 100
Me.CurrentY = 100
Me.ForeColor = vbBlack
Me.Print "abc"

Quote:
> I don't want to use labels, if possible.

That would be the simplest.  Why not use them?  They don't have a window so
they aren't resource hogs and you can make them into a control array so you
only use 1 control name.

Any other solution is going to require that you determine the height & width
of the test on the form and paint that section with the background.  That's
pretty much what a label control does for you so you'd be re-inventing the
wheel.



Mon, 13 Jun 2011 05:45:03 GMT  
 erase text on form
You could use the line method, with BF to draw a filled box. If you are
doing this as a replacement for Debug.Print when running as EXE, you can use
OutputDebugString() instead, and use the following software to view the
text:

DebugView for Windows:
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

OutputDebugString declaration:

Public Declare Sub OutputDebugString Lib "kernel32" Alias
"OutputDebugStringA" (ByVal lpOutputString As String)

Usage:

OutputDebugString "abc" & vbCrLf



Mon, 13 Jun 2011 06:06:22 GMT  
 erase text on form
Many Thanks for your fast answer!
Your solution reprinting with backcolor works great!!!
Regards
Peter



Quote:


> <cut>
>> So how can I just erase a certain area on the form, some text that I have
>> printed previously and needs to be overwritten later.

> You could try something like this:
> Me.CurrentX = 100
> Me.CurrentY = 100
> Me.ForeColor = Me.BackColor
> Me.Print a$
> Me.CurrentX = 100
> Me.CurrentY = 100
> Me.ForeColor = vbBlack
> Me.Print "abc"

>> I don't want to use labels, if possible.

> That would be the simplest.  Why not use them?  They don't have a window
> so they aren't resource hogs and you can make them into a control array so
> you only use 1 control name.

> Any other solution is going to require that you determine the height &
> width of the test on the form and paint that section with the background.
> That's pretty much what a label control does for you so you'd be
> re-inventing the wheel.



Mon, 13 Jun 2011 06:13:13 GMT  
 erase text on form

Quote:

> . . . solution reprinting with backcolor works great!!!

If you're using the default value of False for the FontTransparent property
then that method won't work if the system is set to smooth the edges of
screen fonts, especially if it uses ClearType smoothing, because you will be
left with a "ghost outline" of the characters where the smoothing pixels
were drawn. It will work okay though if your set FontTransparent to False,
and in that case printing a string of space characters that you were
previously doing will also work, except that you will need to make sure that
the number of space characters is such that their total width exceeds the
total width of the string you initially printed, which is not the same as
simply matching the number of characters if you are using proportionally
spaced fonts. Personally I would advise going with expvb's suggestion of
drawing a filled box with the Line method.

Mike



Mon, 13 Jun 2011 18:52:51 GMT  
 erase text on form


Quote:


>> . . . solution reprinting with backcolor works great!!!

> If you're using the default value of False

I think you mean True there

Quote:
> for the FontTransparent property then that method won't work if the system
> is set to smooth the edges of screen fonts, especially if it uses
> ClearType smoothing, because you will be left with a "ghost outline" of
> the characters where the smoothing pixels were drawn.

I don't normally use any smoothing since I dislike the effect but it's
interesting that it wouldn't overwrite exactly the same pixels.


Tue, 14 Jun 2011 01:23:35 GMT  
 erase text on form

Quote:
>> If you're using the default value of False

> I think you mean True there

Yes, I did. Thanks for pointing it out.

Mike



Tue, 14 Jun 2011 01:56:13 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. printing form erases data in form fields

2. Erasing picture box text

3. Erasing text boxes subprocedure

4. CBO.Text Erases

5. Erase text on a bitmap?

6. Text Form Field Help Text - Does it work?

7. Selecting Text in a text form field.

8. Entering text in form field of locked document pushes text on same line

9. Sending text from one forn to a text box on another form

10. Starting query from a form (criterium being based on a text field in the form)

11. parse form a text file to an Outlook form

12. Protected Forms and Text Form Fields

 

 
Powered by phpBB® Forum Software