Results 1 to 13 of 13

Thread: Showing Forms In A Specific Way Dilemma [RESOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53

    Showing Forms In A Specific Way Dilemma [RESOLVED]

    I have searched first and not found anything that matches what I'm after.

    I'm doing the usual:
    Click button on Form1 and show Form2
    Click button on Form2 and back to Form1

    That's all OK, trouble is, the controls and pictures and infact all the form does a quick sort of flicker when changing forms, yuk, now I have found away around it, which I have to do, but it's causing me some grief.

    So initially what's happening is this:

    Button clicked/form1 hide/form2 shown (showdialog)
    Button clicked/form2 hide(disposed)/form1 shown

    It's this gap from hide to show that's causing the flicker.

    What I need is this:

    Button (form1) clicked/form2 shown/form1 then hidden
    Button (form2) clicked/form1 shown/form2 then hidden/disposed

    Now I've done this and it looks much much better, just what I want, trouble is, lol, I get an extra form1 on the taskbar evertime I do it.

    Does anyone know how to do what I'm after, remember it needs to do this:

    Form1: Button Clicked - Form2 Shown - Form1 Hidden
    Form2: Button Clicked - Form1 Shown - Form2 Hidden/Disposed

    Thanks for anyones help.
    Last edited by JustAProg; Apr 18th, 2003 at 12:28 PM.

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Forms expose a .ShowInTaskbar property that you can modify at runtime.
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsformclassshowintaskbartopic.htm

    so you could set form 2 to not show in taskbar, show the second form, then hide the first form, then set form 2 to show in taskbar.

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Trying this (in form1) I noticed no flicker.
    VB Code:
    1. Dim frm as New From2
    2. Me.Hide
    3. frm.Showdialog
    4. Me.Show

    You may also try this to hide form1 when form2 is loaded.

    So you put this in form2
    VB Code:
    1. Dim frm As Form
    2. #Region " Windows Form Designer generated code "
    3.  
    4.     Public Sub New(ByVal frm) 'ByVal frm As Form)
    5.  
    6.         MyBase.New()
    7.         Me.frm = frm
    8.         'This call is required by the Windows Form Designer.
    9.         InitializeComponent()
    10.  
    11.         'Add any initialization after the InitializeComponent() call
    12.  
    13. End Sub
    14.  
    15.  Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    16.         frm.Hide()
    17.  
    18. End Sub

    and this in form1

    VB Code:
    1. Dim frm as New From2(Me)
    2. frm.Showdialog
    3. Me.Show

    so you could set form 2 to not show in taskbar, show the second form, then hide the first form, then set form 2 to show in taskbar.
    the problem is not showing in taks bar. The problem is he is producing a new form1 in his code.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Ah ha!

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    The first one is what I usually use, I just tried again, it has horrendous flicker, only when going to form 2 though, not back.

    The last one gave me errors:
    Dim frm As New Form2(me)

    It wouldn't except the 'me'

    I changed it to Dim frm As New Form2, ran it, then gave me a 'object/instance' error at the frm.hide in form2

  6. #6

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    For instance, this is the closest I've come:

    In Form1 Button:
    Code:
        Dim Form2 As New Form2
        Form2.Show()
        Me.Hide()
    In Form2 Button:
    Code:
        Dim Form1 As New Form1
        Form1.Show()
        Me.Close()
    Now this actually works perfect, you dont see one form dissapear briefly before the other gets displayed, it's all smooth, as you would expect because a form is shown before the other hides.

    Trouble is, even though I can't see them I must be making multiple form 1's everytime I display it as the prog wont then shut down and I have to use the 'STOP' in the IDE.

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    The last one gave me errors:
    Dim frm As New Form2(me)

    It wouldn't except the 'me'
    it means that you have not made the required changes in form2.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    Yes you're right, I'd forgot the '(ByVal frm)'. Unfortunetly though it still didn't work, just done the same as the original method. I can still see the half a second or so of 'nothing' whilst one form dissapears before the other is drawn.

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You may also try this:

    Instead of hiding the form1 in load event of form2
    try to hide it in activated event:
    VB Code:
    1. Private Sub Form2_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
    2.         Static isactive As Boolean
    3.         If Not isactive Then
    4.             frm.Hide()
    5.             isactive = True
    6.         End If
    7. End Sub
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    Hi again.

    That is sort of actually working. I now get a nice transistion to form2, but form2 only, still get the problem going back to form1.

  11. #11
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Actually i dont know if it makes any difference or not(i dont guess so), however try showing form1 in close event of form2.
    VB Code:
    1. Private Sub Form2_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    2.         frm.Show()
    3. End Sub
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  12. #12

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    You genius, now that seems to work, can't mess too much at the moment, will later, I'll let ya know.

  13. #13

    Thread Starter
    Member
    Join Date
    Sep 2002
    Posts
    53
    Yep, that does it, cool.

    Cheers mate, it was really getting to me that one.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width