دلفي تعليم
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول

اذهب الى الأسفل

تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول Empty تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول

مُساهمة  ali 12/3/2016, 1:01 pm

بسم الله الرحمن الرحيم
الصلاة والسلام على رسول الله

تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول

يحتوي هذا المشروع أربع نماذج

طريقة اضافة نماذج الى مشروع
من القائمة Project اختر Add Class ...
تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول Vn2tfr

من Add Class حدد Windows Form
واكتب الاسم في المربع Name
تعدد النماذج في المشروع وطريقة استدعائها من النموذج الاول 51c4e0


نقرتين فوق button1 وكتابة هذا الكود
الكود:

 Form2^ frm = gcnew Form2;
 frm->ShowDialog();

نقرتين فوق button3 وكتابة هذا الكود
الكود:

 Form3^ frm03 = gcnew Form3;
 frm03->ShowDialog();

نقرتين فوق button4 وكتابة هذا الكود
الكود:

 Form4^ frm04 = gcnew Form4;
 frm04->ShowDialog();

نقرتين فوق button5 وكتابة هذا الكود
الكود:

// الشرط
 // اذا نم الضغط فوق موفق سيتم تغير لون النموذج حسب اللون المختار
 // من مربع الالوان
 if(colorDialog1->ShowDialog() == ::DialogResult::OK)
   Form1::BackColor = colorDialog1->Color;
   // والا سيتم اظهارهذه هذه الرسالة
  else MessageBox::Show("لم تختر أي لون من الالوان", "عنوان الرسالة");


نقرتين فوق button6 وكتابة هذا الكود
الكود:

 fontDialog1->ShowColor = true;
 fontDialog1->Font = Form1::Font;
 fontDialog1->Color = Form::ForeColor;
 // الشرط
 // اذا نم الضغط فوق موفق سيتم تغير
 //الخط المستعمل في النموذج حسب الحجم والون والنوع المختار
 // من مربع الخطوط
 if(fontDialog1->ShowDialog() == ::DialogResult::OK)
 {
  // تغيير الخط
  Form1::Font = fontDialog1->Font;
  // تغييير لون الخط
  Form1::ForeColor = fontDialog1->Color;
 }


نقرتين فوق button7 وكتابة هذا الكود
الكود:

 Form5^ frm05 = gcnew Form5;
 frm05->ShowDialog();

نقرتين فوق button2 وكتابة هذا الكود
الكود:

 Close();


كود سورس الملف الرئيسي لهو : Form1.h
الكود:

#pragma once

//  يتصمَّن هذه النماذج أو يشتمل على هذه النماذج
// لهي Form2 و Form3 وForm4
// أو تصريح كما هو جاري العادة في دلفي وباسكال
//
// ملاحظة هامة اذا لم يتم اضافتها تلقائيا
// اضفها يدويا

#include "Form2.h"
#include "Form3.h"
#include "Form4.h"


