Skip to main content
gamedev.net
🔒 Locked

[.net] Difference between adding a control via the IDE vs programatically?

Started by Nytegard 1 reply 600+ views
Original Post
Nytegard
Nytegard
OK, recently purchased DotNetMagic to help with some basic controls that weren't available in .NET, but having a problem. Trying to use their docking window ability, and it allows you to make almost any control dockable. If I add the control to the form via the IDE and make it dockable, everything works fine. However if I try to create it at runtime, things seem to become messed up. Simple pseudo code (as the real code is at work right now). MyControl mycontrol = new MyControl; mycontrol.TopLevel = false; mycontrol.Dock = Docking.Fill; MyForm.Controls.Add(mycontrol); mycontrol.Visible = true; Does adding to the IDE add anything that isn't put in the Initialization function that I don't know about?
ernow
ernow
Well, first of all: you could open the InitializeComponent function to look for yourself...

I created a form with a single button and then added code to add another button when the first was clicked:

Button mycontrol = new Button();
mycontrol.Dock = Dockstyle.Fill;
this.Controls.Add(mycontrol);
mycontrol.Visible = true;


I don't know what you mean by the toplevel property but this seems to work...

Cheers
VizOne
VizOne
There is definitely no magic going on behind the scenes when you use the Forms-designer. What you see (in InitializeComponent) is what you get.

So, like ernow says, check InitializeComponent to see how the designer does it.


Regards,
Andre

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.