Form show unrequested

To get some experience using VBE, I converted a simple program I once made for myself(VB5). It's a birthday calendar, using a VB5 commandbutton for each day of the year, i found that VBE has great problems handling this many controls, it is slow, very slow and realy unworkable. Some where else in this forum I found that others with a lot of controls experience the same problems and there is no neat solution for it. In the mid 80's the basicinterpreter was quicker than this VBE with a machine that is 2000 times faster.

Another problem I have is that the main(start) form of the program shows up unrequested. In the load section of the (start)form I show another form from which I normally select whether I show the (start)form or not. The second form shows correct but then the (start)forms is displayed as wel without executing a .show statement anywhere, when I interrupt(breakpoint at the end of the Load_form) then the (start)form is not visible but its .visible flag is still set to true. Anyone outthere knows why this is happening and has a solution



Answer this question

Form show unrequested

  • donkaiser

    Yes, I know about the startup form, and it should load as well but it should not show untill I wanted it to. It ignores even me.hide or .visible = false statements. The only "dirty" solution I've found is to do a me.hide on the _activate event so it disappears again. Still I think it shouldn't show at all untill a me.show statement is executed.... any other sugestions 

    Below some simple code to show what I mean

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Visible = False

    Me.Timer1.Interval = 10000

    Me.Timer1.Enabled = True

    End Sub

     

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    Me.Visible = Not Me.Visible

    End Sub

    End Class

    This should show the forms after a delay of 10 seconds BUT the form shows immediatly WHY


  • GrimStoner

    Well done JOZZ - that did work...thanks.
  • GConst

    Well, there all ducttape solutions, but moving it off-screen might be the most elegant as also MicaD suggested, we'll wait for MS for visible = false to work again in the mean time, since ducttape solutions always cause problems later. or does John Hart(MS) know for sure it will stay this way.
  • Nick Gravelyn

    Well, thank you Franapoli for your tip but this does not work in VB, the mainform_load is executed and shows that form ALWAYS, the _PAINT event isn't activated when the form is displayed!!!!

    Hiding it immediatly is possible but it always flashes on the screen!

    Hoping MS comes up with a solution soon

    regards Wil


  • eagIe

    Yeah...I have the same problem with using Paint - it's just as ineffective as the Load event. Here's the solution I came up with...keep in mind there is still a minor blip on screen when the program first executes.

    I plan to do more investigating in the coming days to find a better way - for now this method (duct tape and all) is suitable. I know there will be a better way - my first idea is to use a component class and override the form_load event.

    To run this all you need to do is create a new windows form - Form1 - and throw a timer - Timer1 and a notifyicon - NotifyIcon1 on the form and this will work to "hide" Form1 quickly, show a sys tray icon and then execute the timer every 60 seconds.

    Public Class Form1

    Dim oLocPoint As System.Drawing.Point

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    oLocPoint = Me.Location

    Me.Location = New System.Drawing.Point(-1000, -1000)

    NotifyIcon1.Visible = True

    Timer1.Interval = 1

    Timer1.Enabled = True

    Timer1.Start()

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    'actual Timer will check every 60 seconds (interval is 60,000 milliseconds)

    Static x As Long

    Timer1.Stop()

    Timer1.Enabled = False

    If x = 0 Then

    Me.Location = oLocPoint

    Me.Visible = False

    x = 1

    Timer1.Interval = 60000

    Timer1.Enabled = True

    Timer1.Start()

    Else

    'Run Main Routine - This for me is a program that checks data every minute to determine what to do

    Timer1.Enabled = True

    Timer1.Start()

    End If

    End Sub

    End Class


  • Joe Rattz

    In the Solution Explorer, open MY PROJECT and click on the APPLICATION tab. There should be a combobox with the label: "STARTUP FORM". That's the one that shows when you open the program.

  • user__2006

    There is a slight change in the way forms behave in VB6 and VB 2005. Windows Forms in VB 2005 cannot be hidden during the form load event. One solution is to use a Sub Main as your start up object and only load the form when you’re ready to display it.



  • setareh

    I can think of a couple of simple things that might work.

    If you want the form to simply be minimized at start up then you can set the WindowState = Minimized at design time and when your timer fires simple reset it to normal.

    Another solution is just to change the location to be off the screen (for example -1000,-1000) and then set it to the desired location when the event fires.

    I hope that helps.



  • MagedSalah

    In C++ exploiting the Load method didn't work (it seems that after the Load call the form is made unhidden), so I used the Paint one and it worked. Unfortunately I still have the form flashing on start, before being hidden. I hope for a solution too...

    Bye,
    Frank


  • arikve

    Chilly

    I am just diving into the exact problem with a VB6 app that I am converting to VB2005. The code in VB6 did exactly what you showed...Hide Form, Notify System Tray Icon, Start Timer. The problem I have found in VB2005 is that the Form_Load will not allow a Me.Visible = False. The best solution I came up with was to set the initial Timer value to very small and in the Timer_Tick routine immediately hide the Form and set the timer Value to the appropriate value. The problem with this is that the "frmMain" shows like a blip on the screen at the initial run of the executable.

    This is at best a duct tape solution and wish myself to find a better way. If you have found a better solution or wish to discuss for sake of collaberation, please email me from my website - micahd.com - no joke - for spam reasons i just put in my URL with no www.


  • Brianedow

    I was wondering if John had noticed that to be my exact solution, even down to the coordinates...and yes chilly - it is duct tape, no doubt about it. I know there is a way - my honest thought is that MS wants to make it tougher for anyone less than expert to create spyware apps, etc and that this may not change. There is no way that the right solution wouldn't have leaked from Microsoft yet if they wanted developers using that method.
  • SalvaPatuel

    Thank you for your answer, starting in sub main is the way i had it done in VB5 and I moved sub main to the load event since vb2005 showed only forms as startup object. I found now that clearing the application_framework checkbox allows sub main again but this doesn't solve the problem since exiting sub main will terminate the program completely since no form is loaded and I see no way to load a form without showing it. The whole idea is to show an icon only in the taskbar, start some timer(can only be on a form) to take some action later or click on the taskbar_icon to do something, so how can this be done in vb2005 without showing any form to start with
  • rabidrobot

    Same problem here with VC++.

    I solved this (dirty) way:

    if(first_time_flag)
    {
    first_time_flag=
    false;
    Hide();
    }

    Executing that code upon the "Paint" event will cause the form to hide the first time it's painted.


  • Shady9399

    Ok, this is pretty easy.

    In the constructor for the form, put:

    Me.ShowInTaskbar = False
    Me.WindowState = FormWindowState.Minimized

    and there you go, you won't see the form when the program starts.


  • Form show unrequested