Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Controls In Other Forms

Status
Not open for further replies.

wuxapian

Programmer
Jun 13, 2001
52
0
0
GB
Hi,

I am wondering if there is a standard way to update controls in other forms. I am running an aplication to open a form to allow the user to input data, this data then needs to be updated/inserted in a list view in another form that is open at the same time.

In the past I have done this by writing a class to register the form controls but I would like to know if there is a standard way of doing this? Is there a way of sending messages to open controls/forms?

Wux.
 
Sounds like a good time for design patterns.

Look at the Model View Controller pattern and the observer pattern for performing GUI updates. Each GUI item should be independent and not know about the others.

If you are doing a simple entry form though, you can simply expose the data as if it was a typical control on your form.


public class MyInputForm : System.Windows.Forms.Form
{
private TextBox txtLastName;
private Button btnOk;

public MyInputForm()
{
InitializeComponents();
}

public string LastName
{
get
{
return txtLastName.Text;
}
}

private void btnOk_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
}


So that would be your entry form which you can now use in your main form like this:

private void btnAddInfo_Click(object sender, EventArgs e)
{
MyInputForm frm = new MyInputForm();

if (frm.ShowDialog() == DialogResult.OK)
{
//if the user clicks the ok button on the input form then grab the last name from the inputform.
MessageBox.Show(frm.LastName);
}
}
 
JurkMonkey,

Thanks for the reply but that is not really what I meant. I wanted to know if there was basically a way of pumping out messages to controls throughout the application.

I have decided to stick with my original idea and write it myself.

Ta.
 
OK, you didn't mention that the controls are in another application that you don't control.

For that, yes, a Windows message, or using the CBT API (is it still around?) would be good.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top