14 Replies - 783 Views - Last Post: 06 May 2009 - 10:26 PM Rate Topic: -----

#1 ADK_007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-April 09

I have two problems please help me.....

Post icon  Posted 29 April 2009 - 12:29 AM

Please someone help me.......

I am a 1st year student of System developing and I have to design a system as my final project.


I am designing a inventory control system for that.
I have two main QUESTIONS....

1) When i run my program 1st screen is ""LOG IN""
And after typing the UN and PW it will redirect to the ""MAIN MENU""
the problem is when i close the program with using the CLOSE button in the main menu the whole program is not closing.

I used ""this.hide"" in the LOG IN form. i think that is the case... I need to use the DISPOSE method but i cannot find it. I follow some tips but they will not helped me...


2) In my program i need to disable my MAIN MENU when the user is working in a sub form..
For a ex: in Ms WORD when we click FILE--> OPEN
""OPEN DIALOG BOX"" will open and the background is disable. if we try to click somewhere else the active window(OPEN DIALOG BOX) blink and informed.

i need to do the same thing.......


I HOPE YOU GUYS CAN UNDERSTAND WHAT I SAY.. Please help me...

Is This A Good Question/Topic? 0
  • +

Replies To: I have two problems please help me.....

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: I have two problems please help me.....

Posted 29 April 2009 - 12:58 AM

past you code here

in code /code

then we can help you
Was This Post Helpful? 0
  • +
  • -

#3 papuccino1  Icon User is offline

  • His name was Robert Paulson.
  • member icon

Reputation: 63
  • View blog
  • Posts: 1,121
  • Joined: 02-March 08

Re: I have two problems please help me.....

Posted 29 April 2009 - 05:33 AM

Regarding your first problem. Program the MainMenu to use Application.Exit() when the user clicks the red X button.
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: I have two problems please help me.....

Posted 29 April 2009 - 05:59 AM

Quote

Regarding your first problem. Program the MainMenu to use Application.Exit() when the user clicks the red X button.


you are rite! :^:
but he want to hide the login form not all application. :pirate:
Was This Post Helpful? 0
  • +
  • -

#5 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: I have two problems please help me.....

Posted 29 April 2009 - 07:20 AM

View PostADK_007, on 28 Apr, 2009 - 11:29 PM, said:

Please someone help me.......

I am a 1st year student of System developing and I have to design a system as my final project.


I am designing a inventory control system for that.
I have two main QUESTIONS....

1) When i run my program 1st screen is ""LOG IN""
And after typing the UN and PW it will redirect to the ""MAIN MENU""
the problem is when i close the program with using the CLOSE button in the main menu the whole program is not closing.

I used ""this.hide"" in the LOG IN form. i think that is the case... I need to use the DISPOSE method but i cannot find it. I follow some tips but they will not helped me...


2) In my program i need to disable my MAIN MENU when the user is working in a sub form..
For a ex: in Ms WORD when we click FILE--> OPEN
""OPEN DIALOG BOX"" will open and the background is disable. if we try to click somewhere else the active window(OPEN DIALOG BOX) blink and informed.

i need to do the same thing.......


I HOPE YOU GUYS CAN UNDERSTAND WHAT I SAY.. Please help me...


The second one is an easy fix. Use this

formName.ShowDialog();



This makes a modal dialog that you have to close before returning back to the sending form.

*edit*
I made a typo. :)

This post has been edited by SixOfEleven: 29 April 2009 - 07:22 AM

Was This Post Helpful? 1
  • +
  • -

#6 InternalStatic  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 11
  • Joined: 28-April 09

Re: I have two problems please help me.....

Posted 29 April 2009 - 07:30 AM

View PostADK_007, on 28 Apr, 2009 - 11:29 PM, said:

Please someone help me.......

I am a 1st year student of System developing and I have to design a system as my final project.


I am designing a inventory control system for that.
I have two main QUESTIONS....

1) When i run my program 1st screen is ""LOG IN""
And after typing the UN and PW it will redirect to the ""MAIN MENU""
the problem is when i close the program with using the CLOSE button in the main menu the whole program is not closing.

I used ""this.hide"" in the LOG IN form. i think that is the case... I need to use the DISPOSE method but i cannot find it. I follow some tips but they will not helped me...


2) In my program i need to disable my MAIN MENU when the user is working in a sub form..
For a ex: in Ms WORD when we click FILE--> OPEN
""OPEN DIALOG BOX"" will open and the background is disable. if we try to click somewhere else the active window(OPEN DIALOG BOX) blink and informed.

