Hello, the code below generate's automatic labels from an MSSQL database depending on the top ranked labels.
I would like to know how I can create Label click events so I can go onto the next form, also it somehow needs to have this code be executed when it happens:
LoggedUser.Statuses[0].StatusRank++;
An answer would be much appreciated.
// the number of labels
int count = top3.Count;
// dimensions of labels
Size labelsize = new Size(234, 30);
Font fontlable = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold);
// the location to start putting them
Point baseLocation = new Point(3, 155);
Point location;
for (int i = 0; i < count; i++)
{
// creating a new label
Label l = new Label();
// changing the text for the label
l.Text = top3[i].StatusText;
l.Size = labelsize;
l.Font = fontlable;
// calculating the location of the label using the base location and the current label number
location = new Point(
baseLocation.X,
baseLocation.Y + (labelsize.Height * i)
);
l.Location = location;
// add label to form
this.Controls.Add(l);
3 replies to this topic
#1
Posted 19 August 2010 - 09:32 AM
|
|
|
#2
Posted 19 August 2010 - 10:30 AM
Can anyone help please, I need this urgently!
#3
Posted 19 August 2010 - 12:46 PM
I've changed the Label to Button and added :
btn.Click += new EventHandler(btn_Click);
but I'm not sure what to do with this, or how to add to the StatusRank
btn.Click += new EventHandler(btn_Click);
but I'm not sure what to do with this, or how to add to the StatusRank
#4
Posted 21 August 2010 - 07:57 AM
Looks like you have your buttons (I am assuming that is what you decided to go with) and added a generic click handler to them somewhere in your loop (make sure its in the loop where you create the buttons so that all of the buttons are assigned to the click handler). Now you need to write the click handler method:
private void btn_Click(object sender, System.EventArgs e)
{
//Button tempButton = (Button)sender; this is how you can
//access your buttons seperatly all from one click handler event
//all the rest of the code you want to execute goes here
}
Then just put the other code you want to run in the click handler event. Use the sender object to access the properties of the button that was clicked.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









