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

set all rightclick method of all textboxes in a form 1

Status
Not open for further replies.

Akourou

Programmer
Mar 28, 2019
34
0
0
GR
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
 
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 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
 
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
 
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:
Tamar
 
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 [Smile]ing

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
 
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
 
There's another possible solution that I can recommend: Rick Schummer's excellent HackCX Professional product. (See 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
 
Yes, no doubt, and the duplication of code is a waste of resource and it's no quicker...



Regards

Griff
Keep [Smile]ing

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top