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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to assign an event to a TEXT BOX

Status
Not open for further replies.

FoxEgg

Programmer
Mar 24, 2002
749
AU
This is a bit embarrassing... because I am not sure how to ask the question I want answered... But I can describe the problem.

I have some code which I have put in the RIGHT CLICK event of a Text Box...It lets me Right Click and Copy or Paste (thanks to those who helped me develop that)

Code:
LOCAL lEsc
lESC = SET("ESCAPE")

DEFINE POPUP myPop SHORTCUT RELATIVE FROM MROW(),MCOL()

DEFINE BAR 1 OF myPop PROMPT "Copy"
DEFINE BAR 2 OF myPop PROMPT "Paste"


ON SELECTION POPUP myPop DEACTIVATE POPUP

ACTIVATE POPUP myPop
DO CASE

CASE BAR() = 1
Sys(1500, '_MED_COPY', '_MEDIT')


CASE BAR() = 2
Sys(1500, '_MED_PASTE', '_MEDIT')


ENDCASE
**
RELEASE POPUP myop
SET ESCAPE &lESC

Now (belatedly) I have decided to put this Right Click code in all the text boxes on the Form. Is there an easier way to do this other than copy and paste into the right click code box for each text box ?

*** I am also thinking of coding a colour change when the box has focus... hence the same issue of copying to many text boxes.

OR Can I define my own text box with that pre-programmed (Now am really showing my ignorance.

Thanks in advance...

John Fox
 
John,

Can I define my own text box with that pre-programmed

This is the key to your problem. What you can - and should - do is to create your own textbox class. You do that in the Visual Class Designer.

Basically, you create a class based on the standard text box, and give it whatever properties and behaviours you want. That will include its right-click menu and the colour change on focus.

Then, throughout your forms, you remove the existing textboxes and replace them with your custom textbox class. Once you've done that, you can make any changes you like to the class, and that change will be inherited by every textbox in the application (unless you stipulate otherwise).

You're probably thinking that it's going to be a lot of work to change every text box in this way, and you'd be right. It's too late to tell you this now, but you should have started with your own classes from the outset. That way you would have all the benefits with no additional work. Something to think about for your next application, perhaps.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Thanks Mike... Much appreciated .. That is what I wanted

I remember reading topic that once but I forgot the key words... I will find a Tutorial somewhere.

JF
 
John, I change the background color of all of my controls, texbox, combo, etc. when they have focus through the use of classes as Mike has suggested. In your base classes create a property to hold the current background color. Set this property to the current background color in the got focus method and immediately set the color to whatever you want. In the lost focus method just set the color back to the original color. I even let the users choose what color they want from a list in the user setup. I prefer a light yellow. One note, if you are using the back color to indicate other things like using red to indicate a bad date, then you might have to do something special for those situations.

Auguy
Northwest Ohio
 
Oops, forgot something. I also added an override flag to cancel the background color behavior if it wasn't apporpriate for the current usage of the control.

Auguy
Northwest Ohio
 
Auguy...

Not a good idea to change background colors. A high percentage of people are color blind, some are shade blind. You may actually prohibit people from see the text in the control. Best option is to leave color settings at defaults. VFP will then use the colors the user selected in Windows Display Settings. Also, depending on who your customers are, you could be violating the American with Disabilities Act.

Craig Berntson
MCSD, Visual FoxPro MVP,
 
If you feel strongly that you do want to change colors from the standard, you should use only colors that are in the user's selected Windows colors. You can use the API function GetSysColor to find those colors, so you can apply them.

Tamar
 
Thanks Tamar. I think my users would be very upset if I took away the background color changing with the control that has focus. Currently I limit them to a few choices, a couple of shades of gray, a couple of blues, a couple of yellows, and white. I guess I'll look into the API function and see what I can work out.

Auguy
Northwest Ohio
 
Thanks All... I'll go and read up how to do this Classes thing...

Gotta appreciate the Auguy and his NW Ohio opinions.. Having lived 8 years in Cleveland, I can sympathize.

Sydney now.. current temp = 30C.... Pool time. Hehehehe.

PS if anyone knows any good "Visual Class Designer Explained for Aussie Dummies" (or web sites) please let me know.

John Fox

 
Gotta appreciate the Auguy and his NW Ohio opinions

Auguy,

I've always meant to ask you - what exactly is Northwest Ohio? North west of Columbus presumably? Perhaps around Toledo?

The only reason I ask is that I have a good client in Cleveland. I'd guess you'd call that Northeast Ohio. But what do I know?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
John, thanks for the weather info. I'm a cold weather guy and your 30C sounds a bit warm for me. I don't like anything over about 70F, unless of course you are at the pool. As you know around here when the temp is in the 80F's and above we get the humidity, which I really hate. But even I was a little chilly last week when it was -15F with a wind chill of about -40F a couple mornings. I can't believe you actually left Cleveland For Australia (joke)!

Mike, I actually live in a suburb of Toledo. Around here most people consider Northwest Ohio to be slightly less than the upper left 1/4 of the state. Just a note, many years ago when Fox was in Perrysburg I used to go their offices and pick up my updates. I believe the son of one of the founders of Fox still lives a few miles from me. As far as Cleveland, it is considered to be in the Northeast part of the state. For those of you that don't know this area of the US and see or hear that Cleveland received some massive amount of snow, it could be the Northeast parts of the city and the suburbs of Cleveland that received a foot or two of snow, but the rest of the city may not gotten much of anything because of the lake effect snow.


Auguy
Northwest Ohio
 
Auguy,

Now you mention it, I suppose it's obvious that north west Ohio is the top left corner. I was a bit confused by the somewhat irregular shape of the state. (Mind you, I shouldn't talk; Scotland is one of the most irregular countries in the world.)

What you said about the snow is interesting. I might be visiting my client before the end of the winter. They're out in the suburbs, to the south east. I'll have to get a very local weather forecast before I set out.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Yes, the weather can very tricky around there in the winter. I was there a few years ago during a snow/ice storm and had to drive home in the middle of it. Of course as soon as I got to the western portions of the city, there was no snow or anything, just sunshine. My car had snow and ice caked all over it and I got the strangest looks as I drove along west I80.

Auguy
Northwest Ohio
 
You guys are all serious scaredy cats... Snow is fun... I remember first time I drove in snow in Cleveland OH. In my Renault Le Car. 500cc of wimpy muscle... before they ploughed and salted I was off to the Clinic at 5 am... The first corner found me on front lawn of someone's house. That's the problem when u come from Oz... I doesn't snow here ever.

Lake effect is great... one minute its clear ... then its a dump.

Enjoy Cleveland Mike.

J
 
J, I love cold and snow. There's nothing better than a good snow storm. Like I said before, I prefer the cold to the heat. Most of the people I know make fun of me because I rarely wear a coat unless it was like it was last week (-15F). Basically I'm miserable (hot) from about June through mid September.

Auguy
Northwest Ohio
 
I prefer the cold to the heat

I'm with you there. Give me a snow-covered mountain with a sharp bite in the air and a winter's sun drifting above the horizon, and you can keep your beaches and tropical paradises. (Well, I can tolerate an occasional tropical paradise, I suppose.)

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