Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- InitButtons();
- }
- private void InitButtons()
- {
- int lastX = textBox1.Location.X;
- Point points = textBox1.Location;
- int defaultX = textBox1.Left;
- int x = defaultX;
- int y = textBox1.Bottom + 10;
- for (int i = 1; i <= 12; i++)
- {
- // spawn an button
- Button button = SpawnButton(i.ToString(), $"button{i}");
- button.Location = new Point(x, y);
- Controls.Add(button);
- // if mod 4 go down couple pixels
- if (i % 4 == 0)
- {
- x = defaultX;
- y = button.Bottom + 10;
- }
- else
- {
- x = button.Right + 10;
- }
- }
- }
- public static Button SpawnButton(string text, string name)
- {
- return new Button
- {
- Name = name,
- Text = text
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement