.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching app at Me.Hide()

11 REPLIES 11
Reply
Message 1 of 12
hericson
926 Views, 11 Replies

Switching app at Me.Hide()

I start a dialog with dialogName.ShowDialog(). When I close the dialog I would like to display a message box before closing the dialog but I want to hide the dialog so the user don't see it under the message box. I use Me.Hide() for hiding the dialog but now the strange things happens. The dialog hides but switches to another open program and shows my message box on top of that application instead of AutoCAD! When I close the message box, AutoCAD will switch back. My question is why and what to do to prevent this from happening? I'm using VB.NET
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: hericson

It may be related to the how you're showing the dialog and,
if its modal or modeless, etc., but without seeing code it's
just a guessing game.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


wrote in message news:6212894@discussion.autodesk.com...
I start a dialog with dialogName.ShowDialog(). When I close the dialog I
would like to display a message box before closing the dialog but I want to
hide the dialog so the user don't see it under the message box. I use
Me.Hide() for hiding the dialog but now the strange things happens. The
dialog hides but switches to another open program and shows my message box
on top of that application instead of AutoCAD! When I close the message box,
AutoCAD will switch back. My question is why and what to do to prevent this
from happening? I'm using VB.NET
Message 3 of 12
hericson
in reply to: hericson

I have a command that opens the dialog (HETerr_Class.vb):


Option Explicit On

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Public Class HETerr_Class
_
Public Sub cmdOmHeterr()
Dim dialogOmHeterr As New dlgOmHeterr
dialogOmHeterr.ShowDialog()
End Sub
End Class


And then I have the code from the dialog (I have more than one button but I removed the code from those) (dlgSkapaTrianglar.vb):


Option Explicit On

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Imports System.Windows.Forms

Public Class dlgSkapaTrianglar

Private Sub ButtonTriangulera_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTriangulera.Click
Me.Hide()
MsgBox("my message")
Me.Close()
End Sub

End Class


I hope this makes sense.
Message 4 of 12
Anonymous
in reply to: hericson

Try the Application.ShowModalDialog() method rather
than Form.ShowDialog().

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


wrote in message news:6212923@discussion.autodesk.com...
I have a command that opens the dialog (HETerr_Class.vb):


Option Explicit On

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Public Class HETerr_Class
_
Public Sub cmdOmHeterr()
Dim dialogOmHeterr As New dlgOmHeterr
dialogOmHeterr.ShowDialog()
End Sub
End Class


And then I have the code from the dialog (I have more than one button but I
removed the code from those) (dlgSkapaTrianglar.vb):


Option Explicit On

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Runtime

Imports System.Windows.Forms

Public Class dlgSkapaTrianglar

Private Sub ButtonTriangulera_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ButtonTriangulera.Click
Me.Hide()
MsgBox("my message")
Me.Close()
End Sub

End Class


I hope this makes sense.
Message 5 of 12
hericson
in reply to: hericson

I tried the Application.ShowModalDialog() method but the switch remains and the message box will not even be active in this case. Active app is the app that showed up when hiding the dialog. If I switch back manually to AutoCAD I still don't see the message box in this case, I have to make another switch to that.

Form.ShowDialog() at least showed me the message box.

Any other ideas?
Message 6 of 12
Anonymous
in reply to: hericson

If calling System.Windows.Forms.Application.DoEvents() before
calling MessageBox.Show() doesn't work, then I would try moving
the call to MessageBox.Show() to the code that calls ShowDialog()
or ShowModalDialog(), like this:

Application.ShowModalDialog(myDialog);

if( condition )
{
System.Windows.Forms.Application.DoEvents();
System.Windows.Forms.MessageBox.Show(...);
}

Where 'condition' is the condition that determines if you need to
show the messagebox. You can access the form from the code
that calls it as well, if the condition depends on something in the
form.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


wrote in message news:6213056@discussion.autodesk.com...
I tried the Application.ShowModalDialog() method but the switch remains and
the message box will not even be active in this case. Active app is the app
that showed up when hiding the dialog. If I switch back manually to AutoCAD
I still don't see the message box in this case, I have to make another
switch to that.

Form.ShowDialog() at least showed me the message box.

Any other ideas?
Message 7 of 12
hericson
in reply to: hericson

I was thinking about your workaround as well as a last solution...
I think its strange this switch. It works well in VBA applikation and I thought VB.NET were a 'better' programming language.
Message 8 of 12
Anonymous
in reply to: hericson

'Better' does not mean easier to use, unfortunately.

The error occurs because the AutoCAD window is disabled while your dialog is
visible. The managed runtime watches for when your form is closed, and when
it does, it enables the AutoCAD window again.

Your code is calling MessageBox.Show() before that, which leads to the
problem, because the parent window of the message box must be enabled, and
AutoCAD's main window (which is the parent by default) is not enabled yet.

To solve the problem, do this just before calling MessageBox.Show():

{code}


Autodesk.AutoCAD.Internal.Utils.EnableFloatingWindows( True )

{code}

If you're using AutoCAD 2009 or earlier, you need to reference
AcMgdInternal.dll to call the above function.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


wrote in message news:6213173@discussion.autodesk.com...
I was thinking about your workaround as well as a last solution...
I think its strange this switch. It works well in VBA applikation and I
thought VB.NET were a 'better' programming language.
Message 9 of 12
Anonymous
in reply to: hericson

It still doesn't work for me. I'll go for the workaround mentioned earlier.