namespace Dialoge2 {

 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>
 /// Summary for Form1
 ///
 /// WARNING: If you change the name of this class, you will need to change the
 ///          'Resource File Name' property for the managed resource compiler tool
 ///          associated with all .resx files this class depends on.  Otherwise,
 ///          the designers will not be able to interact properly with localized
 ///          resources associated with this form.
 /// </summary>
 public ref class Form1 : public System::Windows::Forms::Form
 {
 public:
 Form1(void)
 {
 InitializeComponent();
 //
 //TODO: Add the constructor code here
 //
 }

 protected:
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 ~Form1()
 {
 if (components)
 {
 delete components;
 }
 }
 private: System::Windows::Forms::Button^  button1;
 protected:
 private: System::Windows::Forms::Button^  button2;
 private: System::Windows::Forms::Button^  button3;
 private: System::Windows::Forms::Button^  button4;
 private: System::Windows::Forms::ColorDialog^  colorDialog1;
 private: System::Windows::Forms::Button^  button5;
 private: System::Windows::Forms::FontDialog^  fontDialog1;
 private: System::Windows::Forms::Button^  button6;

 private:
 /// <summary>
 /// Required designer variable.
 /// </summary>
 System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 void InitializeComponent(void)
 {
 this->button1 = (gcnew System::Windows::Forms::Button());
 this->button2 = (gcnew System::Windows::Forms::Button());
 this->button3 = (gcnew System::Windows::Forms::Button());
 this->button4 = (gcnew System::Windows::Forms::Button());
 this->colorDialog1 = (gcnew System::Windows::Forms::ColorDialog());
 this->button5 = (gcnew System::Windows::Forms::Button());
 this->fontDialog1 = (gcnew System::Windows::Forms::FontDialog());
 this->button6 = (gcnew System::Windows::Forms::Button());
 this->SuspendLayout();
 //
 // button1
 // الزر الاول
 //
 this->button1->Location = System::Drawing::Point(202, 36);
 this->button1->Name = L"button1";
 this->button1->Size = System::Drawing::Size(174, 31);
 this->button1->TabIndex = 0;
 this->button1->Text = L"النموذج الثاني";
 this->button1->UseVisualStyleBackColor = true;
 this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
 //
 // button2
 // الزر الثاني
 //
 this->button2->Location = System::Drawing::Point(64, 161);
 this->button2->Name = L"button2";
 this->button2->Size = System::Drawing::Size(195, 42);
 this->button2->TabIndex = 1;
 this->button2->Text = L"إغــلاق";
 this->button2->UseVisualStyleBackColor = true;
 this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
 //
 // button3
 // الزر الثالث
 //
 this->button3->Location = System::Drawing::Point(64, 48);
 this->button3->Name = L"button3";
 this->button3->Size = System::Drawing::Size(88, 31);
 this->button3->TabIndex = 2;
 this->button3->Text = L"Show Form3";
 this->button3->UseVisualStyleBackColor = true;
 this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
 //
 // button4
 // الزر الرابع
 //
 this->button4->Location = System::Drawing::Point(399, 36);
 this->button4->Name = L"button4";
 this->button4->Size = System::Drawing::Size(121, 22);
 this->button4->TabIndex = 3;
 this->button4->Text = L"Form4";
 this->button4->UseVisualStyleBackColor = true;
 this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
 //
 // button5
 // الزر الخامس
 //
 this->button5->Location = System::Drawing::Point(335, 91);
 this->button5->Name = L"button5";
 this->button5->Size = System::Drawing::Size(121, 23);
 this->button5->TabIndex = 4;
 this->button5->Text = L"Color";
 this->button5->UseVisualStyleBackColor = true;
 this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
 //
 // button6
 // الزر السادس
 //
 this->button6->Location = System::Drawing::Point(333, 139);
 this->button6->Name = L"button6";
 this->button6->Size = System::Drawing::Size(123, 23);
 this->button6->TabIndex = 5;
 this->button6->Text = L"Font";
 this->button6->UseVisualStyleBackColor = true;
 this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
 //
 // Form1
 //
 this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
 this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
 this->ClientSize = System::Drawing::Size(532, 234);
 this->Controls->Add(this->button6);
 this->Controls->Add(this->button5);
 this->Controls->Add(this->button4);
 this->Controls->Add(this->button3);
 this->Controls->Add(this->button2);
 this->Controls->Add(this->button1);
 this->Name = L"Form1";
 this->Text = L"Form1";
 this->ResumeLayout(false);

 }

#pragma endregion

 // اظهار النموذج الثاني
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
 {
 Form2^ frm = gcnew Form2;
 frm->ShowDialog();
 }

 // اغلاق البرنامج
 private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)
 {
 Close();
 }

 // اظهار النموذج الثالث
 private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e)
 {
 Form3^ frm03 = gcnew Form3;
 frm03->ShowDialog();
 }

 // اظهار النموذج الرابع
 private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e)
 {
 Form4^ frm04 = gcnew Form4;
 frm04->ShowDialog();
 }


 // تغير لون النموذج
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e)
 {
 // الشرط
 // اذا نم الضغط فوق موفق سيتم تغير لون النموذج حسب اللون المختار
 // من مربع الالوان
 if(colorDialog1->ShowDialog() == ::DialogResult::OK)
     Form1::BackColor = colorDialog1->Color;
 // والا سيتم اظهارهذه هذه الرسالة
 else MessageBox::Show("لم تختر أي لون من الالوان", "عنوان الرسالة");
 }

 // تغيير الخط المستعمل في النموذج
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e)
 {
 fontDialog1->ShowColor = true;
 fontDialog1->Font = Form1::Font;
 fontDialog1->Color = Form::ForeColor;
 // الشرط
 // اذا نم الضغط فوق موفق سيتم تغير
 //الخط المستعمل في النموذج حسب الحجم والون والنوع المختار
 // من مربع الخطوط
 if(fontDialog1->ShowDialog() == ::DialogResult::OK)
 {
 // تغيير الخط
     Form1::Font = fontDialog1->Font;
 // تغييير لون الخط
 Form1::ForeColor = fontDialog1->Color;
 }

 }
};
}


ملاحظة هامة
يمكن استدعاء النماذج بطريقتين

1
form2^ fsrm =gcnew form2();
fsrm->Show();

2
Form ^ frm= gcnew Form();
frm->ShowDialog();


ملاحظة هامة
يمكن غلق النماذج بثلاث طرق

1
Close();

2
this->Close();

3
Form1::Close();

ali
مبرمج مجتهد

عدد المساهمات : 913
تاريخ التسجيل : 29/07/2013

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

- مواضيع مماثلة

 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى