C# stores Label controls in a two-dimensional array as follows:
Is it possible to generate a click event when I click this label and get the index of the clicked label (although the above code sets the drag drop event...)?
For example, if labels[1,1] are clicked, I would like to get an index called [1,1].
As far as the contents of the Sender are concerned, there is information set in the properties, but there is no index information.
If you have not already used the
Tag property, you may want to write index information to that property.
Any type of data derived from Object can be set and used by the user.
If you don't have the right one, why don't you add a string and convert it each time, or create your own local definition object?
Retrieves or configures an object that stores data about the Tag control.(From Control)
Gets or sets the object that stores data about the control.
Types derived from the Object class can be assigned to this property. If the Tag property is set in the Windows form designer, you can only assign text.
A common use of Tag properties is to store data closely associated with controls. For example, if you have a control that displays information about a customer, you can store DataSet containing the customer's order history in the Tag properties of that control for quick access to data.
Here is an example of a similar application.
C#:8 Try creating puzzles using the control array
The index as a one-dimensional array is stored in a tag as a string.
© 2023 OneMinuteCode. All rights reserved.