andrepadez Posted April 26, 2008 at 10:37 PM Report Share #181581 Posted April 26, 2008 at 10:37 PM Boas, Tenho uma matriz de [8x8] pictureboxes, "SquareButtons". é criada no form principa, onload, com um for quadrático. Quero que todas elas funcionem como um botão, cujas acções sejam iguais, mas sejam controláveis uma a uma pelos índices da matriz. Inseri dentro dos for de criação das mesmas a linha squareButtons[rank, file].Click += new EventHandler(SquareButton_Click); queria de alguma forma enviar como argumentos a posição xy na matriz. Anyone??? Obrigado Link to comment Share on other sites More sharing options...
andrepadez Posted April 27, 2008 at 04:17 PM Author Report Share #181717 Posted April 27, 2008 at 04:17 PM Desde já peço desculpa por ter escolhido mal o thread, mas é o primeiro post que ponho neste forum. Obrigado Link to comment Share on other sites More sharing options...
Betovsky Posted April 28, 2008 at 12:46 PM Report Share #181879 Posted April 28, 2008 at 12:46 PM Bem, que eu saiba, não tens maneira de mandar um argumento para o handler. A maneira mais simples que vejo é usares a propriedade Tag. Na altura que crias a pictureBox nos fors metes (presumindo que a variável i e j são as coordenadas) novaPictureBox.Tag = String.Format("{0};{1}", i, j); Depois no handler, para obter as coordenadas, só tens que ir buscar o Tag. Control c = sender as Control; String[] coordenadas = c.Tag.Split(';'); int i = Int32.Parse(coordenadas[0]); int j = Int32.Parse(coordenadas[1]); "Give a man a fish and he will eat for a day; Teach a man to fish and he will eat for a lifetime. The moral? READ THE MANUAL !" Sign on a computer system consultant's desk Link to comment Share on other sites More sharing options...
skm Posted April 28, 2008 at 01:35 PM Report Share #181896 Posted April 28, 2008 at 01:35 PM Podes enviar a posição XY como argumentos para o EventHandler. Para isso basta criares uma classe a extender a classe EventArgs. // This example demonstrates the EventHandler<T> delegate. using System; using System.Collections.Generic; //--------------------------------------------------------- public class MyEventArgs : EventArgs { private string msg; public MyEventArgs( string messageData ) { msg = messageData; } public string Message { get { return msg; } set { msg = value; } } } //--------------------------------------------------------- public class HasEvent { // Declare an event of delegate type EventHandler of // MyEventArgs. public event EventHandler<MyEventArgs> SampleEvent; public void DemoEvent(string val) { // Copy to a temporary variable to be thread-safe. EventHandler<MyEventArgs> temp = SampleEvent; if (temp != null) temp(this, new MyEventArgs(val)); } } //--------------------------------------------------------- public class Sample { public static void Main() { HasEvent he = new HasEvent(); he.SampleEvent += new EventHandler<MyEventArgs>(SampleEventHandler); he.DemoEvent("Hey there, Bruce!"); he.DemoEvent("How are you today?"); he.DemoEvent("I'm pretty good."); he.DemoEvent("Thanks for asking!"); } private static void SampleEventHandler(object src, MyEventArgs mea) { Console.WriteLine(mea.Message); } } //--------------------------------------------------------- /* This example produces the following results: Hey there, Bruce! How are you today? I'm pretty good. Thanks for asking! */ http://msdn2.microsoft.com/en-us/library/db0etb8x.aspx para mais informações. "There are two kinds of programmers. Those who write something to get the work done and those who want to write good code."João BrandãoWebsite e blog: http://jamab.blogspot.com/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now