473,804 Members | 3,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ShowDialog

Hi All,

I'm having a problem displaying a form as a modal dialog
window, when I call the code below from one part of my
program (a right-click menu) it works fine, but when I
call it from within another Sub, the new form displays
but I can click back to the main form so the dialog
window no longer has the focus.

Here is the code I am using, does anyone know why this
would happen?

Dim fAbout As frmAbout = New frmAbout()
fAbout.ShowDial og()
fAbout.Dispose( )

Thanks,
Steve
Nov 20 '05 #1
6 2683
"Steve" <ms**@zuna.co.u k> schrieb
I'm having a problem displaying a form as a modal dialog
window, when I call the code below from one part of my
program (a right-click menu) it works fine, but when I
call it from within another Sub, the new form displays
but I can click back to the main form so the dialog
window no longer has the focus.

Here is the code I am using, does anyone know why this
would happen?

Dim fAbout As frmAbout = New frmAbout()
fAbout.ShowDial og()
fAbout.Dispose( )


You should call Close instead of Dispose. Otherwise events like Closing or
Closed don't fire. Dispose is automatically called as an reaction on the
Form being closed.

Back to your problem: I can't reproduce it. Do you show the modal form in a
different thread?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "Steve" <ms**@zuna.co.u k> scripsit:
I'm having a problem displaying a form as a modal dialog
window, when I call the code below from one part of my
program (a right-click menu) it works fine, but when I
call it from within another Sub, the new form displays
but I can click back to the main form so the dialog
window no longer has the focus.

Here is the code I am using, does anyone know why this
would happen?

Dim fAbout As frmAbout = New frmAbout()
fAbout.ShowDial og()
fAbout.Dispose( )


