![](/img/trans.png)
[英]how to pass input data from one form to another form C#, WinForms, wpf,
[英]How to transfer data from one form to another in winforms c#?
現在,我將所有控件都放在同一頁面上,並且已使用這些代碼進行插入。
private void submit_addbtn_Click(object sender, EventArgs e)
{
try
{
//personal data insert
Personal per = new Personal();
per.Name = nametxt.Text;
per.FatherName = f_nametxt.Text;
per.MotherName = m_nametxt.Text;
per.Gotra = gotra_txt.Text;
per.Panth = panthcb.Text;
per.FamilyHead = fhntext.Text;
per.Educationlvl = edulvlcb.Text;
per.Education = educb.Text;
per.Blood = bloodcb.Text;
per.Gender = genderlist.Text;
per.Marrital = MarritalStatus;
per.DateOfBirth = dobdtp.Text;
if (new InsertAction().Insertpersonal(per))
{
MessageBox.Show("Personal Insertion Happen ");
}
else
{
MessageBox.Show(" Personal Insertion does not Happen ");
}
// spouse data insert
Spouse sps = new Spouse();
sps.Spousename = s_nametxt.Text;
sps.Spouseeducationlvl = s_edulvlcb.Text;
sps.Spouseeducation = s_educb.Text;
sps.Spouseblood = s_bgcb.Text;
sps.Spousedob = s_dobdtp.Text;
if (new InsertAction().Insertspouse(sps))
{
MessageBox.Show(" Spouse Insertion Happen ");
}
else
{
MessageBox.Show(" Spouse Insertion does not Happen ");
}
// Resident data insert
Ressident resi = new Ressident();
resi.RessiHnumber = ressi_numtxt.Text;
resi.RessihCmplx = ressi_complextxt.Text;
resi.RessiStrt = ressi_streettxt.Text;
resi.RessiLandmrk = ressi_landtxt.Text;
resi.RessiArea = ressi_areatxt.Text;
resi.RessiCity = ressi_citytxt.Text;
resi.RessiPhone = Convert.ToInt64(ressi_phnotxt.Text);
resi.RessiMobile = Convert.ToInt64(mobi_notxt.Text);
if (new InsertAction().Insertressident(resi))
{
MessageBox.Show(" Ressident Insertion Happen ");
}
else
{
MessageBox.Show(" Ressident Insertion does not Happen ");
}
//occupation data insert
Occupation ocp = new Occupation();
ocp.Occuptype = occup_typetxt.Text;
ocp.Occupadd = office_addresstxt.Text;
ocp.Occupnature = occup_naturecb.Text;
ocp.Occupphone = Convert.ToInt64(office_phno1txt.Text);
ocp.Occupmobile = Convert.ToInt64(office_mobnotxt.Text);
if (new InsertAction().Insertoccupation(ocp))
{
MessageBox.Show(" Occupation Insertion Happen ");
}
else
{
MessageBox.Show(" Occupation Insertion does not Happen ");
}
}
請幫我。 謝謝。
要在兩種形式之間發送值,您可以
1->在第二種形式的構造函數中發送值。 您可以創建參數化的構造函數,並在將表單初始化為時發送值:
Form1 obj = new Form1(Object);
2->您可以在第二種形式中引用您的第一種形式。
在第二種形式中
public Form1 objForm1;
在第一種形式中
Form2 objForm2=new Form2();
Form2.objForm1=this;
然后您可以使用Form2的objForm1來引用Form1的文本框或任何控件。
編輯:
考慮您要將所有值從Form1
發送到Form2
在第二種形式中,您必須具有引用上一形式的Form1類型的變量。 第二種形式
public Form1 objForm1;
然后您需要將Form1
的當前實例發送給Form2
如下所示:
Form2 objForm2=new Form2();
Form2.objForm1=this;
即,您在Form2中創建的objForm1引用此Form1實例。
現在在Form2中,您可以將Form1的任何控件或變量用作,
Form1.TextBox1
或Form1.Variable
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.