---------------------------------------
public class EventClass
{
public Button Btn;
public Label Lbl;
public int Rownum;
public int Colnum;
public EventClass(Button btn, Label lbl ,int row,int col)
{
Btn = btn;
Rownum = row;
Colnum = col;
Lbl = lbl;
}
public void ClickEventMethod(object ss, RoutedEventArgs ee)
{
this.Lbl.Dispatcher.BeginInvoke((Action)(() => Lbl.Content = {"Click i = {this.Rownum} j = {this.Colnum}" ));
Console.WriteLine($"Click i = {this.Rownum} j = {this.Colnum}");
}
}
---------------------------------------
Here is main Code
-------------------------------------
public partial class MainWindow : Window
{
List
public MainWindow()
{
EvtList = new List
InitializeComponent();
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
Button btn = new Button();
btn.Width = 80;
btn.Height = 80;
Grid.SetColumn(btn, j);
Grid.SetRow(btn, i);
EventClass evc = new EventClass(btn, lbl, i, j);
EvtList.Add(evc);
btn.Click += evc.ClickEventMethod;
gridmain.Children.Add(btn);
}
}
}
}
-------------------------------------
Here is Xaml
-------------------------------------
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
-------------------------------------
댓글 없음:
댓글 쓰기