Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modal Dialogbox disappearing when switching to other virtual desktop

Status
Not open for further replies.

LazyMe

Programmer
Jan 13, 2003
938
MX
Hi, I'm using Actual Windows Manager which has a virtual desktop switcher and a collegue of mine uses another virtual desktop manager (of which I don't know the name).

Both of us have the exact same problem: I show a modal dialog from my dotnet app (ShowModal(me/this)) and when I switch from my main desktop to a virtual one, the modal dialog returns DialogResult.Cancel. This is with every dotnet app we have and it is ONLY with dotnet apps; other apps just behave well when switching desktops.

So, I guess dotnet doesn't really show a modal dialog (something I suspected already before this problem surfaced), but the question is: How can we prevent this from happening. It is really destructive if our users start out filing forms and halfway thru that switch to another desktop and when returned find that their form is gone...

Any advice greatly welcomed!

Thanks....

Greetings,
Rick
 
Hi Rick,
Perhaps you could show us a piece of your code here.

Regards.
 
There is really nothing special about that and it happens with every modal dialogbox in every dotnet app. An xample would be:

Code:
using (dlgDatabase dlg = new dlgDatabase(Connection.CurrentConnectionString))
{
  if (dlg.ShowDialog(this) == DialogResult.Cancel)
  {
    //Do something after cancel ws clicked. Unfortunately it also gets here when switching to a virtual desktop.....
  }
}

Greetings,
Rick
 
By the way: I grabbed this from a C# app, but the exact same lines in VB.NET cuase the exact same problem....

Greetings,
Rick
 
Seems fine to me, except that you put something in the dlgDatabase's lost focus or similar events.

Another thing that crossed my mind is whether the dlgDatabase form has accept and cancel button set.

Would you tell us more about the dlgDatabase form?

Regards.
 
Yes, the dlgDatabase form has accept and cancel buttons set. But other forms where this occurs do not have those buttons set. Also, there are no other events hooked to the form itself:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using LangSoftDev.Data.SQLClient;
using LangSoftDev.Data.SQLClient.Errors;
using LangSoftDev.Data.SQLClient.Enumerations;
using LangSoftDev.Data.SQLClient.Desktop;
using System.Data;
using System.Data.SqlClient;

namespace Reporting
{
    public partial class dlgDatabase : Form
    {
        #region Member variables
        private bool m_bServersRefreshed;
        #endregion

        #region Constructors
        public dlgDatabase()
        {
            InitializeComponent();
        }
        public dlgDatabase(string sConnectionString)
            :this()
        {
            cmbServer.DropDown += new EventHandler(cmbServer_DropDown);
            optNT.CheckedChanged += new EventHandler(optNT_CheckedChanged);

            cmdOK.Click += new EventHandler(cmdOK_Click);
            cmdRefresh.Click += new EventHandler(cmdRefresh_Click);
            cmdTestConnection.Click += new EventHandler(cmdTestConnection_Click);

            if (sConnectionString != null)
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(sConnectionString);

                cmbServer.Text = builder.DataSource;

                if (builder.IntegratedSecurity)
                    optNT.Checked = true;

                else
                {
                    optSQL.Checked = true;

                    txtUID.Text = builder.UserID;
                    txtPW.Text = builder.Password;
                }
            }
        }
        #endregion

