views:

38

answers:

1

I am making a custom textbox control and am thinking about adding keybindings in the constructor that execute commands to open and save files. I am also thinking about handling the find and replace dialog from within my textbox control.

Is there a reason I shouldn't do this?

--Edit--

I am planning on only using this control in my current application. One of the reasons I am thinking of doing this is to avoid binding to the textbox's Text property, since this binding seems like it would be just as inefficient as updating a string on the textbox's textchanged event.

+1  A: 

Well, flexibility comes to mind. Consider the following scenarios, which would be impossible (or at least difficult) in your control:

  1. You want to handle multiple or different methods of opening a file, but it depends on your application.

  2. You want to use your textbox but limit the functionality -- e.g., Find/Replace is not allowed.

  3. You want to change the behavior of any of that in one application but not the other. For example, in app A you want to tack on an extra slash to the end of the text, but in app B you want to add a custom folder name.

In general, I would consider something more generic. Something like a textbox has a specific purpose; enhancing that purpose is fine, but you're going beyond that. You're taking logic that rightly belongs to the app and putting it on a specific control. That limits what you can do with the control across multiple apps.

Of course, if you're writing a control specifically for one and only one app, you don't need to worry about these things. But I would still consider it a bad practice, myself.

Ari Roth