الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

فتح فورم جديد وقفل الحالي ثم العكس

مغلق
بدأه musa في 12 سبتمبر 2004 · 2 رد · 707 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

لقد قمت بمراجعة الرابط:

/index.php?showtopic=35911

ولكن في تلك الحالة فإن الفورم الاصلية لن تغلق ولكنها تختفي عن الانظار.

وسؤالي عندما اقوم بفتح الفورم الجديدة واخفاء او غلق الحالية ثم قمت بقفل الفور الجديدة واريد العودة الى الفورم القديمة فما هو الحل؟

#2

In your second form procedure (Form2_Closing) show your

first form, that will show your form1 after form2 closes

btw, you can't close your main form and continue with your application

if u closed your main form your whole application will close as well, you

can just hide your Form1 and then show your form2, and when you want

to show form1 and close form2 do what I suggest above

تم تعديل هذه المشاركة بواسطة محمد عبد العليم في 12 سبتمبر 2004 في 15:40

رأس الحكمة الإيمان بالله

#3

هل يمكن التوضيح اكثر بوضع مثال بسيط؟

انا قمت بعمل برنامج ولكن بالاضافة الى مشكلة الاظهار والاخفاء ايضا واجهتني مشكلة ارسال المتغيرات من فورم الى الاخرى

اليكم اجزاء من المثال

form 1
______


	public class Form1 : System.Windows.Forms.Form
	{
  private System.Windows.Forms.TextBox uId;
  private System.Windows.Forms.TextBox uPass;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Button button2;
  private System.Windows.Forms.Button signIn;
  private string m_userId="";
  public string userId
  {
  	get
  	{
    return m_userId;
  	}
  	set
  	{
    m_userId=value;
  	}
  }
.
.
.
	static void Main() 
{
	Application.Run(new Form1());
}

	private void signIn_Click(object sender, System.EventArgs e)
	{
  bool isUserValid=false;
  
  SqlConnection cn = new SqlConnection("Data Source=IBB; Initial Catalog=testProcess; User ID=sa; Password=******");
  cn.Open();
  SqlCommand cmd=new SqlCommand("select uId, uName, uPass from users where uName='"+uId.Text+"' and uPass='"+uPass.Text+"'",cn);
  SqlDataReader dr=cmd.ExecuteReader();

  while(dr.Read())
  {
    userId=dr["uId"].ToString();
    isUserValid=true;
  }
  cn.Close();
  if(isUserValid)
  {
  	MessageBox.Show("Your login successed "+this.userId,"Success Logging",MessageBoxButtons.OK,MessageBoxIcon.Asterisk);
  	MainForm form2 = new MainForm();
  	form2.sMainForm=this;
  	form2.Show();
  	this.Hide();

  }
  else
  {
  	MessageBox.Show("Unvalid user name or password","Error Logging",MessageBoxButtons.OK,MessageBoxIcon.Error);
  	uPass.Text="";
  	uPass.Focus();
  }
	}


form 2
______

	public class MainForm : System.Windows.Forms.Form
	{
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private Form m_sMainForm = null;

  public Form sMainForm
  {
  	get
  	{
    return m_sMainForm;
  	}
  	set
  	{
    m_sMainForm=value;
  	}
  }

  public MainForm()
  {
  	//
  	// Required for Windows Form Designer support
  	//
  	InitializeComponent();

  	//
  	// TODO: Add any constructor code after InitializeComponent call
  	//

  }
.
.
.
  private void MainForm_Closed(object sender, System.EventArgs e)
  {
  	//myParent.Visible=true;
  	//myParent.Close();

  	this.sMainForm.Visible=true;
  	this.Dispose();

  }

  private void MainForm_Load(object sender, System.EventArgs e)
  {
  	this.Text += this.sMainForm.Text;
  	this.Text += this.sMainForm.userId;
  	//Form1 m=new Form1();
  	//this.Text=m.userId;
  }




	}

وطبعا كما سوف تلاحظ من الكود باني استخدمت خاصية بروبرتي(property) في الفورم رقم 2 وذلك لكي اظهر الفورم رقم 1.

المشكلة هي انه عند اخفاء الفورم رقم 1 واعطاء الفورم رقم 1 للبروبرتي في الفورم رقم 2 فإن الفورم رقم واحد تظل في الذاكرة + البروبرتي مما يجعل حجم البرنامج في الذاكرة يزيد , وكذلك عندما اقوم باستخدام الفورم رقم 2 لاظهار الفورم 1 واقفال فورم2 فإن الفورم رقم 2 سوف تكون الاساس للفورم رقم 1 في المرة الثانية وباستمرار العملية فإنها تصبح تراكمية مما يجعلها في كل مرة تزيد من حجم الذاكرة للبرنامج.

اما المشكلة الثانية في حالة برنامجي الموضح سابقا فهي انني لا استطيع تمرير متغير من الفورم الاولى الى الثانية سواءً بأستخدام (public) او باستخدام البروبرتي(property)

تم تعديل هذه المشاركة بواسطة musa في 15 سبتمبر 2004 في 00:46

هذا الموضوع مغلق.

مواضيع مشابهة