Thread: Dynamic Labels again!!

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    173

    Dynamic Labels again!!

    hi:

    I've created one label array in one form like this:

    //first in the beginning of the code,
    private System.Windows.Forms.Label mylabel[];

    //then inside the button event

    this.mylabel = new System.Windows.Forms.Label[1];
    this.mylabel[0].Location = new System.Drawing.Point(200, 100);
    this.mylabel[0].Size = new System.Drawing.Size(50, 50);
    this.mylabel[0].TabIndex = 0;
    Controls.AddRange( new System.Windows.Forms.Control[] {this.mylabel[0]});

    no problem when compile it, but it got crashed when click the button, what is the problem?

    THankx
    Don't laugh at me,I am just a SuperNewbie.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    What line did it crash at ?

    If you have Visual Studio, the debugger should show you, if not, put a MessageBox before each line and see which one you get last.

    You might want to have a closer look at this line

    private System.Windows.Forms.Label mylabel[];

    Put the brackets after the type and before the name, unlike C++.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User Esss's Avatar
    Join Date
    Aug 2001
    Posts
    133
    > this.mylabel = new System.Windows.Forms.Label[1];

    ...does not create a single label. It creates an array of references to labels but does not initialise any of the elements.

    mylabel[0] = new System.Windows.Forms.Label();
    Ess
    Like a rat in a maze who says,
    "Watch me choose my own direction"
    Are you under the illusion
    The path is winding your way?
    - Rush

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    173
    it crashed always at the first either one of lines:

    this.mylabel[0].Location = new System.Drawing.Point(200, 100);
    this.mylabel[0].Size = new System.Drawing.Size(50, 50);
    this.mylabel[0].TabIndex = 0;


    don't know why
    Last edited by SuperNewbie; 07-11-2002 at 12:55 AM.
    Don't laugh at me,I am just a SuperNewbie.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing labels in a list?
    By arcaine01 in forum C# Programming
    Replies: 2
    Last Post: 05-10-2008, 11:10 PM
  2. dynamic array/vector help
    By Cpro in forum C++ Programming
    Replies: 8
    Last Post: 04-05-2008, 03:30 PM
  3. Identify dynamic IP address of network device
    By BobS0327 in forum Tech Board
    Replies: 2
    Last Post: 02-21-2006, 01:49 PM
  4. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM
  5. Dynamic labels??
    By SuperNewbie in forum C# Programming
    Replies: 2
    Last Post: 07-09-2002, 01:31 AM