43460

Cancel Leave Event when closing

Question:

I have got a textbox on a form with a method being called from the txPredio_Leave event.

My problem is that is the user has focus on the textbox and then close the form by clicking the little X close icon in the top corner or by calling this.ActiveMdiChild.Close(); or by calling

private void mnucerrarTodas_Click(object sender, EventArgs e) { foreach (Form form in this.MdiChildren) { form.Close(); } }

The txPredio leave execute the method.. then i need doesn't excute this method when the form is closing.

i have think that one solution could be ask in leave event if form is closing

private void txPredio_Leave(object sender, EventArgs e) { if(!form is closing)//pseudo code Check_Load_Predio(); }

or other solution could be

private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { //code for cancel the txPredio_Leave event }

Solution <a href="https://stackoverflow.com/questions/2339362/how-to-stop-textbox-leave-event-firing-on-form-close" rel="nofollow">Here</a> Doesn´t work for me. Then I need one solution for my problem. Thanks in advance

Answer1:

Try removing the Leave handler in FormClosing.

<strong>EDIT</strong>: Like this:

private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { txPredio.Leave -= txPredio_Leave; }

Recommend

  • Can PyCharm set breakpoints on ipython notebook?
  • Associate ID with Class in CSS
  • Getting JavaScript runtime error: irrationalPath, what does it mean?
  • AutoFit Label Font Size
  • .net security exception
  • Type Native Wifi.Wlan + WlanReasonCode cannot be marshaled error
  • formediting modals shows at wrong position
  • iOS Localization Doesn't Work with More Than 63 Files
  • why calling cd shell command through system() or execvp() from a child process won't work?
  • Click on button in another program - FindWindow, C#
  • Can't delete or rename original file after resizing
  • c# open webrowser in many tab
  • How to Cache Real-time Data?
  • Change multiple background-images with jQuery
  • Algorithm for a smudge tool?
  • QLineEdit password safety
  • Optimizing database types to compact database (SQLite)
  • Can Jackson SerializationFeature be overridden per field or class?
  • TFS: Get latest causes slow project reloading
  • Running a C# exe file
  • sending/ receiving email in Java
  • Javascript + PHP Encryption with pidCrypt
  • Eraser for UIBezierPath
  • Why winpcap requires both .lib and .dll to run?
  • Akka Routing: Reply's send to router ends up as dead letters
  • AT Commands to Send SMS not working in Windows 8.1
  • Android Studio and gradle
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Suggestions to manage Login/Logout transitions
  • How do I configure my settings file to work with unit tests?
  • Getting Messege Twice Using IMvxMessenger
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Reading document lines to the user (python)
  • How can i traverse a binary tree from right to left in java?
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?