Tony Tanzillo wrote:
> 'Better' does not mean easier to use, unfortunately.
>
> The error occurs because the AutoCAD window is disabled while your dialog is
> visible. The managed runtime watches for when your form is closed, and when
> it does, it enables the AutoCAD window again.
>
> Your code is calling MessageBox.Show() before that, which leads to the
> problem, because the parent window of the message box must be enabled, and
> AutoCAD's main window (which is the parent by default) is not enabled yet.
>
> To solve the problem, do this just before calling MessageBox.Show():
>
> {code}
>
>
> Autodesk.AutoCAD.Internal.Utils.EnableFloatingWindows( True )
>
> {code}
>
> If you're using AutoCAD 2009 or earlier, you need to reference
> AcMgdInternal.dll to call the above function.
>
Message 10 of 12
Anonymous
in reply to: hericson

Try passing Application.MainWindow as the owner
parameter in MessageBox.Show().

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");


"Hericson" wrote in message
news:6214699@discussion.autodesk.com...
It still doesn't work for me. I'll go for the workaround mentioned earlier.


Tony Tanzillo wrote:
> 'Better' does not mean easier to use, unfortunately.
>
> The error occurs because the AutoCAD window is disabled while your dialog
> is
> visible. The managed runtime watches for when your form is closed, and
> when
> it does, it enables the AutoCAD window again.
>
> Your code is calling MessageBox.Show() before that, which leads to the
> problem, because the parent window of the message box must be enabled, and
> AutoCAD's main window (which is the parent by default) is not enabled yet.
>
> To solve the problem, do this just before calling MessageBox.Show():
>
> {code}
>
>
> Autodesk.AutoCAD.Internal.Utils.EnableFloatingWindows( True )
>
> {code}
>
> If you're using AutoCAD 2009 or earlier, you need to reference
> AcMgdInternal.dll to call the above function.
>
Message 11 of 12
hericson
in reply to: hericson

I got "Reference required to assembly 'PresentationCore xxx...' containing the implemented interface 'System.Windows.Interop.IWin32Window'. Add one to your project." errror when I enter Application.MainWindow as the owner parameter in MessageBox.Show().

If I click the button to the right of the underlined error and select the errormessage that shows up, it seems it will add the reference because the error disappears. But when debuging the code in AutoCAD it will cause an error in VB Express: "Unable to cast object of type 'Autodesk.AutoCAD.Windows.WindowOnHandle' to type 'System.Windows.Forms.IWin32Window'."

Any ideas what I have to do to get the right Application.MainWindow reference?
Message 12 of 12
Mikko
in reply to: hericson

Not sure if this is what you want or not but if
your using a WPF form I think you can collapse the
form then show the message box before the close if
this is what your talking about.


Me.Visibility = Windows.Visibility.Collapsed
MsgBox(txtbox1.Text)
Close()


A quick example I posted a bit ago.


http://discussion.autodesk.com/forums/thread.jspa?messageID=5969562ᚚ


here it is again with Me.Visibility = Windows.Visibility.Collapsed added.


Imports Autodesk.AutoCAD.Runtime


Public Class Class1


<CommandMethod("WPFsample")> Public Shared Sub WPFsample()
Dim wpffrm As New wpfCAD
wpffrm.ShowDialog()
wpffrm = Nothing
End Sub


End Class


====
====


Imports System
Imports System.Windows
Imports System.Windows.Controls


Public Class wpfCAD
Inherits Window


Public Shared Sub Main()
Dim app As Application = New Application()
app.Run(New wpfCAD())
End Sub


Private txtbox1 As TextBox


Public Sub New()
Title = "WPF acad sample"
Width = 400.0
Height = 80.0
Me.WindowStartupLocation = Windows.WindowStartupLocation.CenterScreen
Dim stack As StackPanel = New StackPanel()
Content = stack
Dim grid1 As Grid = New Grid()
grid1.Margin = New Thickness(3)
stack.Children.Add(grid1)
Dim rowdef As RowDefinition = New RowDefinition()
rowdef.Height = GridLength.Auto
grid1.RowDefinitions.Add(rowdef)
Dim lbl As Label = New Label()
lbl.Margin = New Thickness(5)
lbl.Content = "Enter something: "
lbl.VerticalContentAlignment = VerticalAlignment.Center
lbl.HorizontalAlignment = HorizontalAlignment.Left
lbl.Width = 150.0
grid1.Children.Add(lbl)
txtbox1 = New TextBox()
txtbox1.Margin = New Thickness(5)
txtbox1.Width = 150.0
txtbox1.VerticalContentAlignment = Windows.VerticalAlignment.Center
txtbox1.HorizontalAlignment = HorizontalAlignment.Center
txtbox1.Name = "TextBox1"
grid1.Children.Add(txtbox1)
Dim btn As Button = New Button()
btn.Margin = New Thickness(5)
btn.Content = "OK"
btn.HorizontalAlignment = HorizontalAlignment.Right
btn.Width = 75.0
btn.IsDefault = True
AddHandler btn.Click, New RoutedEventHandler(AddressOf OK_ButtonClick)
grid1.Children.Add(btn)
End Sub


Private Sub OK_ButtonClick(ByVal sender As Object, ByVal args As RoutedEventArgs)
Me.Visibility = Windows.Visibility.Collapsed
MsgBox(txtbox1.Text)
Close()
End Sub


End Class

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost