• C - Bir shakldan boshqa shaklga qiymatlarni yuborish
  • Mirzo Ulug‘bek nomidagi O‘zbekiston Milliy universiteti Amaliy matematika va intellektual texnologiyalar




    Download 301,58 Kb.
    bet4/5
    Sana19.01.2024
    Hajmi301,58 Kb.
    #141271
    1   2   3   4   5
    Bog'liq
    Saidova Jasmina Umrzoq qizi

    MyBaby->MdiParent = bu;
    MyBaby->Show();
    }

    };
    }



  • Ilovani bajaring



  • Uni yoping va MSVC ga qayting


  • Misol
    // nis.cpp : main project file.


    #include "stdafx.h"
    #include "Form1.h"


    using namespace nis;


    [STAThreadAttribute]
    int main(array ^args)
    {
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);


    // Create the main window and run it
    Application::Run(gcnew Form1());
    return 0;
    }
    Menda ikkita shakl bor. Bu "Form1.h":
    #ifndef FORM1_H
    #define FORM1_H
    #pragma once
    #include "Form2.h"
    namespace nis {


    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 for Form1
    ///

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }


    protected:
    ///
    /// Clean up any resources being used.
    ///

    ~Form1()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Button^ button1;
    protected:


    private:
    ///
    /// Required designer variable.
    ///

    System::ComponentModel::Container ^components;


    #pragma region Windows Form Designer generated code
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    void InitializeComponent(void)
    {
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->SuspendLayout();
    //
    // button1
    //
    this->button1->Location = System::Drawing::Point(78, 77);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(144, 53);
    this->button1->TabIndex = 0;
    this->button1->Text = L"button1";
    this->button1->UseVisualStyleBackColor = true;
    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    //
    // Form1
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(282, 253);
    this->Controls->Add(this->button1);
    this->Name = L"Form1";
    this->Text = L"Form1";
    this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    this->ResumeLayout(false);


    }
    #pragma endregion
    private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
    }
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    this->Hide();
    Form2^ f1 = gcnew Form2();
    f1->ShowDialog();
    }
    };
    }


    #endif
    Va bu "Form2.h":
    #ifndef FORM2_H
    #define FORM2_H
    #pragma once
    #include "Form1.h"
    namespace nis {


    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 for Form2
    ///

    public ref class Form2 : public System::Windows::Forms::Form
    {
    public:
    Form2(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }


    protected:
    ///
    /// Clean up any resources being used.
    ///

    ~Form2()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Button^ button1;
    protected:


    private:
    ///
    /// Required designer variable.
    ///

    System::ComponentModel::Container ^components;


    #pragma region Windows Form Designer generated code
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    void InitializeComponent(void)
    {
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->SuspendLayout();
    //
    // button1
    //
    this->button1->Location = System::Drawing::Point(44, 102);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(149, 53);
    this->button1->TabIndex = 0;
    this->button1->Text = L"button1";
    this->button1->UseVisualStyleBackColor = true;
    //
    // Form2
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(282, 253);
    this->Controls->Add(this->button1);
    this->Name = L"Form2";
    this->Text = L"Form2";
    this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
    this->ResumeLayout(false);


    }
    #pragma endregion
    private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
    }
    };
    }
    #endif
    Iltimos, menga qo'riqchilar bilan nima bo'lganini ayta olasizmi? Men bu xatolarni olaman:
    Error 1 error C2065: 'Form2' : undeclared identifier
    d:\users\lior\documents\visual studio 2010\projects\nis\nis\Form1.h 85
    Error 2 error C2065: 'f1' : undeclared identifier
    d:\users\lior\documents\visual studio 2010\projects\nis\nis\Form1.h 85
    Error 3 error C2061: syntax error : identifier 'Form2'
    d:\users\lior\documents\visual studio 2010\projects\nis\nis\Form1.h 85
    Error 4 error C2065: 'f1' : undeclared identifier
    d:\users\lior\documents\visual studio 2010\projects\nis\nis\Form1.h 86
    Error 5 error C2227: left of '->ShowDialog' must point to
    class/struct/union/generic type d:\users\lior\documents\visual studio
    2010\projects\nis\nis\Form1.h 86

    Xulosa


    Men C++ da Windows formasi bilan ishlash uchun Visual studio 2012 dasturidan foydalanaman. Men bir nechta shaklga ega bo'lishni xohlayman. Men Form2ni loyihalashtirdim va Form2.h ni Form1.h ichiga kiritdim. Lekin form2 ni ochganimda, u paydo bo'ladi va darhol o'chadi.
    Bu mening kodim:
    #include "Form2.h"
    ...
    private: System::void button_Click(System::Object^ sender, System::EventArgs^ e){
    Form2 frm2;
    frm2.Show();
    //this->Hide();
    //this->Close();
    }
    foydalansam
    this->Hide();
    ikki shakl yashirinadi va agar men forma1ni yopsam
    this->Close();
    form2 ham yopiladi.
    Shakllarni mustaqil ravishda ochish va yopishni xohlayman. Nima qilishim kerak?
    Har qanday yordam minnatdor bo'ladi
    Agar siz Visual Studio bilan ishlasangiz, barqaror sozlamalarni olish juda oson. Solution Explorer-da loyihani o'ng tugmasini bosing va Xususiyatlar-ni tanlang. Sozlamalar yorlig'ini tanlang va sozlamalar mavjud bo'lmasa, giperhavolani bosing.
    Ilova sozlamalarini yaratish uchun Sozlamalar yorlig'idan foydalaning. Visual Studio Settings.settings va Settings.Designer.settings fayllarni yaratadi, unda ApplicationSettingsBase-dan meros bo‘lib qolgan singleton sinfi Settings mavjud. . Ilova sozlamalarini oʻqish/yozish uchun kodingizdan ushbu sinfga kirishingiz mumkin:
    Properties.Settings.Default["SomeProperty"] = "Some Value";
    Properties.Settings.Default.Save(); // Saves settings in application configuration file
    Ushbu uslub konsol, Windows Forms va boshqa loyiha turlari uchun ham qo'llaniladi.
    Sozlamalaringizning ko‘lami xususiyatini o‘rnatishingiz kerakligini unutmang. Agar siz Ilova doirasini tanlasangiz, u holda Settings.Default. faqat oʻqish uchun boʻladi.
    Ma'lumotnoma: Qanday qilib: C# bilan ish vaqtida foydalanuvchi sozlamalarini yozish - Microsoft Docs
    C# - Bir shakldan boshqa shaklga qiymatlarni yuborish

    Buning bir nechta echimlari bor, lekin men foydalanadigan naqsh bu.
    // Form 1
    // inside the button click event
    using(Form2 form2 = new Form2())
    {
    if(form2.ShowDialog() == DialogResult.OK)
    {
    someControlOnForm1.Text = form2.TheValue;
    }
    }
    Va...
    // Inside Form2
    // Create a public property to serve the value
    public string TheValue
    {
    get { return someTextBoxOnForm2.Text; }
    }

    Download 301,58 Kb.
    1   2   3   4   5




    Download 301,58 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Mirzo Ulug‘bek nomidagi O‘zbekiston Milliy universiteti Amaliy matematika va intellektual texnologiyalar

    Download 301,58 Kb.