简体   繁体   中英

How to pop up a message box when user clicks anywhere within the form window in Visual Studio?

I'm fairly new to Visual Studio in C#.

I was wondering how to pop up a message box when the user clicks anywhere within the form window.

Basically, I don't want them accessing and interacting with the program unless they have a password.

Code for the Form1() is really simple right now:

public Form1()
{
    InitializeComponent();
}

The actual interface has a bunch of buttons and settings (buttons and settings I don't want the user to be able to interact with unless they have verified themselves).

Click on form and press F4 key that show property window then click on event button there you click on click event that show in .cs file of form .

Make function like

private void Form1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Click");
        }

regarding the 1st questions. You usually create a second model form , that is transparent and is on top of your form. Handle the on-click event of the transparent form .

Regarding the second questions- you should rethink your design , maybe do not show the sensitive form at all untill a user has typed the password.

By the way , you have not specified what tech do you use? is it desktop (winforms / wpf , other)/ web (web forms, asp mvc, other) ?

recommended reading for client side windows programming.

http://msdn.microsoft.com/en-us/library/dd492132.aspx

Edit: In order to put a form on top of another form , you use a model dialog.

http://msdn.microsoft.com/en-us/library/39wcs2dh(v=vs.110).aspx

In order to create a form transparent

http://msdn.microsoft.com/en-us/library/czke9azk(v=vs.110).aspx

Also , it still depends on your UI technology.

Provided links are form winforms, other technology may require a different approach.

Edit: As another answer pointed out , you could also bind to the original forms click event , but you will also have to bind to every child control click event recursively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM