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

KeyPress in run time 1

Status
Not open for further replies.

and0b

MIS
Mar 27, 2007
51
US
How to use KeyPress methode in run time. I have a form on which I'm creating textboxes in run time. When user enters data, he is using ENTER key to jump to the next textbox. How to assing KeyPress method to the just created tsxtbox so it will working with ENTER key (13)?

Thnak you for any help.
Andrew
 
Don't just add baseclass textboxes to your forms. Create a textbox class that contains all the code you need it to have and when you add the textbox, use that class.

Tamar
 
Thank for quick reply, but I'm a beginner. Can you say little bit more? some samples?
 
Pressing ENTER in a text box is the same as pressing TAB as far as movement between controls using the keyboard. No need for any KeyPreview method code.

Andy Snyder
SnyAc Software Services
 
But I'm going to use also other events like GotFocus, LostFocus.
 
Pressing the Enter key should have no impact on the GotFocus and LostFocus events. You might pick up a copy of "The Fundamentals" at hentzenwerke.com. Although it was written for VFP6, most of the basic principles it covers still apply.

pamela
 
Here's how I'd do it.

In the Command Window:

CREATE CLASS

In the dialog that appears, give your new class a name. In this case, maybe something like txtAddAtRuntime. In addition, specify the name of the class library where you want to store this class. I gather you don't have any class libraries yet, so you just need to specify a folder and file name. VFP will add a VCX extension. Click OK.

The Class Designer opens up. Here you can write any code that should apply to every textbox of this class, as well as change any properties (such as Width and Height). You can also add custom properties and methods to do things that aren't built into textboxes. In the code you write, use THIS to refer to the textbox itself.

When you've made all your changes, save and close the Class Designer.

Now, in your form where you want to add one of these textboxes, instead of using:

ThisForm.AddObject("myNewTextBox", "TextBox")

use:

ThisForm.NewObject("myNewTextBox", "txtAddAtRuntime", "YourClassLib")

and presto, the newly added textbox will have all the code you need available.

All that said, why do you need to add textboxes at runtime?

Tamar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top