Yes, what you describe is entirely possible if you're coding in C# or VB, but it requires a moderate understanding of windows form programming, and as the previous two posters have said, you'd probably be better off accomplishing this within InfoPath, without using dialogs.
Nonetheless, here's a simple example in C# to get you started. A real-life form would naturally be a bit more complex.:
Create an InfoPath form with one text box (bound to "my:myFields/my:field1") and a button.
In Tools->Form Options...->Programming, choose C# as the programming language.
Open VSTA. (Tools->Programming->Microsoft Visual Studio Tools for Applications)
Select "Add Windows Form..." from the Project menu. Select "Windows Form" from the dialog that pops up, leave the filename as Form1.cs, and click Add
A new blank windows form will be created. Now from the Toolbox (to the left), drag one TextBox and one Button onto your form. Notice that when you click the TextBox, the Properties window shows its name as textBox1.
Now double-click the button. This will open up the code view and position your cursor inside the Button's event handler. Add the following code to that event handler:
DialogResult =
DialogResult.OK;
Close();
This tells the form to close when the button is clicked.
One last thing you need to do is add a property to allow your InfoPath form code to access the TextBox's value. Beneath the closing brace of the Button's event handler, add the following code:
public string TextBoxValue
{
get
{
return textBox1.Text;
}
}So that that area of the code looks like:
private
void button1_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
public string TextBoxValue
{
get
{
return textBox1.Text;
}
}
If you did that all correctly, that's all that you need to do to the windows form. Save the file.
Now go back to your InfoPath form. Double-click its button, and click "Edit form code..."
Add this code to the button's event handler:
// this line creates an instance of the dialog
Form1 dialog = new Form1();
// this line opens up the dialog, and causes this code to wait until it is closed
dialog.ShowDialog();
// this line selects the /my:myFields/my:field1 node from your data source
XPathNavigator node = MainDataSource.CreateNavigator().SelectSingleNode("my:myFields/my:field1",NamespaceManager);
// this line assigns the contents of the dialog to field1
node.SetValue(dialog.TextBoxValue);
Now preview the form and try it out.