Create PushButton at Runtime

I need to create some debug stuff in my code but I don’t want the debug controls or code to be included in the Final build and I do not want to have to comment it all out either.

I know you can create controls at runtime so how do I create a PushButton at runtime. I tried the following code in the Window.Open Event but the button does not appear:

#If DebugBuild Dim d As New PushButton d.Visible = True d.Top = 0 d.Left = 0 d.Width = 90 d.Height = 20 d.Caption = "Debug Menu" #EndIf

make a container control with a button and embed it at runtime.

How do I do that?

[quote=173801:@Charles Fasano]I need to create some debug stuff in my code but I don’t want the debug controls or code to be included in the Final build and I do not want to have to comment it all out either.

I know you can create controls at runtime so how do I create a PushButton at runtime. I tried the following code in the Window.Open Event but the button does not appear:

#If DebugBuild Dim d As New PushButton d.Visible = True d.Top = 0 d.Left = 0 d.Width = 90 d.Height = 20 d.Caption = "Debug Menu" #EndIf[/quote]

You need to first have one PushButton as a control set to be able to create new members that way.

Or to place one on a ContainerControl which you make a new instance with embedwithin.

in some code in window:

dim c as new MyContainerControl c.embedwithin(self, x, y, c.width, c.height)

x and y are there coordinates. Self is the current window.

There is no way to fulfill these requirements exactly. There will always be some residue left over in the built application, unless you remove the debug stuff manually.

Sure there is.
If there are NO references to a class (like a container control) in the compiled code the class will be stripped out.
So the embedding code Christian posted above needs to be wrapped in a #if DebugBuild / #endif.
Then when building a release there are (or should be) no actual references to the control & the container will be stripped and the code that existed in the #if debugbuild will not be compiled in as it won’t even exist.

Thanks, that’s good to know.

You do have to watch you dont do something like

if x IsA ClassIExpectToBeStrippedOut

as that will count as a reference and retain the class