Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / December 2005

Tip: Looking for answers? Try searching our database.

Starting A form hidden

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AJPlonka - 05 Dec 2005 22:07 GMT
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
Stacey - 05 Dec 2005 22:29 GMT
What is the windowstate on the form itself.  Why would you want to start
with it hidden?
> Can anyone tell me why this doesn't start hidden?
>
[quoted text clipped - 26 lines]
> End Sub
> End Class
Armin Zingler - 05 Dec 2005 22:33 GMT
> 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
cbrown@duclaw.com - 05 Dec 2005 23:51 GMT
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.
AJPlonka - 06 Dec 2005 23:08 GMT
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!
AJPlonka - 06 Dec 2005 23:39 GMT
> 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.
AJPlonka - 07 Dec 2005 17:34 GMT
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.

> > 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.
AJPlonka - 06 Dec 2005 22:57 GMT
>>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.
Armin Zingler - 07 Dec 2005 00:08 GMT
> > > Unless you've got a NotifyIcon or a Timer.
>
[quoted text clipped - 3 lines]
> 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
AJPlonka - 07 Dec 2005 06:43 GMT
> > I want single stand-alone executable- no dlls.
>
[quoted text clipped - 3 lines]
> 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
[quoted text clipped - 17 lines]
>
>    End Sub
Cor Ligthert [MVP] - 07 Dec 2005 07:16 GMT
AJ,

>> > I want single stand-alone executable- no dlls.
>>
[quoted text clipped - 11 lines]
> 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.
AJPlonka - 07 Dec 2005 17:28 GMT
And I would be using vb to do this because...

> AJ,
>
[quoted text clipped - 24 lines]
>
> Cor.
Armin Zingler - 07 Dec 2005 10:28 GMT
> > > I want single stand-alone executable- no dlls.
> >
[quoted text clipped - 15 lines]
> 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?
[quoted text clipped - 4 lines]
> 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
AJPlonka - 07 Dec 2005 17:25 GMT
> 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.
Armin Zingler - 07 Dec 2005 18:52 GMT
> > silliness. Apart from this, I don't see the relation to your
> > actual problem, but never mind.
[quoted text clipped - 8 lines]
> 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
tomb - 06 Dec 2005 03:03 GMT
You can add one line in sub New()
See below

>Can anyone tell me why this doesn't start hidden?
>
[quoted text clipped - 4 lines]
>        InitializeComponent()
>  

me.hide

>    End Sub
>    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
[quoted text clipped - 21 lines]
>
>  
AJPlonka - 06 Dec 2005 23:19 GMT
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.