Jump to content

Creating a Auto-Generated Label Creation

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Abakuz

Abakuz

    Newbie

  • Members
  • Pip
  • 8 posts
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);

#2
Abakuz

Abakuz

    Newbie

  • Members
  • Pip
  • 8 posts
Can anyone help please, I need this urgently!

#3
Abakuz

Abakuz

    Newbie

  • Members
  • Pip
  • 8 posts
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

#4
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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