views:

327

answers:

3

For a OSS project, I'm trying to add controls programmatically to a WinForms view.. and I want to make these editable and resizeable as in the Visual Studio Designer. I've been playing around with adding programmatically, using Controls.Add(label).. but I'm struggling to work out how to make the UI editable.

I'm assuming it would make use of DesignMode - but I can only find getters and not setters for these properties. Simply put - is there any way of enabling and disabling DesignMode in WinForms programmatically?

I'm yet to investigate WPF - perhaps that would be able to have editable controls?

Many thanks, sorry to be a pain right after christmas.. T

+1  A: 

As far as I know, the Designer functionality is implemented in Visual Studio, and is not part of the WinForms runtime libraries. The DesignMode property is read-only because it gives information about the execution context; this is not something that can be changed on the fly (as a side note: this property is not as easy to use as one would hope).

If you want to make the UI editable at runtime (i.e. changing the size/layout of controls), you would have to implement a lot of the behavior manually (e.g. OnMouseDown handlers, etc.). If you wanted to do things like drawing bounding boxes with grabbable corners, you might need to delve into custom drawing.

I'm not sure about WPF, as I have much less experience with it, but this question on SO has some information about making controls resizable at runtime.

tcovo
+2  A: 

Actually there is a way to make UI editable as in VS designer.You have to host the winforms designer on your form. this info might help: http://msdn.microsoft.com/en-us/magazine/cc163634.aspx

alexm
A: 

It is available in WinForm as explained by alexm. Unfortunately this is not true for the WPF designer. There you would have to implement your own designer.

Lars Truijens