private void renderItems() { for (int row = 0; row < this.values.Length; row++) { Point location = new Point(this.itemsStartX + row * this.itemsMargin, this.itemsStartY + 20); Size size = new Size(20, 20); string name = $"item{row}"; string text = $"{this.values[row]}"; TextBox item = ControlsHelper.CreateTextbox(size, location, name, text, HorizontalAlignment.Center, true); this.Controls.Add(item); } }
private void renderWeights() { for (int i = 0; i < this.weights.Length; i++) { Point location = new Point(this.itemsStartX + i * this.itemsMargin, this.itemsStartY + 20); Size size = new Size(20, 20); string name = $"weight{i}"; string text = $"{this.weights[i]}"; TextBox item = ControlsHelper.CreateTextbox(size, location, name, text, HorizontalAlignment.Center, true); this.Controls.Add(item); } }
private void setItemsButton_Click(object sender, EventArgs e) { int count = int.Parse(itemsInput.Text); if (count >= 0) { int previousCount = this.Items.Count; if (previousCount > 0) { for (int i = 0; i < previousCount; i++) { this.Controls.Remove(this.Items[i]); this.Controls.Remove(this.Weights[i]); } this.Weights.Clear(); this.Items.Clear(); } for (int i = 0; i < count; i++) { Size size = new Size(35, 20); string itemName = $"item{i}"; Point itemlocation = new Point(this.itemsStartX + i * this.itemsMargin, itemsStartY); TextBox item = ControlsHelper.CreateTextbox(size, itemlocation, itemName); string weightName = $"weight{i}"; Point weightlocation = new Point(this.itemsStartX + i * this.itemsMargin, itemsStartY + 30); TextBox weight = ControlsHelper.CreateTextbox(size, weightlocation, weightName); this.Controls.AddRange(new Control[] { weight, item }); this.Items.Add(item); this.Weights.Add(weight); } if (count > 0) { weightLabel.Show(); itemsLabel.Show(); this.startButton.Show(); } else { weightLabel.Hide(); itemsLabel.Hide(); this.startButton.Hide(); } } }
private void renderKnapsackTable() { this.renderItemLabels(); for (int row = 0; row < yBagDimension; row++) { for (int column = 0; column < xBagDimension; column++) { Point location = new Point(this.itemsStartX + column * this.itemsMargin, this.itemsStartY); Size size = new Size(20, 20); string name = $"tableItem{column}x{row}"; Console.WriteLine(name); string text = "0"; TextBox item = ControlsHelper.CreateTextbox(size, location, name, text, HorizontalAlignment.Center, true); this.Controls.Add(item); } this.itemsStartY += 45; } }