Starting A form hidden

G

Guest

Can anyone tell me why this doesn't start hidden?

Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
Private Sub InitializeComponent()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
Public Shared Sub Main()
Dim myForm As New Form1
myForm.Visible = False
System.Windows.Forms.Application.Run(myForm)
Return
End Sub
End Class
 
S

Stacey

What is the windowstate on the form itself. Why would you want to start
with it hidden?
 
A

Armin Zingler

AJPlonka said:
Can anyone tell me why this doesn't start hidden?
[...]
System.Windows.Forms.Application.Run(myForm)

Run shows the Form. It wouldn't make sense not to show it because this
overloaded version of Run returns as soon as the Form is closed, therefore
it would return immediatelly. If you don't want to start with a startup
form, use Application.Run(). But when do you intend to show the form? There
is no user interface enabling the user to show it. The app would run in the
background without doing anything. Unless you've got a NotifyIcon or a
Timer.

This return is not necessary


Armin
 
C

cbrown

You could always set the forms opacity to 0.

Dim Form1 As New Form1
Form1.opacity = 0
Form1.Show()

I use this in a biometric timeclock app I wrote.

When you show the form all you have to do is bring the opacity back to
100, you can even use a loop to make it fade-in.
 
G

Guest

Unless you've got a NotifyIcon or a Timer.

Those are just two reasons someone would want to start a form hidden. I can
think of a few more... In my case it is a form that loads directly into the
minimized to the tray. How else would you suggest I use application.run? I
tried it in seperate module with the same results. I want single stand-alone
executable- no dlls.
It's useful for setting breakpoints. I forgot to clean it out of the post.
 
G

Guest

That's a functional workaround. I simply start the form minimized with
showintaskbar false. But that's not what I want to know. I'd like to be able
to simply toggle visible on and off, since opacity and windowstate have other
uses, but I don't see a way of starting a form with visible=false!
 
G

Guest

You can add one line in sub New()

That's a reasonable assumption. Are you using 2005? I haven't had time to
install it yet. It doesn't hide anything on my installation of 2003.
 
G

Guest

That's a functional workaround.

Though as I think about it, wouldn't a transparent (as opposed to hidden)
form still respond to mouseclicks and keystrokes? But I suppose it would
suffice for loading purposes.
 
A

Armin Zingler

AJPlonka said:
Those are just two reasons someone would want to start a form
hidden. I can think of a few more... In my case it is a form that
loads directly into the minimized to the tray. How else would you
suggest I use application.run? I tried it in seperate module with
the same results.

Post some code.
I want single stand-alone executable- no dlls.

Then you have to write your own just-in-time compiler, your own managed
execution environment, your own memory management - and do not even declare
an Integer variable because the type is located in mscorlib.dll which is
part of the Framework that is, for the reasons mentioned, the minimum
requirement for every .Net application.


Back to your question... I copied some parts of a real-world app. Does this
help?


Private Shared WithEvents NI As NotifyIcon
Private Shared MainForm As Form1

Shared Sub main()

NI = New NotifyIcon

Try
NI.Visible = True

Try
MainForm = New Form1
Application.Run()
Finally
NI.Visible = False
End Try
Finally
NI.Dispose()
End Try

End Sub

Private Shared Sub NI_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NI.DoubleClick
ShowOrActivateForm()
End Sub

Private Shared Sub ShowOrActivateForm()
If MainForm.Visible Then
MainForm.Activate()
Else
MainForm.Show()
End If
End Sub



Armin
 
G

Guest

I want single stand-alone executable- no dlls.
Then you have to write your own just-in-time compiler, your own managed
execution environment, your own memory management - and do not even declare
an Integer variable because the type is located in mscorlib.dll which is
part of the Framework that is, for the reasons mentioned, the minimum
requirement for every .Net application.

That's just silliness. By that reasoning, you made assumptions about my
operating system. And what about the bootstrap loader? Heck, if JAVA apps can
be referred to as standalone outside of a browser I think it's perfectly
reasonable to call a .NET executable without distributed DLLs "standalone."

If you run an application, you assume it to be in context, be it framework,
VM, or OS. But, to be clear: I meant a single executable file for
distribution to clients with .Net installed.


Back to your question... I copied some parts of a real-world app. Does this
help?
I already have a real-world solution: I delegated the task. What I am
interested in is the underlying theory.

Maybe I should have titled the thread "Loading a form hidden." I want the
form to load and be active. Invisibly. There are timer events and message
monitors, etc, that I want to be up and processing.

