Results 1 to 22 of 22

Thread: Connecting two forms

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Connecting two forms

    Hi All

    Someone know?
    How to connect two forms - I want to connect one to second - because then it possible the moving a first Form together with a second Form. Similarly like in the Swedish Gimp

    I have something like this
    in Module
    Code:
    Option Explicit
    
    Public NewWidth As Long
    
    Public Sub CentreForm(F As Form)
    NewWidth = FrmMAIN.Width + Form2.Width
       F.Move (Screen.Width - NewWidth) \ 2, (Screen.Height - F.Height) \ 2
    End Sub
    Public Sub ReturnCentreForm(F As Form)
       F.Move (Screen.Width - F.Width) \ 2, (Screen.Height - F.Height) \ 2
    End Sub
    In FormMAIN for Picture1 and Picture4 (arrows)

    Code:
    Private Sub Picture1_Click()
    Form2.Hide
    ReturnCentreForm FrmMAIN
    Picture3.Visible = True
    Picture2.Visible = False
    End Sub
    
    Private Sub Picture4_Click()
    CentreForm FrmMAIN
    Form2.Show
    Picture2.Visible = True
    Picture3.Visible = False
    End Sub
    For Form2

    Code:
    Private Sub Form_Load()
    CentreForm FrmMAIN
    Form2.Left = FrmMAIN.Left + FrmMAIN.Width
    Form2.Top = FrmMAIN.Top
    Form2.Height = FrmMAIN.Height
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    ReturnCentreForm FrmMAIN
    With FrmMAIN
    .Picture3.Visible = True
    .Picture2.Visible = False
    End With
    End Sub
    All works nicely, it lacks me this keeping only

    thanks in advance
    I know, I know, my English is bad, sorry .....

  2. #2

  3. #3
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Talking Re: Connecting two forms

    Hai,

    Check this thread as well, Even though a Transperant issue, it ended by moving 2 forms to geter.

    http://www.vbforums.com/showthread.p...56#post2897056
    Last edited by Fazi; Jun 4th, 2007 at 04:32 AM.

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    If you are making something like Winamp-style attached form, then I may have an easy solution for you. If your forms will ALWAYS move together when the 2nd one is shown, you can get by with only one form.
    Make the first form as big as the two would have been together, add the controls to it, and resize the form back to its original size.
    to "show the 2nd form", have a command button resize the form again and the 2nd group of controls will become visible again.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    solution 2: use a timer
    in the timer read the x and y of the first form, and set the 2nd form x and y based on it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Talking Re: Connecting two forms

    Quote Originally Posted by Lord Orwell
    solution 2: use a timer
    in the timer read the x and y of the first form, and set the 2nd form x and y based on it.
    Hai Load,

    #3 Also uses a timer

  7. #7

  8. #8
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Connecting two forms

    Thanks Rhino for the comment

  9. #9
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    Rhino is correct. But it is always dangerous to subclass in the IDE. Be sure to save each and every time before you run your project. One wrong code line will crash vb.
    As for flickering, Perhaps it would if you were refreshing the form display, like in the example given. For just moving, it doesn't do it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  10. #10
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Connecting two forms

    Do there any performance issues on putting the timer an interval of 1 ?

  11. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    Depends on how much code is in the timer event. For window updating alone i would say no. Just don't go nuts with timers. If you have a bunch of stuff that needs to run in the background put it all in the same timer.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  12. #12
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Connecting two forms

    Thanks Lord for the comment.

  13. #13
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Connecting two forms

    Quote Originally Posted by Lord Orwell
    ...But it is always dangerous to subclass in the IDE...
    Why is it dangerous? Hit the SAVE button before you run it or set that ("save before run") in your options.
    Subclassing is often the only option to overcome language limitation(s).

  14. #14
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    1. I use VB6. Where is that option at?
    2. If i break code adding a feature, how would i roll-back code that way?
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  15. #15
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    nevermind question #1. I found it.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  16. #16
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Connecting two forms

    1. I use VB6. Where is that option at?

    Go to Tools > Options > Environment (tab) and select option you like in the "When a program starts..." frame.

    2. If i break code adding a feature, how would i roll-back code that way?

    Use SourceSafe.

  17. #17
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Connecting two forms

    What is that SourceSafe really do?

  18. #18
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    I think it is like a version history of your code changes ala the way msword tracks document changes. I have never understood it though. I have no idea how to get code back out of it if i put it in there. And i don't know how to put code in it after i say "no" the first time.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Connecting two forms

    Quote Originally Posted by Lord Orwell
    it is always dangerous to subclass in the IDE. Be sure to save each and every time before you run your project. One wrong code line will crash vb.
    In Form_Load, debug.print a divide by 0. Trap the error (Error 11) and set a public variable to true. If the variable is true, don't subclass, and don't unhook the subclassing. That way, in the IDE there's no subclassing unless you're aware that you're commenting out that debug print, but in the compiled code you get subclassing.
    Code:
    Private Sub Form_Load()
    
      bDebug is false at this point
      On Error GoTo Error_Handler
      Debug.Print 1 / 0 'if this executes, we'll throw an error 11, so bDebug will be true
    
      If Not bDebug Then 'then we're not in the IDE or we commented out the above error
        'set up subclassing for scrolling the grid with the mousewheel
        '(set up whatever subclassing you need here)
        OldProcGrid = GetWindowLong(Me.hWnd, GWL_WNDPROC)
        SetWindowLong Me.hWnd, GWL_WNDPROC, AddressOf TWndProcMouseWheel
      End If
    
      'The rest of your code here
      On Error GoTo 0
    
    Exit Sub
    
    Error_Handler:
      If Err.Number = 11 Then
        bDebug = True  'bDebug is declared Public in a module
        Resume Next
      End If
      'The rest of your error handler here
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
      If Not bDebug Then
        SetWindowLong Me.hWnd, GWL_WNDPROC, OldProcGrid
      End If
    End Sub
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  20. #20

  21. #21
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Connecting two forms

    Quote Originally Posted by Al42
    In Form_Load, debug.print a divide by 0. Trap the error (Error 11) and set a public variable to true. If the variable is true, don't subclass, and don't unhook the subclassing. That way, in the IDE there's no subclassing unless you're aware that you're commenting out that debug print, but in the compiled code you get subclassing...
    How in world are you going to test your app? Compile and run?
    How about checking whether or not you're passing correct values right when it actually happend?
    I'm afraid I cannot accept that as a reasonable solution.

  22. #22
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Connecting two forms

    i agree wholeheartedly rhinobull. It is however a neat way to test if you are in the development environment. I would use getmodulefilename (perhaps) but of course if for some inane reason someone were to take it in their head to name all their applications vb6.exe then trial version .ocx would work. Hmm.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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