Witam,
nie mam pojęcia czemu nie podpina mi poprawnie metody pod zdarzenie Click.
Mój program tworzy formę z przyciskiem, który po kliknięciu powinien dodać nowy przycisk.
Drugi przycisk również powinien posiadać możliwość dodania następnego przycisku przez kliknięcie itd.
Main:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
static class Program
{
[STAThread]
static void Main()
{
ButtonEventForm skel = new ButtonEventForm();
Application.Run(skel);
}
}
}
Forma z przyciskiem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication2
{
public class ButtonEventForm : Form
{
public OtherButton MyButton = new OtherButton();
public ButtonEventForm()
{
Text = "BEForm";
MyButton = new OtherButton(0,0);
MyButton.Location = new Point(0, 0);
MyButton.Size = new Size(75, 25);
Controls.Add(MyButton);
}
}
}
Przycisk, metoda pod przycisk
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication2
{
public class OtherButton : Button
{
public Button MyButton = new Button();
public Pawn pawn_ = new Pawn();
public OtherButton()
{
pawn_.row = 0;
pawn_.col = 0;
Text
= "[" + pawn_.row.ToString() + ", " +
pawn_.col.ToString() + "]";
Click += OtherButtonClick;
}
public OtherButton(int _row, int _col)
{
pawn_.row = _row;
pawn_.col = _col;
Text
= "[" + pawn_.row.ToString() + ", " +
pawn_.col.ToString() + "]";
Click += OtherButtonClick;
}
public void OtherButtonClick(object who, EventArgs e)
{
OtherButton b = (OtherButton)who;
OtherButton ob = new OtherButton();
ob.Location = new Point(b.Location.X + b.Size.Width * 2, b.Location.Y + b.Size.Height * 2);
ob.pawn_.row = b.pawn_.row + 1;
ob.pawn_.col = b.pawn_.col + 1;
ob.Text = ob.Text
= "[" + ob.pawn_.row.ToString() + ", " +
ob.pawn_.col.ToString() + "]";
Controls.Add(ob);
}
}
}
Klasa zawierająca 2 inty, którą posiada przycisk
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication2
{
public class Pawn : IPawn
{
public int row { get; set; }
public int col { get; set; }
}
}
Z góry dziękuję.