Try statements are kludgy at best. This code was helpful, though because it
helped me see my stupid mistake (I included the object as a parameter to the
run statement)
 
C

Cor Ligthert [MVP]

AJ,
That's just silliness. By that reasoning, you made assumptions about my
operating system. And what about the bootstrap loader? Heck, if JAVA apps
can
be referred to as standalone outside of a browser I think it's perfectly
reasonable to call a .NET executable without distributed DLLs
"standalone."
No Armin gave you the exact answer if you want to use the Net development
enviroment, withouth completely all parts of the framework.

If you want to do it in another development way, you have even much more
posibilities than you wrote, however not always with the same results as you
have with the Net development environment.

Just my thought,

Cor.
 
A

Armin Zingler

AJPlonka said:
That's just silliness. By that reasoning, you made assumptions about
my operating system. And what about the bootstrap loader? Heck, if
JAVA apps can be referred to as standalone outside of a browser I
think it's perfectly reasonable to call a .NET executable without
distributed DLLs "standalone."

If you run an application, you assume it to be in context, be it
framework, VM, or OS. But, to be clear: I meant a single executable
file for
distribution to clients with .Net installed.

Sorry guy, I didn't know your skills before. Some people really think "no
dlls" means "no dlls". If you follow dotnet groups, this is not a rare
question. Otherwise I wouldn't have mentioned this, therefore it's not
silliness. Apart from this, I don't see the relation to your actual problem,
but never mind.
I already have a real-world solution: I delegated the task. What I
am interested in is the underlying theory.

Maybe I should have titled the thread "Loading a form hidden." I
want the form to load and be active. Invisibly.

"That's just silliness". An invisible Form can never be active. "Active" is
a term concerning the focus of a window. I've had a hard time trying to
focus an invisible window...
There are timer
events and message monitors, etc, that I want to be up and
processing.

Only a hint, if it's permitted: You do not necessarily need Form to use a
(Windows.Forms.)Timer
Try statements are kludgy at best. This code was helpful, though
because it helped me see my stupid mistake (I included the object as
a parameter to the run statement)

Glad to have helped you.


Armin
 
G

Guest

silliness. Apart from this, I don't see the relation to your actual problem,
but never mind.
I was thinking that perhaps embedding the form in a dll and then calling it
might work. You're right, it was an off-track comment.
"That's just silliness". An invisible Form can never be active. "Active" is
a term concerning the focus of a window. I've had a hard time trying to
focus an invisible window...
I realize I'm tripping up on my own semantics. For me, "standalone" means
compiling with bcom instead of brun. And I still call an audio CD is an
"album." Oh well. I should have said "load and processing events." But your
comment surprised me. I checked and, sure enough, take a form below 2%
opacity and it simply stops responding to the interface. So how to build
hotspot overlays? Sorry, I'm digressing...
Only a hint, if it's permitted: You do not necessarily need Form to use a
(Windows.Forms.)Timer
I may follow up on that. I just find using the designer an easier way of
keeping track of my code.
Glad to have helped you.
It helped to confirm that there's no straigtforward up-front way of
configuring a form to do what I was asking. It seems like simple enough
requirement: Load invisibly and process events. Thanks, I do appreciate your
time given to this.
 
G

Guest

And I would be using vb to do this because...

Cor Ligthert said:
AJ,

No Armin gave you the exact answer if you want to use the Net development
enviroment, withouth completely all parts of the framework.

If you want to do it in another development way, you have even much more
posibilities than you wrote, however not always with the same results as you
have with the Net development environment.

Just my thought,

Cor.
 
G

Guest

It doesn't! That suprised me. Your workaround is better than mine because
sometimes the app loads before the taskbar fully initializes on bootup,
leaving an ungainly minimized form. Thanks.
 
A

Armin Zingler

AJPlonka said:
I was thinking that perhaps embedding the form in a dll and then
calling it might work. You're right, it was an off-track comment.
I realize I'm tripping up on my own semantics. For me, "standalone"
means compiling with bcom instead of brun.

You mean D:\DOS\Qb4\BCOM41.LIB? ;-)
It helped to confirm that there's no straigtforward up-front way of
configuring a form to do what I was asking. It seems like simple
enough requirement: Load invisibly and process events. Thanks, I do
appreciate your time given to this.

Sorry, I still don't see the problem. If you create the Form, the contained
timer will run even if you don't show the Form. Therefore you do have an
invisible Form and events are processed (that's what application.run is
for). Why is this not straightforward?


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top