private void backgroundWorker1_Progress(object sender, ProgressChangedEventArgs e) { string title = (string)e.UserState; int i = e.ProgressPercentage-1; CustomButton button = new CustomButton(); button.Title = title; if (Properties.Settings.Default.Favorites.Contains(title + ";")) { button.SwitchOn(); } else { button.SwitchOff(); } button.Name = "custombutton" + i; button.OnUserControlButtonClicked += new EventHandler(seriesButton_Click); int Row = i / this.EL_PER_WIDTH; int Column = (i % this.EL_PER_WIDTH); if (this.EL_PER_WIDTH == 1) { Column = 0; } Console.WriteLine("ROW => " + Row + ", COLUMN => " + Column); int marginLeft = (this.ClientSize.Width - (this.EL_PER_WIDTH*250))/2; //Console.WriteLine("(" + this.ClientSize.Width + " - " + 100 + ") - (" + Column + " * " + 260 + ") = " + marginLeft); int posX = marginLeft + Column * 250; int posY = 80 + 63 * Row; button.Location = new Point(posX, posY); this.Controls.Add(button); }