private void button2_Click(object sender, EventArgs e)
{
ChangeLink cl = new ChangeLink();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (cl.ShowDialog() == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
// cl.AcceptButton.DialogResult = DialogResult.OK;
this.label4.Text = cl.textBox1Text;
}
else
{
this.label4.Text = "Cancelled";
}
cl.Dispose();
}
Khi tôi nhấp vào nút, tôi thấy Biểu mẫu mới và textBox1 trong Biểu mẫu mới và tôi có thể nhập nội dung textBox1 nhưng tôi không thấy bất kỳ nơi nào có nút OK hoặc CANCEL. Tôi có nên thêm chúng manualy trong thiết kế mẫu mới? Và làm thế nào để sử dụng chúng sau đó?Tôi làm cách nào để sử dụng Form.ShowDialog?
Đây là mã trong Biểu mẫu mới của tôi những gì tôi muốn làm là nhập nội dung nào đó vào hộp văn bản Form mới1 và chuyển văn bản trong textBox1 đến Form1 label4.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GatherLinks
{
public partial class ChangeLink : Form
{
public ChangeLink()
{
InitializeComponent();
}
public string textBox1Text
{
get
{
return textBox1Text = textBox1.Text;
}
set
{
}
}
}
}
Vì vậy, các nút OK và CANCEL của Form.ShowDialog là gì?