        #region Private methods
        private void EnumerateServers(bool bForceRefresh)
        {
            if (bForceRefresh || !m_bServersRefreshed)
            {
                m_bServersRefreshed = true;

                lblStatus.Text = "Refreshing servers.....";
                Cursor = Cursors.WaitCursor;

                Application.DoEvents();

                try
                {
                    string sServer = string.Empty;

                    using (DataTable servers = SqlDataSourceEnumerator.Instance.GetDataSources())
                    {
                        cmbServer.Items.Clear();

                        foreach (DataRow row in servers.Rows)
                        {
                            sServer = row[0].ToString();
                            if (row[1] != System.DBNull.Value) sServer += "\\" + row[1].ToString();

                            cmbServer.Items.Add(sServer);
                        }
                    }

                    lblStatus.Text = "";
                    Cursor = Cursors.Default;

                    Application.DoEvents();
                }
                catch (Exception ex)
                {
                    lblStatus.Text = "";
                    Cursor = Cursors.Default;

                    Application.DoEvents();

                    MessageBox.Show(this, "Error while refreshing the list with servers:\n\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private bool TestConnection(bool bShowSuccess, bool bSaveConnection)
        {
            Connection con = null;

            if (cmbServer.Text.Trim().Length == 0)
            {
                MessageBox.Show(this, "Please enter or select a servername first.", Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return false;
            }

            try
            {
                lblStatus.Text = "Testing connection.....";
                Cursor = Cursors.WaitCursor;

                Application.DoEvents();

                con = new Connection(ConnectionString, bSaveConnection);

                lblStatus.Text = "";
                Cursor = Cursors.Default;

                Application.DoEvents();

                if (bShowSuccess) MessageBox.Show(this, "Connection OK.", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;
            }
            catch (Exception ex)
            {
                lblStatus.Text = "";
                Cursor = Cursors.Default;

                Application.DoEvents();

                MessageBox.Show(this, "Error while opening the connection:\n\n" + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);

                return false;
            }
            finally
            {
                if (con != null) con.Dispose();
            }
        }
        #endregion

        #region Event handlers
        void optNT_CheckedChanged(object sender, EventArgs e)
        {
            if (optNT.Checked)
            {
                txtUID.Enabled = false;
                txtPW.Enabled = false;

                txtUID.Clear();
                txtPW.Clear();
            }
            else
            {
                txtUID.Enabled = true;
                txtPW.Enabled = true;
            }
        }
        void cmdTestConnection_Click(object sender, EventArgs e)
        {
            TestConnection(true, false);
        }
        void cmdRefresh_Click(object sender, EventArgs e)
        {
            EnumerateServers(true);
        }
        void cmdOK_Click(object sender, EventArgs e)
        {
            if (TestConnection(false, true)) DialogResult = DialogResult.OK;
        }
        void cmbServer_DropDown(object sender, EventArgs e)
        {
            EnumerateServers(false);
        }
        #endregion

        #region Properties
        public string ConnectionString
        {
            get { return Helpers.CreateConnectionString(cmbServer.Text.Trim(), "Report Creator", false, optNT.Checked, txtUID.Text.Trim(), txtPW.Text.Trim()); }
        }
        public string Server
        {
            get { return cmbServer.Text.Trim(); }
        }
        #endregion
    }
}


And just in case you were wondering, here's the designer code:


Code:
namespace Reporting
{
    partial class dlgDatabase
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(dlgDatabase));
            this.lblServer = new System.Windows.Forms.Label();
            this.cmbServer = new System.Windows.Forms.ComboBox();
            this.cmdRefresh = new System.Windows.Forms.Button();
            this.lblLogonInfo = new System.Windows.Forms.Label();
            this.pnlLogonOptions = new System.Windows.Forms.Panel();
            this.optSQL = new System.Windows.Forms.RadioButton();
            this.optNT = new System.Windows.Forms.RadioButton();
            this.txtUID = new System.Windows.Forms.TextBox();
            this.lblUser = new System.Windows.Forms.Label();
            this.txtPW = new LangSoftDev.dotNETControls.InputControls.PasswordControl();
            this.lblPassword = new System.Windows.Forms.Label();
            this.cmdCancel = new System.Windows.Forms.Button();
            this.cmdOK = new System.Windows.Forms.Button();
            this.cmdTestConnection = new System.Windows.Forms.Button();
            this.lblStatus = new System.Windows.Forms.Label();
            this.pnlLogonOptions.SuspendLayout();
            this.SuspendLayout();
            // 
            // lblServer
            // 
            this.lblServer.AutoSize = true;
            this.lblServer.Location = new System.Drawing.Point(13, 13);
            this.lblServer.Name = "lblServer";
            this.lblServer.Size = new System.Drawing.Size(161, 13);
            this.lblServer.TabIndex = 0;
            this.lblServer.Text = "1. Select or enter a &server name:";
            // 
            // cmbServer
            // 
            this.cmbServer.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.cmbServer.FormattingEnabled = true;
            this.cmbServer.Location = new System.Drawing.Point(44, 29);
            this.cmbServer.Name = "cmbServer";
            this.cmbServer.Size = new System.Drawing.Size(266, 21);
            this.cmbServer.TabIndex = 1;
            // 
            // cmdRefresh
            // 
            this.cmdRefresh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.cmdRefresh.Location = new System.Drawing.Point(317, 29);
            this.cmdRefresh.Name = "cmdRefresh";
            this.cmdRefresh.Size = new System.Drawing.Size(75, 21);
            this.cmdRefresh.TabIndex = 2;
            this.cmdRefresh.Text = "&Refresh";
            this.cmdRefresh.UseVisualStyleBackColor = true;
            // 
            // lblLogonInfo
            // 
            this.lblLogonInfo.AutoSize = true;
            this.lblLogonInfo.Location = new System.Drawing.Point(13, 60);
            this.lblLogonInfo.Name = "lblLogonInfo";
            this.lblLogonInfo.Size = new System.Drawing.Size(207, 13);
            this.lblLogonInfo.TabIndex = 3;
            this.lblLogonInfo.Text = "2. Enter information to log on to the server:";
            // 
            // pnlLogonOptions
            // 
            this.pnlLogonOptions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.pnlLogonOptions.Controls.Add(this.optSQL);
            this.pnlLogonOptions.Controls.Add(this.optNT);
            this.pnlLogonOptions.Location = new System.Drawing.Point(38, 77);
            this.pnlLogonOptions.Name = "pnlLogonOptions";
            this.pnlLogonOptions.Size = new System.Drawing.Size(354, 54);
            this.pnlLogonOptions.TabIndex = 4;
            // 
            // optSQL
            // 
            this.optSQL.AutoSize = true;
            this.optSQL.Location = new System.Drawing.Point(15, 28);
            this.optSQL.Name = "optSQL";
            this.optSQL.Size = new System.Drawing.Size(141, 17);
            this.optSQL.TabIndex = 1;
            this.optSQL.TabStop = true;
            this.optSQL.Text = "Use S&QL Server security";
            this.optSQL.UseVisualStyleBackColor = true;
            // 
            // optNT
            // 
            this.optNT.AutoSize = true;
            this.optNT.Location = new System.Drawing.Point(15, 4);
            this.optNT.Name = "optNT";
            this.optNT.Size = new System.Drawing.Size(148, 17);
            this.optNT.TabIndex = 0;
            this.optNT.TabStop = true;
            this.optNT.Text = "Use &Windows NT security";
            this.optNT.UseVisualStyleBackColor = true;
            // 
            // txtUID
            // 
            this.txtUID.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtUID.Location = new System.Drawing.Point(135, 137);
            this.txtUID.MaxLength = 125;
            this.txtUID.Name = "txtUID";
            this.txtUID.Size = new System.Drawing.Size(257, 20);
            this.txtUID.TabIndex = 6;
            // 
            // lblUser
            // 
            this.lblUser.AutoSize = true;
            this.lblUser.Location = new System.Drawing.Point(66, 137);
            this.lblUser.Name = "lblUser";
            this.lblUser.Size = new System.Drawing.Size(63, 13);
            this.lblUser.TabIndex = 5;
            this.lblUser.Text = "&User Name:";
            // 
            // txtPW
            // 
            this.txtPW.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.txtPW.Location = new System.Drawing.Point(135, 164);
            this.txtPW.Name = "txtPW";
            this.txtPW.PasswordChar = '?';
            this.txtPW.Size = new System.Drawing.Size(257, 20);
            this.txtPW.TabIndex = 8;
            // 
            // lblPassword
            // 
            this.lblPassword.AutoSize = true;
            this.lblPassword.Location = new System.Drawing.Point(69, 168);
            this.lblPassword.Name = "lblPassword";
            this.lblPassword.Size = new System.Drawing.Size(56, 13);
            this.lblPassword.TabIndex = 7;
            this.lblPassword.Text = "&Password:";
            // 
            // cmdCancel
            // 
            this.cmdCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.cmdCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.cmdCancel.Location = new System.Drawing.Point(316, 225);
            this.cmdCancel.Name = "cmdCancel";
            this.cmdCancel.Size = new System.Drawing.Size(75, 23);
            this.cmdCancel.TabIndex = 11;
            this.cmdCancel.Text = "&Cancel";
            this.cmdCancel.UseVisualStyleBackColor = true;
            // 
            // cmdOK
            // 
            this.cmdOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.cmdOK.Location = new System.Drawing.Point(235, 225);
            this.cmdOK.Name = "cmdOK";
            this.cmdOK.Size = new System.Drawing.Size(75, 23);
            this.cmdOK.TabIndex = 10;
            this.cmdOK.Text = "&OK";
            this.cmdOK.UseVisualStyleBackColor = true;
            // 
            // cmdTestConnection
            // 
            this.cmdTestConnection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.cmdTestConnection.Location = new System.Drawing.Point(16, 225);
            this.cmdTestConnection.Name = "cmdTestConnection";
            this.cmdTestConnection.Size = new System.Drawing.Size(122, 23);
            this.cmdTestConnection.TabIndex = 9;
            this.cmdTestConnection.Text = "T&est Connection";
            this.cmdTestConnection.UseVisualStyleBackColor = true;
            // 
            // lblStatus
            // 
            this.lblStatus.AutoSize = true;
            this.lblStatus.Location = new System.Drawing.Point(16, 206);
            this.lblStatus.Name = "lblStatus";
            this.lblStatus.Size = new System.Drawing.Size(0, 13);
            this.lblStatus.TabIndex = 12;
            // 
            // dlgDatabase
            // 
            this.AcceptButton = this.cmdOK;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.CancelButton = this.cmdCancel;
            this.ClientSize = new System.Drawing.Size(409, 260);
            this.Controls.Add(this.lblStatus);
            this.Controls.Add(this.cmdTestConnection);
            this.Controls.Add(this.cmdOK);
            this.Controls.Add(this.cmdCancel);
            this.Controls.Add(this.lblPassword);
            this.Controls.Add(this.txtPW);
            this.Controls.Add(this.lblUser);
            this.Controls.Add(this.txtUID);
            this.Controls.Add(this.pnlLogonOptions);
            this.Controls.Add(this.lblLogonInfo);
            this.Controls.Add(this.cmdRefresh);
            this.Controls.Add(this.cmbServer);
            this.Controls.Add(this.lblServer);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "dlgDatabase";
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
            this.Text = "Select Database:";
            this.pnlLogonOptions.ResumeLayout(false);
            this.pnlLogonOptions.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label lblServer;
        private System.Windows.Forms.ComboBox cmbServer;
        private System.Windows.Forms.Button cmdRefresh;
        private System.Windows.Forms.Label lblLogonInfo;
        private System.Windows.Forms.Panel pnlLogonOptions;
        private System.Windows.Forms.RadioButton optSQL;
        private System.Windows.Forms.RadioButton optNT;
        private System.Windows.Forms.TextBox txtUID;
        private System.Windows.Forms.Label lblUser;
        private LangSoftDev.dotNETControls.InputControls.PasswordControl txtPW;
        private System.Windows.Forms.Label lblPassword;
        private System.Windows.Forms.Button cmdCancel;
        private System.Windows.Forms.Button cmdOK;
        private System.Windows.Forms.Button cmdTestConnection;
        private System.Windows.Forms.Label lblStatus;
    }
}


This is just one form, though. The behavior is the same for any other modally popped form in any other dotnet app. Maybe it's of interest that we (me and my collegue) both use Windows 7, although I had the problem on my Vista machine as well. I don't know if XP suffers from this behavior. Also we both have 64 bits machines; don't know if it occurs on x86 machines as well.....

Greetings,
Rick
 
I would suggest asking in the C/C# forum as you likely to get more answers than just those few who program for both. The only suggestion I can give is if it is setup like VB.NET some forms by default will allow the escape key to act as a cancel. You might make sure that option isn't turned on just to see if maybe some how that is being sent to the form. Does it do it when you are in debug mode? If so break on the Form Close/Closing events and see what arguments are being sent to the event.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Hi Sorwen thanks for your reply. I thoght about posting it in c# as well, but it isnt really c# related and didn't wnat to cross post. VB behaves exactly the same, it's just that currently I'm working on a c# app that the example code is c#...

Anyway:
Yes, it's setup to do a close on cancel, but I had already tried without as well... same problem.

the problem occures both in debug as well as in release and the arguments being passed to the Closing event is "CloseReason=None"; the Close event doesn't fire, only the Closing event fires (or at least my debugger doesn't halt on the Close event....).

Greetings,
Rick
 
I don't know that you can do this or that it will fix your problem, but in VB you could setup a variable and have that set in the close button when clicked. Then in the FormClosing you check if the variable is set if it isn't then you can do e.Cancel = True this prevents the form closing. If it still closes then the button is some how pressed. You might try changing the focus to the from any time the button doesn't have focus as in some way it could be pressed. If that doesn't work I'm out of ideas.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Yeah, I thought about such "crappy" workarounds as well, but it is a hell of a lot of forms you need to attack with that, taking into acocunt that the form might be otherwise closed (such as in code) etc etc. Bottom line, I'm afraid, is that there's no real fix for this other than going back to VB6 or C++ and I'm really surprised that such basic stuff as showing a modal dialog isn't even working in dotnet...... :(

Greetings,
Rick
 
Dear Rick,
Sorry for the long silence.
I setup Actual Windows Manager (the latest demo version) on my Vista PC, create such Modal Form (in VB Net 2005) and did a test. Using the default setting of the Actual Windows Manager, I didn't find any problem in switching to any other Virtual windows.
Also, as Sorwen said, seeing VB codes is easier for us here. Please create a simple test application which has a modal dialog form, test it and see the result.

I would also suggest you see the setting of Actual Windows Manager in your machine. If it happens on every machine, well, I don't know what to say.

Regards.
 
Mansii thanks for going to all that trouble.

I recreated the problem a very basic VB app.

this is hte mainform, calling the popup:

Code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.cmd = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'cmd
        '
        Me.cmd.Location = New System.Drawing.Point(86, 139)
        Me.cmd.Name = "cmd"
        Me.cmd.Size = New System.Drawing.Size(75, 23)
        Me.cmd.TabIndex = 0
        Me.cmd.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(534, 349)
        Me.Controls.Add(Me.cmd)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents cmd As System.Windows.Forms.Button

End Class

Code:
Public Class Form1

    Private Sub cmd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd.Click
        Using dlg As New Form2()
            Form2.ShowDialog(Me)
        End Using
    End Sub
End Class

And this is the one being popped:

Code:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form2
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form2
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(284, 262)
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form2"
        Me.ShowInTaskbar = False
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
        Me.Text = "Form2"
        Me.ResumeLayout(False)

    End Sub
End Class

Code:
Public Class Form2

End Class

When I pop any non-dotnet window (ie notepade about box, ie settings etc) no problem at all when switching desktops. But modal dialogs of dotnet apps vanish. Not only my own, but for example also the about box of the SQL server 2005 management studio.

Greetings,
Rick
 
Code:
Public Class Form1

    Private Sub cmd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd.Click
        Using dlg As New Form2()
            [red]Form2[/red].ShowDialog(Me)
        End Using
    End Sub
End Class
That is a typo right? I'm not sure what is going on then if you are having the same problem. I would still suggest setting the button up the way I suggested just for the test. With the CloseReason=None that should mean that the call didn't come from clicking X some how nor windows requesting the window close as both should generate a reason. So in some other way either some how the key combination used to switch screens causing the window to think it is getting a close response or somehow the button is being "click" in some manner. At least that is the two most obvious possibilities.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Yep that' a typo indeed......

Anyway, the form in my vb test project doesn't have any buttons; it's an empty form doing nothing (except closing when I switch desktop.... :) )

Greetings,
Rick
 
For grins you could put it in a try. Also get rid of the using just for the test as sometimes you can get some unexpected things when dealing with errors and using.
Code:
    Public Class Form1