Dispose doesn't make sense here. The form will be disposed
automatically. What exactly do you mayn by "within another Sub"? Are
you showing the form in a different thread (that's not recommended!).

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

The dialog is displayed incorrectly from a subroutine
that is envoked as the result of a barcode scanner
sending data to a serial port, which I guess could be on
a different thread to the main program?

Is there a way of getting the main form thread to display
this dialog window instead?

Steve
-----Original Message-----
* "Steve" <ms**@zuna.co.u k> scripsit:
I'm having a problem displaying a form as a modal dialog window, when I call the code below from one part of my
program (a right-click menu) it works fine, but when I
call it from within another Sub, the new form displays
but I can click back to the main form so the dialog
window no longer has the focus.

Here is the code I am using, does anyone know why this
would happen?

Dim fAbout As frmAbout = New frmAbout()
fAbout.ShowDial og()
fAbout.Dispose( )
Dispose doesn't make sense here. The form will be

disposedautomaticall y. What exactly do you mayn by "within another Sub"? Areyou showing the form in a different thread (that's not recommended!).
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
.

Nov 20 '05 #4
"Steve" <an*******@disc ussions.microso ft.com> schrieb

The dialog is displayed incorrectly from a subroutine
that is envoked as the result of a barcode scanner
sending data to a serial port, which I guess could be on
a different thread to the main program?

Is there a way of getting the main form thread to display
this dialog window instead?

"I guess could be on a different thread".. I'd say you should confirm this
first. I assume this is the only reason why the app behaves like it does, so
you should marshal showing the modal Form to the main UI thread in order to
make it modal for the whole app (assuming there should only be one UI
thread). You can show it in the main thread by calling a procedure using the
Invoke or BeginInvoke methods of any control (inclduing Form) created in the
main thread. You can pass a Delegate pointing to the procedure to be called
to the Invoke/BeginInvoke methods. The procedure will be executed in the
other thread. The MethodInvoker Delegate might be useful in this context.
There you can modally show the Form. But first, as I said, you should make
sure that it is currently really shown in a new thread, e.g. by having a
look at the thread windows.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #5
"I guess could be on a different thread".. I'd say you should confirm thisfirst. I assume this is the only reason why the app behaves like it does, soyou should marshal showing the modal Form to the main UI thread in order tomake it modal for the whole app (assuming there should only be one UIthread). You can show it in the main thread by calling a procedure using theInvoke or BeginInvoke methods of any control (inclduing Form) created in themain thread. You can pass a Delegate pointing to the procedure to be calledto the Invoke/BeginInvoke methods. The procedure will be executed in theother thread. The MethodInvoker Delegate might be useful in this context.There you can modally show the Form. But first, as I said, you should makesure that it is currently really shown in a new thread, e.g. by having alook at the thread windows.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

.


Thanks Armin, I got it working from you reply.

The window obviously was being displayed in a different
thread to the main UI, so I just added the following
delegate to the form:

Private Delegate Sub DisplayDialog(B yVal sMessage As
String)

And then I could call this with BeginInvoke:

Dim myArgs(0) As String
myArgs(0) = "The carton could not be found in the data
file"
Dim ar1 As IAsyncResult = BeginInvoke(New DisplayDialog
(AddressOf DisplayMessage) , myArgs)

Steve
Nov 20 '05 #6
<an*******@disc ussions.microso ft.com> schrieb
Thanks Armin, I got it working from you reply.

The window obviously was being displayed in a different
thread to the main UI, so I just added the following
delegate to the form:

Private Delegate Sub DisplayDialog(B yVal sMessage As
String)

And then I could call this with BeginInvoke:

Dim myArgs(0) As String
myArgs(0) = "The carton could not be found in the data
file"
Dim ar1 As IAsyncResult = BeginInvoke(New DisplayDialog
(AddressOf DisplayMessage) , myArgs)

Thx for your feedabck. Code looks good. Glad I could help you.
--
Armin

Nov 20 '05 #7

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

Similar topics

3
3672
by: Richard L Rosenheim | last post by:
I would like to detect when a form is invoked as the result of a ShowDialog call. Anyone have any ideas or suggestions on how to do that? TIA, Richard Rosenheim
2
10206
by: Bill Burris | last post by:
When you crate a Windows application the wizard adds a line like: Application.Run( new MyMainForm() ); Out of curiosity I replaced this with: MyMainForm myForm = new MyMainForm(); myForm.ShowDialog(); and run the application with no problem.
5
1596
by: Josh Golden | last post by:
3 forms. form 1, when button clicked instantiates form 2 which opens but is not shown. form 2 instantiates form 3 as showdialog. form 3 finishes, raises an event that form 2 catches. during the catch, form 2 closes and disposes the instance of form 3, opens itself as showdialog, and displays some data to the user. the user can select one of these data and upon doing so raises an event that form 1 catches (and closes and disposes of...
4
4397
by: Dennis Sjogren | last post by:
Greetings! First, I'm not 100% sure where to post this question. I use VB.NET for this project, but it's really a design question (a question on which method to use when solving this problem). In this medium sized (30 or so forms) application, our users have requested a more visual notification of when the client (this app) is communicating with the server, or for other lenghty processes. Disabling the current form and changing the...
6
4906
by: Samuel R. Neff | last post by:
I'm having weird results with a form that is already displayed modally (via ShowDialog) displaying a second form via ShowDialog. The last form is not modal even though it's called with ShowDialog. For example, given three forms: Startup Pop1 Pop2
1
2448
by: No Sheds | last post by:
Hi I have an MDI application. I have a MDI child window within this application that shows another form using ShowDialog. This works fine, except that the final form shown with ShowDialog can't be an MDI child window, and so can appear outside the boundaries of the main window. I know I can do something like this: private withevents FinalForm as someform
4
5230
by: trialproduct2004 | last post by:
Hi all I am new to vb.net application. I am using showdialog property of form to display form. First time it is working properly. But next time it is giving me error that ' object reference not set to an instance of an object'. When i went through stacktrace, i found that it is giving error in showwindow. I am not getting why it is happening.
8
5128
by: WvH | last post by:
Hi, When I create a new application, with just one button, then this code works as expected: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim f As New ColorDialog f.ShowDialog() End Sub
2
3067
by: **Developer** | last post by:
I have a little more info about this problem I can't seem to solve! I know it'll take a minute to study the lising but if you like to sove puzzles there is one there. I have a Form (FV&C) containing a userconrtrol (CF&E) I do a ShowDialog for the form and the form's Load event calls a method of the UserControl.
5
10911
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I have a form that has a button. ( this form is a child form of a parent form ( main form ). Anway...in this child form I have a button, and if clicked a bunch of code will get executed. I would like to show a Progress Bar / form in modal/ShowDialog...
0
9707
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
10586
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
10082
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...
0
9161
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...
0
6856
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
5525
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...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2997
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.