Mr.Noob Mr.Noob - 1 year ago 145
C# Question

How to create windows forms dialog with dynamic number of buttons?

I need to create a sort of a dialog box or something like a popup screen. I have this array of items and then I need to create a buttons for each of them on the dialogbox so that i could navigate with a button click.

Whats the best way to do it in C#? can someone guide me on this please

Answer Source

If you are using , then place FlowLayoutPanel on your form. Then add all controls to it at runtime.

foreach(var item in items)
   Button button = new Button();
   // setup button properties
   // subscribe to events

FlowLayoutPanel will arrange your controls automatically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download