Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi

 

In the project I am writing there are some data entry forms that can be called from different parts of the program.

 

One of these screens can be called in over 140 projects so I decided to try and create a componant class that inherits from System.Windows.Forms.Form.

 

What it does is to allow the user to change the processing date for the program, it has 2 buttons (Accept, Cancel) and a textbox on it.

 

I can get it to come up by doing the following

 

AskDate.Date askDate = new AskDate.Date(); 
askDate.ShowDialog();

 

What I don't seem to be able to get my head round is how to pass back the contents of the textbox when the user presses accept.

 

I have declared a ref variable in the construtor to pass in the variable that I want change but I don't know if I can do variableA = variableB as a ref copy in the class code.

 

So my question is Am I going about this the right way and If yes how do I pass back information to the calling program.

 

All Help/Advice is gratefully received :)

 

Thanks

Posted

You could try to pass the calling form into the constructor (that is one way besides many others).

 

Like when you call it, say

 

AskDate.Date askDate = new AskDate.Date(This);

 

[i am not good at C#, but in VB it's Me that you pass]

 

Now, in the sub new of the called form, populate a local variable in the class with the passed form.

 

When you are done, and you want to pass your data back, say someting like:

 

MyParentForm.Label1.Text = myPassValue

 

Whereby MyParentForm is the name of the local variable that you used to store the passed form.

 

Does it work?

IS
Posted

I Schobert

 

Thank you for your reply

 

Under C#, I beleve that when you add a variable in the constructor for a form you have to specify the form name for it to work, don't know of anyway around that so Unfortunately this will not work, unless someone tells me differently of couse, as I am not an expert In C# or OO programming.

Posted

Put the return values into properties.

 

When the user presses ok in the askdate form, hide it. So the caller is able to access the returned values in in the properties.

 

So the askdate form is not required to know anything about its caller.

.nerd

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...