473,788 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why is MDI form minimized by MessageBox

Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran
Mar 15 '07 #1
6 3497
Looking at it more closely it looks like it is not minimized, but rather de-activated. Still, it behaves as minimized, if any other window is active.
"Goran Djuranovic" <go************ **@newsgroups.n ospamwrote in message news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran
Mar 15 '07 #2
On Mar 15, 1:46 pm, "Goran Djuranovic"
<goran.djurano. ..@newsgroups.n ospamwrote:
Looking at it more closely it looks like it is not minimized, but rather de-activated. Still, it behaves as minimized, if any other window is active.

"Goran Djuranovic" <goran.djurano. ..@newsgroups.n ospamwrote in messagenews:%2* *************** @TK2MSFTNGP03.p hx.gbl...
Hi all,
I have a VB.NET windows application that uses MDI form. When I try to delete a datagrid row from one of the MDI children forms, I use a MessageBox YesNo confirmation, which, after confirmed, minimizes the MDI form. Why is this happening and how can I prevent it?

Important thing to say is, if I use just "OK" MessageBox, it DOES NOT minimize the MDI parent.

TIA
Goran
Hi Goran,

Can you post a code sample of the function that displays the message
box?

Thanks!
Mike

Mar 15 '07 #3
Hi Goran,

Based on my understanding, you have a DataGrid control on a form. When you
press the Delete key to delete a row from the datagrid, you use a
MessageBox to confirm the operation. The problem is that after the
MessageBox is closed, the MDI parent form is de-activated. If I'm off base,
please feel free to let me know.

Are you using VS.NET 2003 or VS 2005? I performed tests on both VS.NET 2003
and VS 2005, but didn't reproduce the problem on the both.

In my VS.NET 2003 test project, I derived the DataGrid class, and override
the IsInputKey and OnKeyDown methods in the derived DataGrid class.

Class MyDataGrid
Inherits DataGrid

' override the IsInputKey method in order to get the KeyDown event to be
raised when the user presses the Delete key
Protected Overrides Function IsInputKey(ByVa l keyData As
System.Windows. Forms.Keys) As Boolean
Return True
End Function

Protected Overrides Sub OnKeyDown(ByVal ke As
System.Windows. Forms.KeyEventA rgs)
If (ke.KeyCode = Keys.Delete) Then
If (MessageBox.Sho w("are you sure to delete the row?",
"delete", MessageBoxButto ns.YesNo) = DialogResult.Ye s) Then
MyBase.OnKeyDow n(ke)
End If
Else
MyBase.OnKeyDow n(ke)
End If
End Sub

End Class

Build the project and add an instance of MyDataGrid on an MDI child form.
When the program is run, I select one row in the DataGrid control and press
the Delete key. A messagebox pops up and I select 'Yes'. The messagebox is
closed and the MDI parent form regains the focus.

In my VS 2005 test project, I add a DataGridView control on an MDI child
form and handle the UserDeletingRow event of the DataGridView.

Public Sub New()
AddHandler Me.DataGridView 1.UserDeletingR ow, AddressOf
dataGridView1_U serDeletingRow
End Sub

Sub dataGridView1_U serDeletingRow( ByVal sender As Object, ByVal e As
DataGridViewRow CancelEventArgs )
If (MessageBox.Sho w("are you sure to delete the row?", "delete",
MessageBoxButto ns.YesNo) = Windows.Forms.D ialogResult.No) Then
e.Cancel = True
End If
End Sub

When the program is run, all works fine.

Is there any difference between your code and mine? If the problem is still
not resolved, you may send me a sample project that could just reproduce
the problem. To get my actual email address, remove 'online' from my
displayed email address.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 16 '07 #4
Linda (& Mike),
I haven't derived my DataGrid like you did, but used the original.
I attached ContextMenu to the datagrid. So, when the user right-clicks on the row, it has an option to delete the row. No matter what the confrmation is (Yes or No), the MDI parent de-activates. I use VS.NET 2003, and the datagrid gets the data from DataTable. Here is the subroutine I use for deletion:
----------------------------------------------------
Private Sub DeleteSource(By Val sender As Object, ByVal e As EventArgs)
Try
If MessageBox.Show ("Are you sure you want to delete selected record?", "Warning!", YesNo, Question, Button2, DefaultDesktopO nly) = Yes Then
SourceIDStr = SourceDataTable Obj.Rows.Item(S electedSourceRo wInt).Item("Sou rceID").ToStrin g()
End If
Me.MdiParent.Ac tivate() <--- this line makes it work fine, but why do I have to do that???
Catch ErrObj As Exception
SetErrorMessage (ErrObj)
End Try
End Sub
----------------------------------------------------

DeleteSource is called by a context menu event handler. I will try deriving my datagrid like you did, just to see if that makes it work.

TIA
Goran
"Linda Liu [MSFT]" <v-****@online.mic rosoft.comwrote in message news:rU******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Hi Goran,

Based on my understanding, you have a DataGrid control on a form. When you
press the Delete key to delete a row from the datagrid, you use a
MessageBox to confirm the operation. The problem is that after the
MessageBox is closed, the MDI parent form is de-activated. If I'm off base,
please feel free to let me know.

Are you using VS.NET 2003 or VS 2005? I performed tests on both VS.NET 2003
and VS 2005, but didn't reproduce the problem on the both.

In my VS.NET 2003 test project, I derived the DataGrid class, and override
the IsInputKey and OnKeyDown methods in the derived DataGrid class.

Class MyDataGrid
Inherits DataGrid

' override the IsInputKey method in order to get the KeyDown event to be
raised when the user presses the Delete key
Protected Overrides Function IsInputKey(ByVa l keyData As
System.Windows. Forms.Keys) As Boolean
Return True
End Function

