How do i use Form.ShowDialog?
Posted
by
Daniel Lip
on Stack Overflow
See other posts from Stack Overflow
or by Daniel Lip
Published on 2012-09-16T02:51:05Z
Indexed on
2012/09/16
3:38 UTC
Read the original article
Hit count: 140
c#
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();
}
When i click the button i see the new Form and the textBox1 in the new Form and i can type in the textBox1 something but i dont see anywhere an OK or CANCEL buttons. Should i add them manualy in the new Form designer ? And how to use them then ?
This is the code in my new Form what i wanted to do is to type something in the new Form textBox1 and pass the text in the textBox1 to 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
{
}
}
}
}
So where are the OK and CANCEL buttons of the Form.ShowDialog ?
© Stack Overflow or respective owner