Chandra Eskay
Chandra Eskay

Reputation: 2203

Need to define control flow and functionalities

I have a project with requirements as below,

  1. Login form opens up and asks for user name and password.
  2. Login Successful - Login form closes and another main form opens and all the functionalities will be added here.
  3. In the main form there is a Call button when clicked on it, it will pop a dial pad.
  4. When the number is entered on the dial pad and clicked "ok", control comes back to the same main form.
  5. When logout is clicked, It wil take me to the login screen again.

For this can anybody explain me the following points:

  1. How do I tranfer the control from one form to another?
  2. I have to make sure when user clicks on the close 'x' , I have to log out and close the windows?
  3. Neeed some rough class information.

Thanks in advance.

This is what i used earlier to carry data from one form to other

public partial class DialPad : Form { public MainGUI guiObject;

    public DialPad(MainGUI mG)
    {
        InitializeComponent();
        guiObject = mG;
    }  

Upvotes: 1

Views: 146

Answers (3)

MattDavey
MattDavey

Reputation: 9017

By the sounds of it your dialler form should be a dialog..

class MyDiallerDialog : Form
{
    public String DialledNumber
    {
        get { return this.txtNumber.Text; } // Or however the form stores its number...
    }
}

class MyMainForm : Form
{
    void btnCall_Click(object sender, EventArgs e)
    {
        using (var dialog = new MyDiallerDialog())
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                String number = dialog.DialledNumber;

                // do something interesting with the number...
            }
        }
    }
}

Upvotes: 3

Marshal
Marshal

Reputation: 6661

For your point no. 2

I have to make sure when user clicks on the close 'x' , I have to log out and close the windows?

In the event FormClosing of the form, take a look at e.ClosingReason.

So if user closes using Close Button (X), then ClosingReason would be UserClosing. So check that and then write appropriate code therein.

How do I tranfer the control from one form to another?

For e.g If you want to get the number in main form from Dialpad form.

1st in the contructor of main form

public static MainForm instance = null;
public string numberInMainForm = null;
public MainForm()
{

instance = this;
}

now in your dialpad form, when user enters the number, you can pass the number (or any other variable.) to main form from the dialpad form directly.

In dialpad form just write:

MainForm.instance.numberInMainForm = number;

thats it. You are done !!

Upvotes: 1

Sangram Nandkhile
Sangram Nandkhile

Reputation: 18202

let us assume you 1st form is loginform, Suppose User press OK on the login form, so on OK_click() event call another form. suppose your name of the another form is MainForm.cs then you can call using...

MainForm mf = new Mainform()

Suppose you want to close the login form when user press OK of your logIn form you can keep the order in following way..

 private void OK_Click(object sender, EventArgs e)
    {
       . . .
        // your validations
        //return bool  (true or false ) to confirm you have complted validations

        MainForm mf = new Mainform();
        mf.show();  //  or you can use  mf.ShowDialog();

        . . .

        . . .
        this.close();



    }

When you will close the MainForm,its control will come directly to the next line after mf.show();

To close any form use this.close() command.

I hope this will help you ands you can start working on your project now.

EDIT:

Add a new class file named commondata.cs and in that use static variables like

 public static string myString = "";

You can keep all the static functions and variables in the common file like commonData.cs so that you can modify its value from anywhere and can be used from anywhere.

Before closing your current form store the information in the static myString so even if u close the current form related information will be stored in myString & you can access it in any form using commonData.myString command.

string temp = commonData.myString;

Regards,

Sangram Nandkhile.

Upvotes: 1

Related Questions