473,414 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

shown event problem

10
Hi,

I have a problem about shown event. I have a login form and a main form. I start the program with main form. then I used frmMain.Shown() to control the login form. When main form is shown, it checks Win. Registry if username and password is stored there. İf yes, login form comes and wants me to sign in and if not, it calls first login form to create a record in Registry.

The problem is that;
When I click on X (close) button, it closes the login form, but Main form is still running and I can use it without sign in.

How do I solve this problem? Or is there any other way to controls if Registry has the record or not?

Thanks&Regards...
May 24 '10 #1
5 1183
tlhintoq
3,525 Expert 2GB
I would suggest you create a class of "privileges" that contain properties like "CanExit", "CanMakeUsers" and so on.

Your main form methods should check the user's privileges class to see if they are allowed to do each thing.

You populate the privileges at log in. If they don't log in, the privileges are all false.
May 24 '10 #2
nrylm25
10
@tlhintoq
thanks for your reply...

But I want to close program completely when user canceled the Login process. the program closes when I close it form cancel button, but I also want to close it when I click on X button.

Privileges are good idea, but I dont work with a database, the progarm is created for a single user, and all the information is stored in windows registry.
May 24 '10 #3
tlhintoq
3,525 Expert 2GB
nrylm25: Privileges are good idea, but I dont work with a database, the progarm is created for a single user, and all the information is stored in windows registry.
So store the privileges in the registry. I do it all the time. I just encrypt the features so someone can't use RegEdit to give themselves capabilities.

nrylm25: But I want to close program completely when user canceled the Login process. the program closes when I close it form cancel button, but I also want to close it when I click on X button.
Ok. So quit the program. You should create a single "Quit()" method, then call that from all the various ways someone might quit the program. If they choose a menu option "File | Exit" then call the Quit() method. If they close the form, then call the Quit() method.

This way you have consistent behavior. Everything routes through the same Quit() method, which is responsible for cleaning up, closing threads, closing datafiles etc.etc.

Take a look at the FormClosing event. No matter how they close the form, the form still fires this event.
May 24 '10 #4
tlhintoq
3,525 Expert 2GB
If you are having trouble with your Main form reacting to events in your log-in form, maybe this will help.

Original Poster: How do I get my Form2 to react to something on my Form1?
How do I make my Form1 control something on my Form2?
Although you can have Form1 directly access items on Form2 it isn't the recommended way to go. It ties the two forms tightly to each other. If a change is made in Form2 such as removing one of the controls, then code in Form1 breaks.
It is better to Form1 raise an event, and have Form2 contain its own code for how to react to this. This places responsibility for Form2 within Form2, and Form1 within Form1.
It keeps Form1 blissfully ignorant of Form2 - and a logging component - and a progress component, and a dozen other little black boxes that can be subscribed to events in Form1, all without Form1 being made responsible for directly affecting controls other than itself.
Events tutorial (including Form to Form which is the same as class to class)
This tutorial for a cash register does exactly that: It makes a virtual numeric keyboard.

Bad: Directly accessing controls of one class/form from another.
Expand|Select|Wrap|Line Numbers
  1. bool IsOn = Form2.button1.IsChecked;
Good: Use a property to get such information
Expand|Select|Wrap|Line Numbers
  1. //Form1
  2. bool IsOn = Form2.IsOn;
Expand|Select|Wrap|Line Numbers
  1. //Form 2
  2. public bool IsOn
  3. {
  4.    get { return CheckBox1.Checked; }
  5.    set { CheckBox1.Checked = value; }
  6. }
It's a subtle but important difference as your applications become more complex. Using properties means your target class/form (Form2) can be changed and updated a thousand different ways yet won't negatively impact the classes that are reading from it. If you change the name of a control for example: It won't break references in all your other classes. If your target form evolves where it needs to do 10 things when it is turned on, then the responsibility stays within Form2, and that burden is not put on Form1 and a dozen other forms that might be using Form2. The goal is to compartimentalize the work so that Form2 is responsiblity SOLELY for Form2. From1 should only have to say "Turn on" or "Turn Off"

Form2
Expand|Select|Wrap|Line Numbers
  1. public bool IsOn
  2. {
  3.    get { return btnMeaningfulName.Checked; }
  4.    set {
  5.             btnMeaningfulName.Checked = value;
  6.             panelDashboard.Visible = value;
  7.             labelStatus = value == true ? "On" : "Off";
  8.             btnRunNow.Enabled = value;
  9.        }
  10. }
Now when Form1 tells Form2 to turn on, Form2 will check a box, make an entire panel visible, change its Status label to say 'On' and enable a Run Now button.
May 24 '10 #5
nrylm25
10
@tlhintoq
Thanx a lot....

I solved the problem. Thanks again:))
May 24 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
2
by: Chuck Bowling | last post by:
I have a problem I can't quite figure out. I want to trigger an event when a some text is selected in a RichTextBox. When the selection is finished, I want to mark the selected text and allow...
3
by: bhavik | last post by:
hi I have problem that when I am upload my application to the client server, I am losing buttion event on some pages. on some pages button event is working fine ro some pages is not working. I...
7
by: Girish | last post by:
OK.. phew. Playing with data grids for the past few days has been fun and a huge learning experience.. My problem. I have a requirement to display a gird with a gird. Within the embedded grid,...
2
by: henk | last post by:
Hi, On my form I have one textbox and one lookup button. If you click the lookup button you can choose eg Red, Blue, Yellow from a datagrid. The one you choose will be filled in the textbox....
1
by: Victory | last post by:
i am using the Shown event for a form. It is in .NET 2.0. It is an event that occurs when a form is displayed. I wanted to use this event since i needed the processing of data to occur after the...
2
by: cty0000 | last post by:
Please anybody help me... I have some serious problem.. I'm doing to keep equpiment list(string).. In my code, there are 3 page which are having 4 equpiment ID (user control.) like this...
3
by: cty0000 | last post by:
Please anybody help me... I have some serious problem.. I'm doing to keep equpiment list(string).. In my code, there are 3 page which are having 4 equpiment ID (user control.) like this...
8
by: Dilip | last post by:
I am running into a weird problem in my ultra-simple Winforms application written in C#. In the Form.Shown event I set a couple of environment variables using the standard SetEnvironmentVariable...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.