Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#3.0
can a form reflect a value(like a function)?
how? Smile | :)
when calling in other form.
calling in frmAccount
frmPerson f1 = new frmPerson(); f1.ShowDialog();
Posted 6-Mar-12 1:59am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Why not use DialogResult if you want to return back the success or failure. In case you want to pass some data between forms them their is a very good article [here]explaining how it can be done.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Hi faezun, I think you should work on your general .net/OOP understanding. A constructor like you have given in your example NEVER returns a value!!!! (only the constructed object) So someproperty = new frmPerson(); never works (same in C++, Java...). Just expose properties and maybe initialize with parameterized constructor (like pashad showed you).
Maybe I can give you a similar (but full)example:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
    static class Program
        static void Main()
            string strSomeProperty = "Hello Form!";
            // create a form
            FormWithProperty form = new FormWithProperty(strSomeProperty);
            MessageBox.Show("Property was: " + form.SomeProperty);
        class FormWithProperty : Form
            TextBox m_textbox; 
            // don't forget to write a default constructor if you provide a parametrized one, and want the possibility to construct the form with a default value...
            public FormWithProperty() : this("DefaultString") { }
            public FormWithProperty(string strSomeProperty)
                SomeProperty = strSomeProperty;
            private void InitializeComponentDummy()
                m_textbox = new TextBox();
                m_textbox.Multiline = true;
                m_textbox.Dock = DockStyle.Fill;
            public string SomeProperty
                get { return m_textbox.Text; }
                set { m_textbox.Text = value; }
(copy to a new WindowsForms-Project and replace the file Program.cs content with my example code -> run)
faezun at 6-Mar-12 9:13am
thanks. :)
johannesnestler at 6-Mar-12 11:25am
I'm glad I was able to help - good luck with your project!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

int a = 10;
calling in frmAccount
frmPerson f1 = new frmPerson(a); 
FrmPersons Code: on this form create a parameterized constructor on this as shown below,
int _a =0;
public frmPerson(int a)
      _a = a;
Access _a where ever you wants.
Message if any problem..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 645
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,095
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web01 | 2.8.150327.1 | Last Updated 6 Mar 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100