coldzero
coldzero

Reputation: 25

How to hold state of label (color, location)

In Window Forms I have TabControl with 2 tabs. On second tab I add dynamically in for loop labels from xml file based on cords in xml file. When I click on whichever label shows up new Form with three buttons (Important, Total, Address). When I choose for example important label must change color on Orange (I can handle that). My problem is how to save state (color, location) of these label which was clicked. I need that, because state of these labels which was clicked go to database. I have no idea how to save or hold it this state.

Upvotes: 0

Views: 113

Answers (2)

coldzero
coldzero

Reputation: 25

Solved: In for loop I've add each one label to List, and in other Button I've check in foreach which label has color and location I needed.

Upvotes: 0

Waescher
Waescher

Reputation: 5747

You have to make your labes referrable in code. For example by giving them unique names once you create them from XML, like "lblNode141".

Next, if you say, they "go to database" you should have a place there where you can store that information. For example, you could create a table like this:

LabelName   | X | Y |  Color
-----------------------------
lblNode141  | 20| 30| #577ae4
lblNode142  | 20| 60| #ff8000
lblNode143  | 20| 90| #14bfb2

Now, the next time you create your labels from the same XML, you can retrieve the chosen values from the database. Just query over the name, given that it is unique. You may need to extend those names to get them really unique, I don't have enough information about that.

Note, this is ONE possible solution - depending on what you really want to achieve, this might not perfectly fit your needs.

Upvotes: 0

Related Questions