Как правильно работать с элементами графического интерфейса?

как правильно изменять свойства элементов GUI из текста основной программы? среда разработки - VS 2008.
  1. Оффлайн

    nucleon

    Посетители

    Сообщений: 1

    Подскажите пожалуйста как в Visual Studio 2008 правильно обращаться к элементам графического интерфейса, из текста основной программы?
    нужно ли при этом менять статус подэлементов с privat до public
    #pragma once


    namespace form {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;

        /// <summary>
        /// Сводка для Form1
        ///
        /// Внимание! При изменении имени этого класса необходимо также изменить
        ///          свойство имени файла ресурсов ("Resource File Name") для средства компиляции управляемого ресурса,
        ///          связанного со всеми файлами с расширением .resx, от которых зависит данный класс. В противном случае,
        ///          конструкторы не смогут правильно работать с локализованными
        ///          ресурсами, сопоставленными данной форме.
        /// </summary>





        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
            Form1(void)
            {
                InitializeComponent();
                //
                //TODO: добавьте код конструктора
                //
            }

        protected:
            /// <summary>
            /// Освободить все используемые ресурсы.
            /// </summary>
            ~Form1()
            {
                if (components)
                {
                    delete components;
                }
            }
        private : System::Windows::Forms::NumericUpDown^  numericUpDown1;


        private : System::Windows::Forms::TextBox^  textBox1;

        private:

        private: System::Windows::Forms::Label^  label1;
        private: System::Windows::Forms::Label^  label2;
        private: System::Windows::Forms::CheckBox^  checkBox1;

        protected:

        private:
            /// <summary>
            /// Требуется переменная конструктора.
            /// </summary>
            System::ComponentModel::Container ^components;



    #pragma region Windows Form Designer generated code
            /// <summary>
            /// Обязательный метод для поддержки конструктора - не изменяйте
            /// содержимое данного метода при помощи редактора кода.
            /// </summary>
            void InitializeComponent(void)
            {
                System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
                this->numericUpDown1 = (gcnew System::Windows::Forms::NumericUpDown());
                this->textBox1 = (gcnew System::Windows::Forms::TextBox());
                this->label1 = (gcnew System::Windows::Forms::Label());
                this->label2 = (gcnew System::Windows::Forms::Label());
                this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->BeginInit();
                this->SuspendLayout();
                //
                // numericUpDown1
                //
                this->numericUpDown1->Location = System::Drawing::Point(172, 2);
                this->numericUpDown1->Maximum = System::Decimal(gcnew cli::array< System::Int32 >(4) {50, 0, 0, 0});
                this->numericUpDown1->Minimum = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
                this->numericUpDown1->Name = L"numericUpDown1";
                this->numericUpDown1->Size = System::Drawing::Size(43, 20);
                this->numericUpDown1->TabIndex = 0;
                this->numericUpDown1->Value = System::Decimal(gcnew cli::array< System::Int32 >(4) {2, 0, 0, 0});
                this->numericUpDown1->ValueChanged += gcnew System::EventHandler(this, &Form1::numericUpDown1_ValueChanged);
                //
                // textBox1
                //
                this->textBox1->BackColor = System::Drawing::SystemColors::ControlText;
                this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                    static_cast<System::Byte>(204)));
                this->textBox1->ForeColor = System::Drawing::Color::Gold;
                this->textBox1->Location = System::Drawing::Point(484, 2);
                this->textBox1->Name = L"textBox1";
                this->textBox1->ReadOnly = true;
                this->textBox1->Size = System::Drawing::Size(62, 20);
                this->textBox1->TabIndex = 2;
                this->textBox1->Text = L"1";
                this->textBox1->WordWrap = false;
                this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
                //
                // label1
                //
                this->label1->AutoSize = true;
                this->label1->Location = System::Drawing::Point(311, 5);
                this->label1->Name = L"label1";
                this->label1->Size = System::Drawing::Size(167, 13);
                this->label1->TabIndex = 3;
                this->label1->Text = L"осталось очков распределения";
                this->label1->Click += gcnew System::EventHandler(this, &Form1::label1_Click);
                //
                // label2
                //
                this->label2->AutoSize = true;
                this->label2->Location = System::Drawing::Point(58, 5);
                this->label2->Name = L"label2";
                this->label2->Size = System::Drawing::Size(108, 13);
                this->label2->TabIndex = 4;
                this->label2->Text = L"Уровень Флагмана";
                this->label2->Click += gcnew System::EventHandler(this, &Form1::label2_Click);
                //
                // checkBox1
                //
                this->checkBox1->AutoCheck = false;
                this->checkBox1->AutoSize = true;
                this->checkBox1->ForeColor = System::Drawing::SystemColors::ControlText;
                this->checkBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"checkBox1.Image")));
                this->checkBox1->Location = System::Drawing::Point(46, 42);
                this->checkBox1->Name = L"checkBox1";
                this->checkBox1->Size = System::Drawing::Size(65, 50);
                this->checkBox1->TabIndex = 5;
                this->checkBox1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
                this->checkBox1->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageBeforeText;
                this->checkBox1->UseVisualStyleBackColor = true;
                //
                // Form1
                //
                this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(592, 579);
                this->Controls->Add(this->checkBox1);
                this->Controls->Add(this->label2);
                this->Controls->Add(this->label1);
                this->Controls->Add(this->textBox1);
                this->Controls->Add(this->numericUpDown1);
                this->Name = L"Form1";
                this->Text = L"Form1";
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->numericUpDown1))->EndInit();
                this->ResumeLayout(false);
                this->PerformLayout();

            }
    #pragma endregion




        private: System::Void numericUpDown1_ValueChanged(System::Object^  sender, System::EventArgs^  e)
                 {
                 int LevelX = Convert::ToInt32 (numericUpDown1->Value);
                                         int ochki = LevelX - 1;
                                                     (textBox1->Text) = Convert::ToString(ochki);
                                                     if (ochki <= 0) {checkBox1->CheckState = System::Windows::Forms::CheckState::Indeterminate; }  

                                                     else {checkBox1->CheckState = System::Windows::Forms::CheckState::Unchecked;};
    //нужно вынести эти формулы отсюда ... из попрограммы в тело программы...

                 }
    private: System::Void label1_Click(System::Object^  sender, System::EventArgs^  e)
                 {

                 }
    private: System::Void label2_Click(System::Object^  sender, System::EventArgs^  e)
             {

             }
    private: System::Void textBox1_TextChanged(System::Object^  sender, System::EventArgs^  e)
            
             {
                
                         }

    private: System::Void checkBox1_CheckedChanged(System::Object^  sender, System::EventArgs^  e)
            
             {
                

             }
    };
    }

    11 Января 2012 - 19:41 / #1
  2. Оффлайн

    aaa_91_08

    Посетители

    Сообщений: 2

    скажите в чём ошибка???

    #include <iostream>

    int main(){

    using namespace std;

    int carrots;
    carrots  25;
    cout << "i have ";
    cout << carrots;
    cout<< "carrots";
    cout << endl;
    carrots carrots - 1;
    cout <<"crunch, crunch. Now i have "carrots<< " carrots." << endl;
    return 0;

    }
    Сообщение отредактировал admin 18.01.2012 в 14:23
    18 Января 2012 - 00:20 / #2
  3. Оффлайн

    Yur4ik

    Посетители

    Сообщений: 2

    aaa_91_08,

    #include <iostream>

    int main(){

    using namespace std;

    int carrots;

    carrots = 25;

    cout << "i have ";
    cout << carrots;
    cout << "carrots";
    cout << endl;

    carrots = carrots - 1;

    cout <<"crunch, crunch. Now i have carrots"<< carrots << endl;
    return 0;

    }



    Попробуй так
    Сообщение отредактировал admin 18.01.2012 в 14:23
    18 Января 2012 - 00:40 / #3
  4. Оффлайн

    admin

    Администраторы

    Сообщений: 7

    Симпатий: 2

    aaa_91_08, Для правильного отображения кода используйте [ code ] [ /code ]
    18 Января 2012 - 00:43 / #4
  5. Оффлайн

    Yur4ik

    Посетители

    Сообщений: 2

    admin,

    там просто щас тэги видны стали
     [u] .... [/u] 
    и прочие, это же может ввести в заблуждение новичков. Как быть?
    Сообщение отредактировал Yur4ik 18.01.2012 в 01:06
    18 Января 2012 - 01:05 / #5
  6. Оффлайн

    admin

    Администраторы

    Сообщений: 7

    Симпатий: 2

    Yur4ik, обновили движок недавно, сейчас устраним все неполадки, добавим code в bb коды
    Yur4ik нравится это сообщение.
    18 Января 2012 - 01:13 / #6
  7. Оффлайн

    aaa_91_08

    Посетители

    Сообщений: 2

    нашёл свою ошибку... я тупая голова директиву препроцессора не правильно написал... ошибсяя в букве и всё труба=)))
    unclude написал а надо ====>>> include
    18 Января 2012 - 06:08 / #7

Пользователи которые читают эту тему

Сейчас онлайн:1
(пользователей:0, гостей: 1)