Thread: Deleting labels

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    34

    Deleting labels

    Hello, so im facing problem with labels. Im writing word guessing game in windows forms. I have function to create labels and store them into array. But when word is guessed, i need to delete labels, which is my problem. I have no idea how to do it. Also my intelliSense stopped working.. Here is code:

    Code:
    void BuildLabels( int nLabels )       
     {
                array<String^>^ smartLabel = gcnew array<String^> {L"label1",L"label2",L"label3",L"label4", L"label5",L"label6",L"label7",L"label8",L"label9",L"label10"};
                labels = gcnew array<System::Windows::Forms::Label^>(10);
                int x = 400 / nLabels;
                for (int i = 0; i < nLabels ; i++)
                {
                    labels[i] = gcnew Label();
                    labels[i]->AutoSize = false;
                    labels[i]->Location = System::Drawing::Point( ( i*x ) + ( x / 3 ), 10);
                    labels[i]->Name = smartLabel[i];
                    labels[i]->Size = System::Drawing::Size(25, 35);
                    labels[i]->TabIndex = 0;
                    labels[i]->TextAlign = System::Drawing::ContentAlignment::BottomCenter;
    
    
                    labels[i]->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(192)), static_cast<System::Int32>(static_cast<System::Byte>(192)), 
                    static_cast<System::Int32>(static_cast<System::Byte>(0)));
    
    
                    labels[ i ]->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 25.5F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
                    static_cast<System::Byte>(186)));
                    labels[ i ]->Text = "_";
                                
                }
                Controls->AddRange(labels);
            }

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    That code is not C++. I assume it's managed C++ (a different beast entirely, despite the name), which not too many folks use, in which case you would be better off asking your question in a forum concerned with windows (Microsoft) development.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    I can't speak much for "Managed C++", but I do know that `gcnew' is "garbage collected new"--or whatever--so the runtime will handle deletion.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    34
    Well i know that garbage collector will collect it, but i need to delete it from screen.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    That would be called "hiding".

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    34
    Any hint how to do it? My intelliSense left me so its a bit hard now..

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    o_O

    That was a hint.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by Aeoskype View Post
    My intelliSense left me
    What version of visual studio are you using? I know that they removed intellisense for C++/CLI (Managed C++) projects for that version, and I don't know if they've brought it back in subsequent releases.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Registered User
    Join Date
    Apr 2013
    Posts
    34
    Visual studio 2008. It was working but after program crash stopped working. And figured it out, thanks.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    FYI Latest version is 2013. If you can, upgrade. Express edition is still free.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating Labels on a Form
    By ejohns85 in forum C# Programming
    Replies: 4
    Last Post: 01-03-2007, 03:37 PM
  2. Dynamic Labels again!!
    By SuperNewbie in forum C# Programming
    Replies: 3
    Last Post: 07-11-2002, 12:36 AM
  3. Dynamic labels??
    By SuperNewbie in forum C# Programming
    Replies: 2
    Last Post: 07-09-2002, 01:31 AM
  4. GOTO and Labels
    By moemen ahmed in forum C++ Programming
    Replies: 13
    Last Post: 07-01-2002, 06:41 PM
  5. Labels in C++?!!?
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2001, 04:27 AM