Sign in to follow this  
JBS103

Dock/Float Windows - C#

Recommended Posts

I am working in Visual C# 2005 and was trying to figure out the best way to create a dockable or floatable window (similar to the solutions explorer, etc.). I have a basic idea down on how to make it possible, but was wondering if there was a cleaner or better way than what I have. I only want simple and specific functionality so I'm trying to avoid a huge library with all the bells and whistles. (Plus this is a good learning experience, anyway). So here is how I though it out... To be more specific, I want to use a treeview component. I stick the treeview inside a panel and listen to mouse clicks on that panel. When a click and drag is registered, I make a new instance of a specific form I've created (before hand) and then I hide the original panel. Then I copy the treeview on the main form into the treeview on the new form. When a double click on the title bar is registered, I hide the form and make the original panel visible. It seems like it would work decently (and I'm pretty sure I'd have no problem doing it), however, copying the tree back and forth seems to be a downside. When a treeview gets large, does this back and forth cause problems? Is it a downside at all? Can I improve this design any? Would this set up allow for more functionality down the road (hiding on the edge and reappearing on mouse over, etc)? I'm only a novice so I might be missing something. I appreciate any response in advance.

Share this post


Link to post
Share on other sites
I doubt you want to make a copy of the control. Think about how you would handle complex controls such as ActiveX controls. During a drag-drop you should be able to add some user defined data. That data could simply be the instance of the control. Instead of making a new instance of the control and then copying the items from the old to the new, just transfer ownership of the control to the new container.

Share this post


Link to post
Share on other sites
Thanks for the response. Is there any good reading out there on control ownership? Any examples out there?.

I'm relatively unfamiliar with a lot of techniques.

Thanks again.

Share this post


Link to post
Share on other sites
Quote:
Original post by JamesLewis
You need to use 3rd party libraries to do this kind of stuff otherwise it takes too much time. Try this:

http://sourceforge.net/projects/dockpanelsuite/

There's more out there if you don't like that one.


Thankfully I have no deadlines, no specific requirements, or any other outside pressure so I am free to pursue whatever I feel up to. For that reason, I'd like to figure out the most basic functionality on my own without relying on libraries.

I understand reinventing the wheel is absolutely unnecessary, but in this case, I feel that I can accomplish what I am looking to do with a little help. I also believe that I will learn something getting through this little hang up and not just giving up. This may be a little bit silly but I am a "hobbyist" and nothing hangs in the balance of me finishing or not finishing. This pursuit is a very laid back "adventure". I'm looking for the means, not the ends.

I appreciate the advice.

Share this post


Link to post
Share on other sites
Quote:
Original post by JBS103
Thanks for the response. Is there any good reading out there on control ownership? Any examples out there?.

I'm relatively unfamiliar with a lot of techniques.

Thanks again.


Every control has a Controls member which is all of the controls that are its children. To add a control to another control:

Control foo = new Control();
foo.Controls.Add(blah);

To remove a control:

foo.Controls.Remove(blah);

Controls also know who their parent is (foo.Parent). So you have everything you need in order to remove a child control from one control, and add it to another. It might look something like this (note this is completely untested, I'm just throwin' it out there):

Control controlBeingDragged;//the control being dragged
Control dragDropTarget;//the form the user is dropping the control onto

Control oldParent = controlBeingDragged.Parent;
oldParent.Controls.Remove(controlBeingDragged);
dragDropTarget.Controls.Add(controlBeingDragged);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this