Results 1 to 15 of 15

Thread: Multiple Labels @ Run Time [Resolved]

  1. #1

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166

    Multiple Labels @ Run Time [Resolved]

    Can someone show me how you would have one label on your window at design time and then once your window is run you would have 10, one stacked up on the other. I am used to control arrays in VB6. Thanks.
    Last edited by jordan23; Dec 30th, 2003 at 07:33 AM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Check this demo .
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Thanks for your reply, but what do I open that file with? I opened it in VS.net and got garbage.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by jordan23
    Thanks for your reply, but what do I open that file with? I opened it in VS.net and got garbage.
    I've created it with VS.NET 2003 , if you don't have it then use the converter under my signature .

  5. #5

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    I downloaded the tool but could not get it to work. Could you just send it to me in a text file. Thanks.

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Sure . That tool is very important for VS.NET compatibilty issues . Make sure you how to use it properly
    Code:
    private void CreateLabels()
    		{
    			for (int i=0;i<10;i++)
    			{
    				Label lbl=new Label();
    				lbl.Location=new Point(80,20*i);
    				lbl.Size=new Size(120,20);
    				lbl.Text="LabelRuntime"+i.ToString();
    				lbl.Name="Label"+i.ToString();
    				lbl.BackColor=Color.FromArgb(230,130,30);
    				lbl.BorderStyle=BorderStyle.Fixed3D;
    				lbl.TextAlign=ContentAlignment.MiddleCenter;
    				lbl.ForeColor=Color.White;
    				this.Controls.Add(lbl);
    			}
    		}

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    jordan: maybe you had problems unraring? Do you have WinRAR?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Thanks Pirate, that worked perfectly. CornedBee, No I do not have that.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The file he uploaded is an archive similar to ZIP, but with better compression. WinRAR can unpack the file.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Ok, I understand that part of the code. Now, what if I want to know which one the user clicks on. How do I detect that? Sorry for all the simple questions. New to the C# syntax.

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by jordan23
    Ok, I understand that part of the code. Now, what if I want to know which one the user clicks on. How do I detect that? Sorry for all the simple questions. New to the C# syntax.
    Umm , by creating and event and attaching it one event handler . Let me see if I can figure it out .

  12. #12

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Well, I understand that part. My problem is where to you generate the event code for the labels? How do you detect which on was clicked? Thanks for all your help.

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by jordan23
    Well, I understand that part. My problem is where to you generate the event code for the labels? How do you detect which on was clicked? Thanks for all your help.
    You don't create any event but you have to create event handler . I believe you need only one handler , I'll show you how in minutes .

  14. #14
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Casting is the keyword here .
    Code:
    private void CreateLabels()
    		{
    			for (int i=0;i<10;i++)
    			{
    				Label lbl=new Label();
    				lbl.Location=new Point(80,20*i);
    				lbl.Size=new Size(120,20);
    				lbl.Text="LabelRuntime"+i.ToString();
    				lbl.Name="Label"+i.ToString();
    				lbl.BackColor=Color.FromArgb(230,130,30);
    				lbl.BorderStyle=BorderStyle.Fixed3D;
    				lbl.TextAlign=ContentAlignment.MiddleCenter;
    				lbl.ForeColor=Color.White;
    				this.Controls.Add(lbl);
    				
    				//Here subscribed with click events with 
    				//each label is created .
    				lbl.Click+=new EventHandler(lbl_Click);
    			}
    			
    		}
    
    
    
    //This is the handler that dectects which label
    		//was clicked
    		private void lbl_Click(object sender, EventArgs e)
    		{
    			Label l=(Label)sender;
    			MessageBox.Show(l.Name);
    			//Here you can various implementations 
    			//switch cases or handle them by name . 
    		}
    
    
    
    private void button1_Click(object sender, System.EventArgs e)
    		{
    			CreateLabels();
    		}

  15. #15

    Thread Starter
    Addicted Member jordan23's Avatar
    Join Date
    Dec 2002
    Posts
    166
    Thanks Pirate, that is exactly what I needed to know. I appreciate all your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width