×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

set all rightclick method of all textboxes in a form

set all rightclick method of all textboxes in a form

set all rightclick method of all textboxes in a form

(OP)
hello,

Is there a method like setall to set all rightclick method of all textboxes of a form?

for example i want to set all rightclick of all textboxes to copy the value to the clipboard

thank you

RE: set all rightclick method of all textboxes in a form

Yes, design a textbox class with that and use it, that's the simplest way of having that. Simple OOP.

If you don't want that it becomes a bit more cumbersome, actually, though you don't need to replace any textbox. We discussed that not very long ago: using BINDEVENTS.

What you need anyway, is a class that has the rightclick code in it, that becomes the handler of the rightclick events happening in your textboxes. BINDVENT then redirects the event processing from the textboxes that have no code in them to your nes class that has. It can be a custom class, it doesn't need to be a textbox. And the method that then actually has the rightclick code in it doesn't have to be named rightclick, you specify which event of an object triggers which method of the handler.

And, you see, you have to have a class with a method that has the rightclick code in it, anyway, so why not subclass the textbox to a new textbox class with that feature? You don't get around having a class anyway. if you absolutely want to mess with the design of your application you can use the form designer you use already, I assume, and add a method to the form, which means you make the form the eventhandler for all your textboxes and have a form method do the rightclick code. So you can avoid to get into OOP that way, while you already bathe your hands in it with the form designer anyway. And then you still have to write a loop iterating all textboxes to do a Bindevent call for each of them.

You could also simply go a standard way and let the right click start a context menu that has an item for copy. But even without that a user can always do CTRL+A ,CTRL+C to copy the current control's content to the clipboard.

Anyway you do it - with context menu, or with bindevents - you have to do more than just write the rightclick code, and so the textbox with rightclick code is the simplest solution in that respect. You just then need to replace all your textboxes with your new class. The not-so-old thread184-1819758: Adding a Procedure to Multiple Objects has a hack to solve that, too, by changing the class of textboxes from textbox to your new class in the scx file. Or append code. But use such hacks with caution...



Chriss

RE: set all rightclick method of all textboxes in a form

The obvious solution is to create a textbox class; put the required code in the right-click of that class; then use the class for all the trextboxes on the form. The individual textboxes will then inherit the right-click code.

But in this case, it is presumably too late for you to do that. You have already created the form and added all the textboxes to it. Although Chris has suggested a possible solution, using BINDEVENTS(), you might find it simpler to simply delete all the existing textboxes and to replace them with textboxes based on the class.

If, in the individual textboxes, you have already set any properties to non-default values, or if you have added any code to any of the other events or methods, you would have to repeat those changes in the new textboxes. But where any such changes apply to all the textboxes (for example, if you have set the MaxLength of all the textboxes to the same value), then you only need to make that change once, at the class level.

If nothing else, this exercise should convince you of the benefits of object-oriented programming.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: set all rightclick method of all textboxes in a form

(OP)
thank you Chris and Mike

RE: set all rightclick method of all textboxes in a form

If you're really stuck with a form that has a bunch of VFP baseclass textboxes and you don't want to change them to use a custom class, you can add code in the form's Init method to apply BindEvent to each textbox. You can have a form method act as the event handler and use the AEVENTS() function in that method to determine what textbox you're dealing with.

I wrote about BindEvent() here: http://tomorrowssolutionsllc.com/ConferenceSession...

Tamar

RE: set all rightclick method of all textboxes in a form

I know it's probably frowned upon, but I have put code snippets against all text boxes in a project that invoke a right click menu
running the FSSPell product in the past, using code that opened the forms, processed all the elements looking for text boxes
and then added right click methods if they did not already exist... not at all difficult to do - so long as you have a backup!

Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: set all rightclick method of all textboxes in a form

Didn't you also came to the conclusion you can use your SCX manipulation to change the class of objects?

There is a memory footprint difference of adding the same lines to the code memo of all textboxes of a form than to have a class with that code once. A classs is only loaded into memory once. So the first instance of a textbox class is loaded into memory and further instances of it refer to that. That's also the reason CLEAR CLASS works if and only if all instances of a class are released. So no object refers to the first loaded code anymore.

If you hack an SCX and add code to all textboxes you load one baseclass textbox that has no rightclick code, but all code added to the individual textboxes, no matter if it's all the same code, is loaded for each of these base textboxes, so the same code is loaded X times.

In the age of abundant memory it doesn't matter much, but it's also one advantage of OOP.

Chriss

RE: set all rightclick method of all textboxes in a form

There's another possible solution that I can recommend: Rick Schummer's excellent HackCX Professional product. (See http://www.whitelightcomputing.com/prodhackcxpro.h...) I've been using this for many years now, and it's saved me a lot of time and trouble.

Essentially, you would create a custom textbox class that contains the required code in the RightClick event, as well as any other customisation common to most or all of your texboxes. You then use HackCX to rebase all the existing textboxes on the custom class. And that's all there is to it. All the other customisations would be preserved. And if nothing else it will provide you with a painless first step into using classes.

HackCX is not free, but it is not very expensive, especially given its many other uses.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: set all rightclick method of all textboxes in a form

Yes, no doubt, and the duplication of code is a waste of resource and it's no quicker...



Regards

Griff
Keep Smileing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0

RE: set all rightclick method of all textboxes in a form

Tom, you're right. Thor has "Re-Define Parent Class" tool. I've never used it, because I already had HackCX when the Thor tools came out. But it looks like it would be worth a look.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close