i need to do the same thing.......


I HOPE YOU GUYS CAN UNDERSTAND WHAT I SAY.. Please help me...


Q1: Invoking System.Windows.Forms.Application.Exit() will work most of the time, but I've found it has some subtle issues (I haven't looked into the source of the problem quite yet). Instead, I would recommend calling System.Diagnostics.Process.GetCurrentProcess().Kill(). This ensures that the entire program is ended, including all application domains (though I'm sure you have only one, anyway).

You can't "find" the Dispose() method? What's that supposed to mean? Just call nameOfForm.Dispose(). IntelliSense isn't everything (though I'm not sure why it wouldn't show you that method...)

Q2: The guy above me basically sums it up with invoking the ShowDialog() method. You may have to pass the handle of the main form to the ShowDialog's arguments (can't remember the overloads); if so, just call the Handle property. ShowDialog creates what we call a "modal" dialog window. For example, invoking the System.Windows.Forms.MessageBox.Show() method creates a modal dialog box "attached" to the current window. It will basically prevent access to the attached window(s), giving you the blinking effect and such that you seek.
Was This Post Helpful? 1
  • +
  • -

#7 ADK_007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-April 09

Re: I have two problems please help me.....

Posted 29 April 2009 - 07:47 PM

Thank you ""SixOfEleven""
Thank you ""InternalStatic""
Thank you guys....... i got the answer to my problem #2.



But the #1 ????

""noorahmad"" ""papuccino1"" How can i write codes to the "red X button"??
Was This Post Helpful? 0
  • +
  • -

#8 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: I have two problems please help me.....

Posted 29 April 2009 - 09:14 PM

I have a solution to your first problem but it is a little complex.

1 - go into Form1 and declare a bool variable loginSuccessful:

public bool loginSuccessful = false;


2 - go into the Program.cs file. Where it says Application.Run(new Form1()) change Form1 to Form2

3 - go into the code for Form2 and go to the constructor and add this code

		public Form2()
		{
			InitializeComponent();
			this.Hide();
			Form1 form = new Form1();
			form.ShowDialog();
			if (!form.loginSuccessful)
				Application.Exit();
		}



4 - go into the code for Form1

5 - where in your form where the login is entered successfully add this code at the end

   loginSuccessful = true;
   this.Close();



6 - if the login is unsuccessful add this code

	loginSuccesssful = false;
	this.Close();



What this will do is start with Form2 instead of Form1. It will call Form1 in modal mode which means Form2 will not receive focus until Form1 has finished. If the user closes Form1 or doesn't login successfully Form2 will close and not allow the user into the program. Hope this helps you. :)
Was This Post Helpful? 1
  • +
  • -

#9 ADK_007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-April 09

Re: I have two problems please help me.....

Posted 30 April 2009 - 04:28 AM

View PostSixOfEleven, on 29 Apr, 2009 - 08:14 PM, said:

I have a solution to your first problem but it is a little complex.

1 - go into Form1 and declare a bool variable loginSuccessful:

public bool loginSuccessful = false;


2 - go into the Program.cs file. Where it says Application.Run(new Form1()) change Form1 to Form2

3 - go into the code for Form2 and go to the constructor and add this code

		public Form2()
		{
			InitializeComponent();
			this.Hide();
			Form1 form = new Form1();
			form.ShowDialog();
			if (!form.loginSuccessful)
				Application.Exit();
		}



4 - go into the code for Form1

5 - where in your form where the login is entered successfully add this code at the end

   loginSuccessful = true;
   this.Close();



6 - if the login is unsuccessful add this code

	loginSuccesssful = false;
	this.Close();



What this will do is start with Form2 instead of Form1. It will call Form1 in modal mode which means Form2 will not receive focus until Form1 has finished. If the user closes Form1 or doesn't login successfully Form2 will close and not allow the user into the program. Hope this helps you. :)



yap looks good..... i will try this and tell you the results... BTW thank you for your time...
Was This Post Helpful? 0
  • +
  • -

#10 ashishshevale  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 92
  • Joined: 14-April 09

Re: I have two problems please help me.....

Posted 30 April 2009 - 05:17 AM

View PostADK_007, on 28 Apr, 2009 - 11:29 PM, said:

Please someone help me.......

I am a 1st year student of System developing and I have to design a system as my final project.


