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

Search For Child Forms

بدأه EXP في 25 يونيو 2008 · 2 رد · 462 مشاهدة · في Microsoft Visual C#.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اعزرونى لو الموضوع مكرر انا عملت search و ملقتش حاجة

سؤالى : لو عندى Parent form و فيها Button & TextBox و ظيفة ال Button ياخد اللـ text الموجود فى ال TextBox و يعمل new Childform ويكون Childform.text = textbox.text

انا بقى عايز اعرف او كان فى Childform لها نفس الاسم ميعملش New Child form

#2
/*
	TestChildForm.CS
	Compile : CSC  /t:winexe /debug TestChildForm.CS
*/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SoftWin
{
	public class Program
	{
		static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.Run(new TestChildForm());
		}
	}

	public class TestChildForm : Form
	{
		TableLayoutPanel	tlpMain 		= new TableLayoutPanel();
		Panel 				panelTop 		= new Panel();
		Panel 				panelChildForm 	= new Panel();
		Button 				btnCreateForm 	= new Button();
		TextBox 			txtFromText 	= new TextBox();
		Label 				lblText 		= new Label();

		public TestChildForm()
		{
			// Initialize Component
			// 
			// tlpMain
			// 
			this.tlpMain.BackColor = SystemColors.Control;
			this.tlpMain.ColumnCount = 1;
			this.tlpMain.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
			this.tlpMain.Controls.Add(panelTop, 0, 0);
			this.tlpMain.Controls.Add(panelChildForm, 0, 1);
			this.tlpMain.Dock = DockStyle.Fill;
			this.tlpMain.Name = "tlpMain";
			this.tlpMain.RowCount = 2;
			this.tlpMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 45F));
			this.tlpMain.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
			this.tlpMain.Size = new Size(553, 433);
			// 
			// panelTop
			// 
			this.panelTop.BackColor = SystemColors.Control;
			this.panelTop.Controls.Add(this.lblText);
			this.panelTop.Controls.Add(this.txtFromText);
			this.panelTop.Controls.Add(this.btnCreateForm);
			this.panelTop.Dock = DockStyle.Fill;
			this.panelTop.Location = new Point(3, 3);
			this.panelTop.Name = "panelTop";
			this.panelTop.Size = new Size(547, 39);
			// 
			// panelChildForm
			// 
			this.panelChildForm.BackColor = SystemColors.ControlDarkDark;
			this.panelChildForm.Dock = DockStyle.Fill;
			this.panelChildForm.Location = new Point(3, 48);
			this.panelChildForm.Name = "panelChildForm";
			this.panelChildForm.Size = new Size(547, 382);
			// 
			// btnCreateForm
			// 
			this.btnCreateForm.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right)));
			this.btnCreateForm.Location = new Point(463, 12);
			this.btnCreateForm.Size = new Size(75, 23);
			this.btnCreateForm.Name = "btnCreateForm";
			this.btnCreateForm.Text = "Create Form";
			this.btnCreateForm.UseVisualStyleBackColor = true;
			this.btnCreateForm.Click += new EventHandler(btnCreateForm_Click);
			// 
			// txtFromText
			// 
			this.txtFromText.Anchor = ((AnchorStyles)(((AnchorStyles.Top | AnchorStyles.Left) | AnchorStyles.Right)));
			this.txtFromText.Location = new Point(73, 12);
			this.txtFromText.Name = "txtFromText";
			this.txtFromText.Size = new Size(384, 20);
			// 
			// lblText
			// 
			this.lblText.Location = new Point(3, 9);
			this.lblText.Name = "lblText";
			this.lblText.Size = new Size(64, 23);
			this.lblText.Text = "Form Text:";
			this.lblText.TextAlign = ContentAlignment.MiddleLeft;
			// 
			// TestChildForm
			// 
			this.ClientSize = new System.Drawing.Size(600, 500);
			this.Controls.Add(this.tlpMain);
			this.StartPosition = FormStartPosition.CenterScreen;
		}

		private void btnCreateForm_Click(object sender, EventArgs e)
		{
			string frmName = txtFromText.Text.Replace(" ", "_");
			Control ch =  panelChildForm.Controls[frmName];
			if(ch != null) {
				if(ch.Name.Equals(frmName))
					return;
			} else {
				Form childform = new Form();
				childform.TopLevel = false;
				childform.Name = frmName;
				childform.Text = txtFromText.Text;
				panelChildForm.Controls.Add(childform);
				childform.Show();
			}
		}
	}
}

مواضيع متنوعة

#3

شكرا اخى Moudey

الله يكرمك

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