pendragon Posted February 13, 2004 Posted February 13, 2004 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 Quote
I Schobert Posted February 13, 2004 Posted February 13, 2004 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? Quote IS
pendragon Posted February 13, 2004 Author Posted February 13, 2004 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. Quote
Heiko Posted February 13, 2004 Posted February 13, 2004 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. Quote .nerd
pendragon Posted February 14, 2004 Author Posted February 14, 2004 Thanks Heiko, that will do it Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.