469,621 Members | 1,759 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

Starting A form hidden

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

Dec 5 '05 #1
16 1963
What is the windowstate on the form itself. Why would you want to start
with it hidden?
"AJPlonka" <AJ******@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
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

Dec 5 '05 #2
"AJPlonka" <AJ******@discussions.microsoft.com> schrieb
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.
Return
This return is not necessary
End Sub

Armin

Dec 5 '05 #3
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.

Dec 6 '05 #4
You can add one line in sub New()
See below

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

Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()

me.hide
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

Dec 6 '05 #5
>>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.
This return is not necessary

It's useful for setting breakpoints. I forgot to clean it out of the post.
Dec 6 '05 #6
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!

Dec 6 '05 #7
> You can add one line in sub New()
me. hide


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.
Dec 6 '05 #8
> 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.

Dec 6 '05 #9
"AJPlonka" <AJ******@discussions.microsoft.com> schrieb
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.


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

Dec 7 '05 #10
> > 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)

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

Dec 7 '05 #11
AJ,
> 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."

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.
Dec 7 '05 #12
"AJPlonka" <AJ******@discussions.microsoft.com> schrieb
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.


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.
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.


"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

Dec 7 '05 #13
> 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.
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...

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.

Dec 7 '05 #14
And I would be using vb to do this because...

"Cor Ligthert [MVP]" wrote:
AJ,
> 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."

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.

Dec 7 '05 #15
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.

"AJPlonka" wrote:
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.

Dec 7 '05 #16
"AJPlonka" <AJ******@discussions.microsoft.com> schrieb
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.
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...

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? ;-)
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.


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

Dec 7 '05 #17

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Terence Parker | last post: by
5 posts views Thread by Yang Li Ke | last post: by
1 post views Thread by Don Stefani | last post: by
11 posts views Thread by newbie | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.