        Private Sub cmd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd.Click
            Try
                Dim dlg As New Form2
                
                If dlg.ShowDialog(Me) <> Windows.Forms.DialogResult.Retry then
                End If
            Catch ex As Exception
                Dim msg As String
                msg = ex.Message

                If ex.InnerException IsNot Nothing Then
                    msg &= " " & ex.InnerException.Message
                End If

                MsgBox(msg)
            End Try
        End Sub
    End Class
I don't really think you are going to get anything, but it is possible. I have had an error before that just wouldn't pop up. Thats all I can think of though if/when that comes up dry I'm not sure what else to suggest.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
It doesn't get in an error because if I put something like below, it does get to the next line of code. Indeed it is cancelled, the question is why......

Code:
if dlg.ShowModal(me)=DialogResult.Cancel then
    'it will get to this line of code
end if



Greetings,
Rick
 
But modal dialogs of dotnet apps vanish. Not only my own, but for example also the about box of the SQL server 2005 management studio.

Strange. I did a test without any problem. Wouldn't you think that it is a compatibility problem?
 
But with what? I mean, I have Actual Window Tools, my collegue has another virtual desktop manager (of which I don't know the name). This problem exists on 3 entirely different pc's, two being windows 7 and one windows vista; two being mine (which you could argue have the same software installed) and the other being the one of my collegue (which is a completely different install). The only thing they all have in common (and which I'm starting to think might be the problem) is that they are 64 bits OSes (or is your system a 64 bits OS as well?)

Greetings,
Rick
 
Unfortunately, I have a 32 bits machine. Yeah, this might be the cause. Not so sure. Sorry, Rick.

Regards.
 
No problem..... thanks for going through so much trouble anyway!

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top