[Beginner Question] – Foreach variable create a button with text

I'm trying to create a Foreach loop that checks for each display on a system, and then creates a button for that display and assigns it text based on which display it is. I thought this would work, but it seems like I'm missing something simple:

private void Form1_Load(object sender, EventArgs e) { foreach (var screen in Screen.AllScreens) { Button btn = new Button(); Button.Text = screen.DeviceName; } } 

by Servatose via /r/csharp

Leave a Reply