Protected Overrides Sub OnKeyDown(ByVal ke As
System.Windows. Forms.KeyEventA rgs)
If (ke.KeyCode = Keys.Delete) Then
If (MessageBox.Sho w("are you sure to delete the row?",
"delete", MessageBoxButto ns.YesNo) = DialogResult.Ye s) Then
MyBase.OnKeyDow n(ke)
End If
Else
MyBase.OnKeyDow n(ke)
End If
End Sub

End Class

Build the project and add an instance of MyDataGrid on an MDI child form.
When the program is run, I select one row in the DataGrid control and press
the Delete key. A messagebox pops up and I select 'Yes'. The messagebox is
closed and the MDI parent form regains the focus.

In my VS 2005 test project, I add a DataGridView control on an MDI child
form and handle the UserDeletingRow event of the DataGridView.

Public Sub New()
AddHandler Me.DataGridView 1.UserDeletingR ow, AddressOf
dataGridView1_U serDeletingRow
End Sub

Sub dataGridView1_U serDeletingRow( ByVal sender As Object, ByVal e As
DataGridViewRow CancelEventArgs )
If (MessageBox.Sho w("are you sure to delete the row?", "delete",
MessageBoxButto ns.YesNo) = Windows.Forms.D ialogResult.No) Then
e.Cancel = True
End If
End Sub

When the program is run, all works fine.

Is there any difference between your code and mine? If the problem is still
not resolved, you may send me a sample project that could just reproduce
the problem. To get my actual email address, remove 'online' from my
displayed email address.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 16 '07 #5
Hi Goran,

Thank you for your reply.

I performed a test based on your sample code but still couldn't reproduce
the problem. In my test project, I didn't add the statement
'Me.MdiParent.A ctivate()', and the MDI parent got focused when the
MessageBox was closed.

I think the problem may be caused by the actual code in your project. You
may have a try replacing the MessageBox with a custom form of your own to
see if the problem still exists.

If the problem is still not solved, you may send me a sample project that
could just reproduce the problem.

Sincerely,
Linda Liu
Microsoft Online Community Support

Mar 20 '07 #6
Hi Linda,
I found out what it is, it is the "MessageBoxOpti ons.DefaultDesk topOnly"
portion of the message box. Once I removed that, it was fine. Anyway, thanks
for all your help.

Goran Djuranovic
"Linda Liu [MSFT]" <v-****@online.mic rosoft.comwrote in message
news:5$******** *****@TK2MSFTNG HUB02.phx.gbl.. .
Hi Goran,

Thank you for your reply.

I performed a test based on your sample code but still couldn't reproduce
the problem. In my test project, I didn't add the statement
'Me.MdiParent.A ctivate()', and the MDI parent got focused when the
MessageBox was closed.

I think the problem may be caused by the actual code in your project. You
may have a try replacing the MessageBox with a custom form of your own to
see if the problem still exists.

If the problem is still not solved, you may send me a sample project that
could just reproduce the problem.

Sincerely,
Linda Liu
Microsoft Online Community Support

Mar 22 '07 #7

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

Similar topics

0
1401
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized automatically. I tried some way to call frmMain.WindowState = FormWindowState.Minimized. The result is my 2 forms are minimized but the side effect is the Child form is gone. Dim f As New frmChild f.ShowDialog()
2
2599
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized automatically. I tried some way to call frmMain.WindowState = FormWindowState.Minimized. The result is my 2 forms are minimized but the side effect is the Child form is gone. Dim f As New frmChild f.ShowDialog()
1
2112
by: Tai | last post by:
Hi all I have 2 forms, frmMain and frmChild. In frmMain, I declare a variable f as frmChid then Call f.ShowDialog() I want when the child form is minimized, the Main form is also minimized automatically. I tried some way to call frmMain.WindowState = FormWindowState.Minimized. The result is my 2 forms are minimized but the side effect is the Child form is gone. Dim f As New frmChild f.ShowDialog()
2
51695
by: amil [c#newbie] | last post by:
Hi all, I am using the Notify Icon sample that came with .Net Docs and was able to run it. However, I want to start the form as minimized. I have the ShowInTaskbar = false and in the this is my code in the form load: private void Form1_Load(object sender, System.EventArgs e) { this.WindowState = FormWindowState.Minimized; this.Visible = false;
8
47304
by: Terry Olsen | last post by:
I want to minimize my program to the tray when minimized. But there's no "minimize" event. So how can I catch this event and use it?
2
7900
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor I call both this.Show() and this.Activate(), but if the parent application is minimized then the Alert form will also stay minimized (and just flash). How can I cause the Alert form to show itself and grab focus?
7
9337
by: Lee | last post by:
Hi, How do I detect when a form is minimizing? specifically when a user clicks the show desktop button on the taskbar, rather than the minimize button on a form. thanks in advance
3
7197
by: Mark Jerde | last post by:
VS 2005. When I google "CSharp single instance form" the returned pages usually use a Mutex or the VB.NET runtime library. http://en.csharp-online.net/Application_Architecture_in_Windows_Forms_2.0%E2%80%94Single-Instance_Detection_and_Management http://www.codeproject.com/csharp/SingleInstanceApplication.asp http://blogs.msdn.com/onoj/archive/2004/06/04/148532.aspx "Program.cs" below seems to work fine. A feature is it restores a...
4
2844
by: raylopez99 | last post by:
See comment below. This is a simple problem but I'm a little rusty. How to break out of a event loop (here _Paint)? I've tried if/else, case, etc but not quite what I want--I keep getting the JIT system event exception handler saying "zero area!", or, worse, the Paint loop refuses to run at all; what I want to do is simply break out of the _Paint loop, and (optionally) show a MessageBox. This error happens everytime the...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
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...
0
10172
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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

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.