Hi. I'm working with my project right now. In my project, there will be 2 form; I will call form1 and form2. Form 1 call first and then it has button to call form 2. I don't want user open many form2 so I use a private boolean variable. When the button is clicked, it call the function to check the bool variable, if false then show form 1 and set the bool variable to true. And form2 open, and that works to prevent user open many form. But after that, I cannot call it again due to the bool variable that time is true. So i want like when the form closed, it will set the variable to false, but it doesn't work. I use debugger and find out that when I close the form, it will call dispose to erase every resource, so that the instance of the form1 in form2 is deleted. So how can I fix that? All I want is prevent it from open many and open it again when need. I appreciate every answer.
NguyenThai
0
Newbie Poster
Recommended Answers
Jump to PostSome of the code you are using might be helpful, but using the
Close
event is probably what you are looking for.
Jump to PostI don't want user open many form2 so I use a private boolean variable. When the button is clicked, it call the function to check the bool variable, if false then show form 1 and set the bool variable to true. And form2 open, and that works to prevent user …
Jump to PostInstead of using a private bool variable, use a private variable for Form2, then you have some options...
public partial class Form1 : Form { private Form2 _form2 = null; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { button1.Enabled = false; _form2 = …
All 9 Replies
nmaillet
97
Posting Whiz in Training
Ramy Mahrous
401
Postaholic
Featured Poster
JerryShaw
46
Posting Pro in Training
NguyenThai
0
Newbie Poster
Ramy Mahrous
401
Postaholic
Featured Poster
Rohini_in
0
Newbie Poster
shajis001
-1
Newbie Poster
adetolah
0
Newbie Poster
adetolah
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.