I am designing a inventory control system for that.
I have two main QUESTIONS....

1) When i run my program 1st screen is ""LOG IN""
And after typing the UN and PW it will redirect to the ""MAIN MENU""
the problem is when i close the program with using the CLOSE button in the main menu the whole program is not closing.

I used ""this.hide"" in the LOG IN form. i think that is the case... I need to use the DISPOSE method but i cannot find it. I follow some tips but they will not helped me...


2) In my program i need to disable my MAIN MENU when the user is working in a sub form..
For a ex: in Ms WORD when we click FILE--> OPEN
""OPEN DIALOG BOX"" will open and the background is disable. if we try to click somewhere else the active window(OPEN DIALOG BOX) blink and informed.

i need to do the same thing.......


I HOPE YOU GUYS CAN UNDERSTAND WHAT I SAY.. Please help me...

for first question you can use master form which makes your code look good and standardized and also makes all the other required forms modal for the master

This post has been edited by ashishshevale: 30 April 2009 - 05:17 AM

Was This Post Helpful? 0
  • +
  • -

#11 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: I have two problems please help me.....

Posted 30 April 2009 - 06:33 AM

View PostADK_007, on 30 Apr, 2009 - 03:28 AM, said:

View PostSixOfEleven, on 29 Apr, 2009 - 08:14 PM, said:

I have a solution to your first problem but it is a little complex.

1 - go into Form1 and declare a bool variable loginSuccessful:

public bool loginSuccessful = false;


2 - go into the Program.cs file. Where it says Application.Run(new Form1()) change Form1 to Form2

3 - go into the code for Form2 and go to the constructor and add this code

		public Form2()
		{
			InitializeComponent();
			this.Hide();
			Form1 form = new Form1();
			form.ShowDialog();
			if (!form.loginSuccessful)
				Application.Exit();
		}



4 - go into the code for Form1

5 - where in your form where the login is entered successfully add this code at the end

   loginSuccessful = true;
   this.Close();



6 - if the login is unsuccessful add this code

	loginSuccesssful = false;
	this.Close();



What this will do is start with Form2 instead of Form1. It will call Form1 in modal mode which means Form2 will not receive focus until Form1 has finished. If the user closes Form1 or doesn't login successfully Form2 will close and not allow the user into the program. Hope this helps you. :)



yap looks good..... i will try this and tell you the results... BTW thank you for your time...


If it works just click the link. ;) That is enough for me. :)
Was This Post Helpful? 0
  • +
  • -

#12 lesPaul456  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 173
  • View blog
  • Posts: 729
  • Joined: 16-April 09

Re: I have two problems please help me.....

Posted 30 April 2009 - 10:47 AM

Hello,

I just want to note something about your first problem.

I'm guessing the the login form is the startup form for your application. You said that you are hiding the form when the user log in. So, a very simple fix yould be to just fire an event when the main form closes, and then just exit the application in that event.

Create a "FormClosed" event handler for the main form. Then, in that event handler add:
Application.Exit();


This will close the entire application whenever the main form is closed.

Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#13 ADK_007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-April 09

Re: I have two problems please help me.....

Posted 03 May 2009 - 07:12 PM

View PostSixOfEleven, on 29 Apr, 2009 - 08:14 PM, said:

I have a solution to your first problem but it is a little complex.

1 - go into Form1 and declare a bool variable loginSuccessful:

public bool loginSuccessful = false;


2 - go into the Program.cs file. Where it says Application.Run(new Form1()) change Form1 to Form2

3 - go into the code for Form2 and go to the constructor and add this code

		public Form2()
		{
			InitializeComponent();
			this.Hide();
			Form1 form = new Form1();
			form.ShowDialog();
			if (!form.loginSuccessful)
				Application.Exit();
		}



4 - go into the code for Form1

5 - where in your form where the login is entered successfully add this code at the end

   loginSuccessful = true;
   this.Close();



6 - if the login is unsuccessful add this code

	loginSuccesssful = false;
	this.Close();



What this will do is start with Form2 instead of Form1. It will call Form1 in modal mode which means Form2 will not receive focus until Form1 has finished. If the user closes Form1 or doesn't login successfully Form2 will close and not allow the user into the program. Hope this helps you. :)



Sir actually this is working and very useful to me....... But there is a small problem still.....

