473,800 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems when canceling OnClosing

I want to prevent a form from closing when the user clicks the form's Close button in the form's ControlBox (i.e., the button with the "X" in the upper-right corner of the form). Instead, I just want to hide the form. My idea is to do something like the following

Protected Overrides Sub OnClosing(ByVal e As System.Componen tModel.CancelEv entArgs
e.Cancel = Tru
MyBase.OnClosin g(e
Me.Visible = Fals
End Su

This technique seems to work fine if the form is shown as a modeless dialog (i.e., via Form.Show). But, if I show the form as a modal dialog (i.e., via Form.ShowDialog ) then the form's controls become corrupt after the form is hidden (by the user clicking the Cancel ControlBox button) and then reshown (by calling the form's ShowDialog method). Note that I need to show the form as a modal dialog

The corruption is most apparent for controls that inherit from ButtonBase and have their FlatStyle property set to Flat. In this case, when the form is reshown the controls' graphics freeze in the "MouseOver" state

I imagine that I must be doing something wrong. Any advice

Thanks
Lance
Nov 20 '05 #1
1 1297
* "=?Utf-8?B?TGFuY2U=?=" <zi***@hotmail. com> scripsit:
I want to prevent a form from closing when the user clicks the form's Close button in the form's ControlBox (i.e., the button with the "X" in the upper-right corner of the form). Instead, I just want to hide the form. My idea is to do something like the following:

Protected Overrides Sub OnClosing(ByVal e As System.Componen tModel.CancelEv entArgs)
e.Cancel = True
MyBase.OnClosin g(e)
Me.Visible = False
End Sub

This technique seems to work fine if the form is shown as a modeless dialog (i.e., via Form.Show). But, if I show the form as a modal dialog (i.e., via Form.ShowDialog ) then the form's controls become corrupt after the form is hidden (by the user clicking the Cancel ControlBox button) and then reshown (by calling the form's ShowDialog method). Note that I need to show the form as a modal dialog.


Did you try to show the form again by setting its 'Visible' property to 'True'?

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7366
by: Phil Galey | last post by:
VB.NET 2002 on Windows 2000 SP 3 When I start my program, the NotifyIcon appears in the tray, as it should. However, when I close the program, the NotifyIcon remains until I hover over it with my mouse. If I don't hover over it to make it disappear and then open the program again, another one is added, resulting in a multiplicity of the icon in the tray. I've even tried setting its Visible property to false, followed by a call to the...
4
4064
by: welie | last post by:
I have a problem canceling a check box update when placing a check in it. Checkbox is not bound. Here is what happens. User clicks a check box. In the BeforeUpdate method of the control, if the check box is being checked, some validation is performed. If the validation fails, I set cancel to true, and the check box is not checked afterwards. This is fine.
1
1715
by: Alex Bink | last post by:
Hi, Anyone knows how to prevent the validating event of a control to be fired when the user clicks the close button? The OnClosing event of the form seems to be to late and setting the form's CausesValidation property to false doesn't seem to help either... Thanks...
3
1077
by: RBirney | last post by:
I have a program (code below) which has a main screen with a button, a tabcontrol and a couple of tab pages. I have two pre written forms that i then put onto the tab pages. The problem i have is when i exit the forms in the tabs i want to clear the text out of the tabpage (which is set in the code below when they are loaded) but i cannot do it from the form as it won't allow me at it and i have no way of actioning it back on the main...
1
4093
by: Phill W. | last post by:
Has any come across a situation where, in a Form-derived .. er .. Form, the Event Arguments passed to OnClosing /already/ have their Cancel argument set to True? Protected Overrides Sub OnClosing( _ ByVal e As System.ComponentModel.CancelEventArgs _ ) Debug.WriteLine("e.Cancel=(" & e.Cancel.ToString() & ")") ' It's True already !!
2
1827
by: polocar | last post by:
Hi, I'm writing a C# program that interfaces with a SQL Server 2005 database (I use Visual Studio 2005 Professional Edition as compiler). I have defined the classical ADO.NET SqlDataAdapter, DataSet and DataTable objects so that, once the database has been loaded with the SqlDataAdapter Fill method, you work with the data off-line. I would like to put a control in the Form OnClosing event handler method: if there are some changes...
2
3299
by: polocar | last post by:
Hi, suppose that you have a C# form with two buttons, that are the classical "btnOk" and "btnCancel" (besides them, of course in the form there can be many other controls). When the user clicks on btnOk, the program makes some confirm operations and closes the form. When the user clicks on btnCancel, the program makes some cancel operations and closes the form. My problem is that, when the user clicks on the "X" button of the form...
2
1795
by: mdavis | last post by:
Hello, I'm using a Login Control on asp.net 2.0 website and it works fine on IE & Firefox, however I have recently added a javscript function to listen for a 'return-key-click' and am encountering problems with Firefox. If the user clicks the 'Login' button with a mouse button click, it works fine, however if the user hits enter, the form fields are cleared and the user is not logged in. Please note, this only happens if the user has...
10
1433
by: kendalk08 | last post by:
This post is for those struggling to figure out why there Drop Down Menus and other scripts are not working using th DOM. There are slight DOM problems with ONMOUSEOVER and ONMOUSEOUT events of parent and child elements. When the child element fires its ONMOUSEOVER event it also fires the ONMMOUSEOUT event. When this happens you get a canceling of script (Like using timers for instance). Because of this you have to check to make sure you...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7580
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.