Design question...

C

craig

I have am working on an app that has many forms. I would like to make each
of these forms capable of interacting with the Windows Clipboard. I did
some research and found out how to do this using the Windows API, which
involves overriding one of the Form methods.

Am I correct in thinking that the best way to add this additional
clipboard-related code to each form would be to subclass the Form class and
create a new ClipboardEnabledForm class? Because of the fact that I need to
do method overrides, I don't know of any other approach. I want to maximize
code reuse. Would there be any pitfalls to subclassing the Form class?

Thanks for any input!
 
O

Otto Havasvölgyi

Hi,

In what way should the form interact with the clipboard? On keystrokes
(Ctrl+Ins etc.)? Please write some details about your concept.

Best Regards,
Otto
 
B

Bruce Wood

You do realize that TextBoxes in particular, and many other Controls,
have copy / cut / paste support built into the framework versions...?

What other kind of clipboard interaction are you thinking of?
 
C

craig

Yes, I realize that many controls have built-in cut/copy/paste
functionality. But it seems to me that a polished Windows app would go
beyond that, to have an edit menu which also includes the cut/copy/paste
buttons. In that case, the buttons would need to become enabled/disabled
based upon the current contents of the clipboard, and whether a valid
windows control currently has the focus, etc (exactly the functionality
found in any MS Office app, for example). In order to be able to do this,
the spp would need to know when the content in the clipboard is modified,
even by a different app.

I found the following article that describes implementing this behavior:

http://www.developer.com/net/csharp/article.php/3359891

However, I would like to find a way to be able to add this behavior to
several forms in my app without adding all this code to every form
independently. It would be better to be able to write this code once and
then resuse it in each form as desired.
 
B

Bill Gregg

Have you thought about using the Decorator pattern? I believe that this
would solve your problem without requiring you to subclass. Then you
can choose at runtime which windows forms will be decorated with Cut and
Paste ability. Just a thought.

Bill Gregg
 
C

craig

That is exactly the type of input I am looking for. Thanks, Bill.....I will
check out that pattern.

Also, I just came upon the NativeWindow class in the .Net Framework that
might make what I am trying to do possible.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top