Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form's Print method

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
I have a problem with the Print method of a form.

I wouldn't nornally use this method, but it does seem to provide a simple way of doing what I want. Essentially, I want to display some text temporarily in various parts of the form, with the text superimposed over the controls.

To simplify, I am doing something like this:

thisform.CurrentX = 200
thisform.CurrentY = 200
thisform.Print("Hello World")

The problem is that sometimes this works OK, but sometimes the text is obscured by the objects in the form.

Is there any way I can force the text to appear above the controls? (I've tried playing with ZOrder(), but I don't think that's any help.)

Thanks in advance.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Assuming that the superimposed text will be merely a displayed text and not have to be an Active, Enabled Input TextBox, have you considered the somewhat crude method of working with the Enabled and various Layout controls?

* --- 'Hide' Object ---
This.Enabled = .F.
This.DisabledForecolor = RGB(<whatever>) && Maybe RGB(212,208,200)
This.DisabledBackcolor = RGB(<whatever>) && Maybe RGB(212,208,200)

* --- 'Show' Object ---
This.Enabled = .F. && Non-Input Text Display (.T. for 'real object)
This.BackStyle = 0 && Transparent for Text display (1 for 'real' object)
This.DisabledForecolor = RGB(255,255,255)
This.DisabledBackColor = RGB(0,0,0)

Also, if necessary, playing with the .Height & .Width controls.

Good Luck,
JRB-Bldr
 
logically I don't think you can do that. since you're printing to the parent form, all of the controls are on top of the form itself.... A possible workaround would be to add a transparent shape to the form as an overlay and always force it to the top .... print to that object instead of to thisform.

Andy Snyder
SnyAc Software Services
 
JRB-Bldr,

Thanks for your reply, but I don't understand your suggestion. Which object are you referring to? Are you suggesting that I should disable all the controls on the form? I'll give it a try, but I don't see how it will help.

Sorry if I've misunderstood. I'd be grateful if you could clarify.

Andy,

Your idea of adding a transparent shape sounds promising. Unfortunately, you can't print directly onto a shape object (or any object other than a form).

I suppose I could use as container instead of a shape, and add labels to it, instead of using the Print method. It's complicated by the fact that the form is scrollable, and so everything has to be relative to the current viewport. Also, the form is a drag-and-drop source and target, so I'd have to do some extra steps to make sure the container doesn't interfere with that.

The attraction of the Print method is that I can quickly clear all the text by putting a CLS in the MouseMove method. That's why I didn't want to add lots of individual objects, which I would then have to keep track of so that I can release them later. Perhaps by using a container, I can make the whole thing invisible rather than hiding or destroying lots of individual labels.

I'll experiment some more, but I'm anxious for it not to get too complicated.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
How about using a form class, without titlebar, borderless, position and size it where the text should go and print to that?

Code:
PUBLIC o

o = CREATEOBJECT("printform",10,10,68,16)
o.show()
o.print("Hello World!")

DEFINE CLASS printform as Form 
   TitleBar = 0
   Borderstyle = 0
   PROCEDURE init()
      LPARAMETERS tnTop, tnLeft, tnWidth, tnHeight
      this.Top = tnTop
      this.Left= tnLeft
      this.Width= tnWidth
      this.Height = tnheight
   ENDPROC 
ENDDEFINE

Bye, Olaf.
 
Olaf,

Actually, I did consider exactly that idea. However, the form would have to be transparent in order for the text to appear above the controls in the other form.

I know how to make a form transparent, but only for top-level forms. I could make the form top-level and hide its taskbar button, but then I'm not sure if I'd be able to keep it in sync with the underlying form as the user moves the viewport.

Still, it's worth pursuing. I'll play around with it. Thanks for the suggestion.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

In what types of cases is the text obscured by the form's objects? In my simple tests this doesn't happen.

Jim
 
Hi Jim,

Good question.

If I just print a single piece of text, it works fine. If I do the printing in a loop (with different text to different X,Y co-ords), then all the text gets obscured.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike,

I created a default-size form with several different controls scattered on it. In the dblclick method of the form I have:

FOR i = 1 TO 10
THISFORM.CURRENTX = i * 25
THISFORM.CURRENTY = i * 20
THISFORM.PRINT('Hello world')
ENDFOR

When I run this code "Hello world" is legible and "on top" in all cases. You must be doing something different...

Jim
 
Jim,

You're right. I must be soing something different.

I'll think I'll do what you did. I'll start with a plain form, with just a few simple controls on it. If that works, I'll gradually add functionality until it resembles my actual form. With luck, that should pinpoint the problem.

Thanks for your help with this.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Aha! I think I'm getting somewhere.

The text is only obscured by controls that are inside containers. Any controls that are placed directly on the form surface don't obscure the text.

I don't see why that should be, but at least it gives me something to work on.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Make sure your containers are "sent to back" maybe?

Also, if you're going to need any ActiveX controls on this form, I don't think this strategy will work (but you probably knew that).

Tamar
 
Tamar,

Good suggestion. But, tell me, how do I "send to back" programmatically? I know how to do it at design time, but all the controls on the form are created at run time (as a result of drag-and-drop).

If the answer is to call the objects' ZOrder(), I have already tried that (but I might not have done it correctly).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
There's only Zorder(1) (sent to back) and Zorder(0) (bring to front). If you only treid Zorder() without parameter that was the false 50:50 chance... :)

I also can't reproduce your behaviour. print prints text in front of everything in my tests, even in front of opaque containers.

But do you print before setting controls visible? Then the controls paint over the text. At refresh or scroll I think the same happens. So as easy as it seems to make use of print, you're perhaps better of with real objects, like labels or even forms in front of everything.

Bye, Olaf.
 
Is there any activeX control on the form. ZOrder() never effect them on runtime. This is the official bug accepted by MS also too. So if you say yes and your text is conflicting with it cant do anything
 
Well, I'm ready to give up with this one. I'm definitely seeing different behaviour from Olaf and Jim, even after reducing the form to its simplest.

The best I've got is that, if I make the containers transparent, the containers themselves don't obscure the text. But the controls within the container do.

Alpaslan: Thanks for your comment, but there are no ActiveX controls on the form, and, in any case, I don't think ZOrder() is the root of the problem, as Olaf's tests showed.

Olaf: Yes, I print after making the controls visible. I can't do it any other way, because of the nature of the interface.

I know I can achieve my goal by showing individual labels for the text, and I'll probably end up doing that.

What attracted me to the Print method was that I could display as much text as necessary, and clear it all with a simple CLS() call. I do that in the MouseMove event, so I wanted to make it as lightweight as possible. With individual labels, I'm going to have to keep track of the object references to all the labels, so that means maining an array or collection of the references, then looping throug it to clear them.

Anyroad, thank you all for your useful suggestions and comments. This was the first time I tried to use the Print method, and I've learned a lot.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top