Normally we are providing user privileges in our systems. But If i use your method providing USER PRIVILEGES is not possible no??? (Actually it's possible but little bit difficult)

In your method LOG-IN window become just a fake.

There should be a proper way of doing this.
Was This Post Helpful? 0
  • +
  • -

#14 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: I have two problems please help me.....

Posted 03 May 2009 - 07:45 PM

View PostADK_007, on 3 May, 2009 - 06:12 PM, said:

View PostSixOfEleven, on 29 Apr, 2009 - 08:14 PM, said:

I have a solution to your first problem but it is a little complex.

1 - go into Form1 and declare a bool variable loginSuccessful:

public bool loginSuccessful = false;


2 - go into the Program.cs file. Where it says Application.Run(new Form1()) change Form1 to Form2

3 - go into the code for Form2 and go to the constructor and add this code

		public Form2()
		{
			InitializeComponent();
			this.Hide();
			Form1 form = new Form1();
			form.ShowDialog();
			if (!form.loginSuccessful)
				Application.Exit();
		}



4 - go into the code for Form1

5 - where in your form where the login is entered successfully add this code at the end

   loginSuccessful = true;
   this.Close();



6 - if the login is unsuccessful add this code

	loginSuccesssful = false;
	this.Close();



What this will do is start with Form2 instead of Form1. It will call Form1 in modal mode which means Form2 will not receive focus until Form1 has finished. If the user closes Form1 or doesn't login successfully Form2 will close and not allow the user into the program. Hope this helps you. :)



Sir actually this is working and very useful to me....... But there is a small problem still.....

Normally we are providing user privileges in our systems. But If i use your method providing USER PRIVILEGES is not possible no??? (Actually it's possible but little bit difficult)

In your method LOG-IN window become just a fake.

There should be a proper way of doing this.


If you look at the code there is a bool on Form1 that you will set is set to false when the form is created that will tell if the login is successful or not. When the program returns to Form2 there is a check to see if the login was successful. If it was successful the application should exit.

I made a simple program that demonstrates how this will work. On Form1 I put two buttons on the form. If button1 is clicked it will simulate the login being successful, in any other case the login has failed. I changed the Program.cs file to start with Form2 like I showed above. I changed the code a little in Form2 so that it will loop until the login is successful. Instead of make the variable just public I made it public static so it can be referenced by the class name.

This is the Program2.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace TwoForms
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());
        }
    }
}



This is the code for Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TwoForms
{
    public partial class Form1 : Form
    {
        public static bool loginSuccessful = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            loginSuccessful = true;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            loginSuccessful = false;
            this.Close();
        }
    }
}



This is Form2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TwoForms
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.Hide();
            Form1 form = new Form1();

            do
            {
                form.ShowDialog();
            } while (Form1.loginSuccessful == false);

        }
    }
}



If you were to make this program you will see that nothing will happen with Form2 until button1 is pressed. In your program you would want to change that so nothing will happen until the login is successful. Does that help any?

This post has been edited by SixOfEleven: 03 May 2009 - 07:46 PM

Was This Post Helpful? 1
  • +
  • -

#15 ADK_007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 17-April 09

Re: I have two problems please help me.....

Posted 06 May 2009 - 10:26 PM

View PostSixOfEleven, on 3 May, 2009 - 06:45 PM, said:

If you look at the code there is a bool on Form1 that you will set is set to false when the form is created that will tell if the login is successful or not. When the program returns to Form2 there is a check to see if the login was successful. If it was successful the application should exit.

I made a simple program that demonstrates how this will work. On Form1 I put two buttons on the form. If button1 is clicked it will simulate the login being successful, in any other case the login has failed. I changed the Program.cs file to start with Form2 like I showed above. I changed the code a little in Form2 so that it will loop until the login is successful. Instead of make the variable just public I made it public static so it can be referenced by the class name.

This is the Program2.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace TwoForms
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form2());
        }
    }
}



This is the code for Form1:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TwoForms
{
    public partial class Form1 : Form
    {
        public static bool loginSuccessful = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            loginSuccessful = true;
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            loginSuccessful = false;
            this.Close();
        }
    }
}



This is Form2:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TwoForms
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.Hide();
            Form1 form = new Form1();

            do
            {
                form.ShowDialog();
            } while (Form1.loginSuccessful == false);

        }
    }
}



If you were to make this program you will see that nothing will happen with Form2 until button1 is pressed. In your program you would want to change that so nothing will happen until the login is successful. Does that help any?


I finally got what i need to do..... Thank you very much sir.... You are my hero of the day........
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1