473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

.Show() on Form object.

MV
Why can't I run .Show() on a System.Windows.Forms object
from a Class? The code works fine if i run it from an
other form.

The form gets visible but no controls are loaded and the
mouse pointer is an hourglass.

..ShowDialog() works fine.
Nov 20 '05 #1
8 6428
Did you use the NEW keyword?
Tom
--
==========================================
= Tom Vande Stouwe MCSD.net, MCAD.net, MCP
= 45Wallstreet.com (www.45wallstreet.com)
= (803)-345-5001
==========================================
= If you are not making any mistakes
..= ..you are not trying hard enough.
==========================================
"MV" <do****@stockholmitservice.se> wrote in message
news:01****************************@phx.gbl...
Why can't I run .Show() on a System.Windows.Forms object
from a Class? The code works fine if i run it from an
other form.

The form gets visible but no controls are loaded and the
mouse pointer is an hourglass.

.ShowDialog() works fine.

Nov 20 '05 #2
Hello,

"MV" <do****@stockholmitservice.se> schrieb:
Why can't I run .Show() on a System.Windows.Forms object
from a Class? The code works fine if i run it from an
other form.

The form gets visible but no controls are loaded and the
mouse pointer is an hourglass.

.ShowDialog() works fine.


Windows version?
Framework version?

Are you sure, the application has a message loop? How do you show the first
form?

Post some code.

Regards,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #3
MV
This is the case:

My .NET application has a form as Startup Object.

My .NET application opens a Access .adp file and sends an
object to it so it can communicate with my .NET
application.

The Access file calls a sub in the .NET application to
open a form.

If the sub tries to open the form with .Show() it doesn't
work.

My resolution is to open the form with .ShowDialog() in a
thread. This works fine but why cant I just use .Show()?

Example code to open the form with a thread:

'***Open form as a thread
Public sub subOpenForm(ByVal oFormToOpen As
System.Windows.Forms)
Dim oOpenForm As clsOpenForm
Dim tOpenForm As Thread

oOpenForm = New clsOpenForm(oFormToOpen)

tOpenForm = New Thread(AddressOf
oOpenForm.subOpenForm)
tOpenForm.Start()
End Function

Private Class clsOpenForm
Private m_oFormToOpen As System.Windows.Forms =
Nothing

Public Sub New(ByRef oFormToOpen As
System.Windows.Forms)
m_oFormToOpen = oFormToOpen
End Sub

Public Sub subOpenForm()
m_oFormToOpen.ShowDialog()
End Sub
End Class

-----Original Message-----
Why can't I run .Show() on a System.Windows.Forms object
from a Class? The code works fine if i run it from an
other form.

The form gets visible but no controls are loaded and the
mouse pointer is an hourglass.

..ShowDialog() works fine.
.

Nov 20 '05 #4
"MV" <do****@stockholmitservice.se> schrieb
This is the case:

My .NET application has a form as Startup Object.

My .NET application opens a Access .adp file and sends an
object to it so it can communicate with my .NET
application.

The Access file calls a sub in the .NET application to
open a form.

If the sub tries to open the form with .Show() it doesn't
work.

My resolution is to open the form with .ShowDialog() in a
thread. This works fine but why cant I just use .Show()?


Becaue Show does not wait until the form is closed, consequently the sub
continues and the end of the thread's main procedure is reached => end of
thread => death of form
--
Armin

Nov 20 '05 #5
Hello,

"MV" <do****@stockholmitservice.se> schrieb im Newsbeitrag
news:0f****************************@phx.gbl...
This is the case:

My .NET application has a form as Startup Object.

My .NET application opens a Access .adp file and sends an
object to it so it can communicate with my .NET
application.

The Access file calls a sub in the .NET application to
open a form.

If the sub tries to open the form with .Show() it doesn't
work.

My resolution is to open the form with .ShowDialog() in a
thread. This works fine but why cant I just use .Show()?

Example code to open the form with a thread:


There are no commands to execute after calling Show, so the application
quits. Have a look at Application.Run and Application.ExitThread:

http://groups.google.de/groups?selm=...TNGP11.phx.gbl

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 20 '05 #6
MV
-----Original Message-----
Hello,

"MV" <do****@stockholmitservice.se> schrieb im Newsbeitrag
news:0f****************************@phx.gbl...
This is the case:

My .NET application has a form as Startup Object.

My .NET application opens a Access .adp file and sends an object to it so it can communicate with my .NET
application.

The Access file calls a sub in the .NET application to
open a form.

If the sub tries to open the form with .Show() it doesn't work.

My resolution is to open the form with .ShowDialog() in a thread. This works fine but why cant I just use .Show()?

Example code to open the form with a thread:
There are no commands to execute after calling Show, so

the applicationquits. Have a look at Application.Run and Application.ExitThread:
http://groups.google.de/groups?selm=u%23xQOutWDHA.2100% 40TK2MSFTNGP11.phx.gbl
HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet
.


....but the application is already running and a main form
is open.

The problem occurs when i try to open a new form from
Access.

This is the scenario:

*Application starts and open the main form.
*The application start Access and open a ADP-file.
*The application create an instance of my adp-facade
object (registered as a COM-component so Access can use
it).
*The application sends a reference to the adp-facade to
Access.
*Access run a sub in the adb-facade to open a form in
the .NET application. Here is the problem! The form does
not get painted and does not get activated properly.

If I run the same code in the adp-facade from the .NET
application it works fine.

Nov 20 '05 #7
"MV" <do****@stockholmitservice.se> schrieb
Becaue Show does not wait until the form is closed, consequently the sub
continues and the end of the thread's main procedure is

reached => end of
thread => death of form


...but i have declared the form object in the scope of the
class. Why should the form die when the sub that runs show
ends? The object with the reference to the form is still
alive.

A thread is the owner of a window. When the thread dies, all windows created
in the thread must be destroyed. It wouldn't make sense to keep the window
alive because only the thread creating the window is allowed to access it.
The form does not die. It just dont get painted and
activated correctly.

Examplecode:

Public Class Class1
Private oForm As Form2
Sub testShowForm()
oForm = New Form2
oForm.Show()
End Sub
End Class

You might still have a reference to the managed Form object, but the
associated window has been destroyed.

So, you have to show the Form modally, or call Application.Run(TheForm)
--
Armin

Nov 20 '05 #8
In addition:
Each thread has it's own message queue (if it becomes a UI thread). The
messages sent to a window (mouse clicks, key presses, ...) are put in the
message queue of the thread that created the window. Consequently, a window
can not exist anymore when it's owner thread is destroyed. Application.Run
and Form.Showdialog contain message loops that process this message queue
for the current thread. If there's no message loop, no messages are
processed.
--
Armin

Nov 20 '05 #9

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

Similar topics

13
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide...
2
by: Ajai Kumar .R | last post by:
Hai all, I've two or more forms on my app. My requirement is, Have to show the first form asa the user press a button have to hide the first form and show the second form. If the user press the...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
4
by: Haris Bogdanovic | last post by:
how do I refer to other form from main form so I can call its Show method ? Thanks Haris
3
by: Nathan | last post by:
I read an earlier post from Gary and answered by Peter Huang concerning closing one form and showing another. I need to do the same thing in my application, but the code Peter gave didn't work for...
7
by: Pi | last post by:
I have an MDI parent with one or more children forms. Each child form has an engine thread that processes data. The child form's _Closing event is roughly 01 Private Sub...
13
by: Tim Smallwood | last post by:
Hi, This is probably a stupid question, but I can't seem to get a form to show / load? In the older versions of VB I'd use frmMyform.show / load myForm, etc? I looked at the help file and it...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...

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.