7 Replies - 2131 Views - Last Post: 27 August 2013 - 05:11 AM Rate Topic: -----

#1 wayans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 13

move form inside splitcontainer panel

Posted 23 August 2013 - 09:48 PM

Dear All,
I have Form1 and SplitContainer1 with two panel inside the form. Splitcontainer1.Panel1 in left side and Splitcontainer1.Panel2 at right side. Then I put Form2 in left panel and Form3 in right panel . I would like both form move vertically when I move Form3 with mouse.
I have tried the code bellow (File attached).
When I run the code , Form3 move correctly as I need but no respond from Form2.
Please advice how to move Form2 with mouse move in Form3.
Thank you very much for any help and suggestions.

Regards,
Wayan

Public Class Form3
    Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer
    Dim mousey1 As Integer
Private Sub Form3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        drag = True
        'mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
        mousey1 = Windows.Forms.Cursor.Position.Y - Form2.Top
    End Sub
Private Sub Form3_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If drag Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Form2.Top = Windows.Forms.Cursor.Position.Y - mousey1
            'Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub
Private Sub Form3_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        drag = False
    End Sub
    
End Class


This post has been edited by andrewsw: 24 August 2013 - 03:24 AM
Reason for edit:: Corrected code tags


Is This A Good Question/Topic? 0
  • +

Replies To: move form inside splitcontainer panel

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: move form inside splitcontainer panel

Posted 24 August 2013 - 03:32 AM

Where does your reference to Form2 originate? If you haven't create a reference to the running instance of Form2 then Form2 just refers to the default static instance, not to the running instance that is shown on the left.

Dim frmLeft As Form2
frmLeft = .. some reference to the Form2 instance..


I am not sure just at the moment of the best way that this reference should be obtained, but I suppose you could reference it via the main, parent, form:

frmLeft = Me.FindForm.Controls("Form2")

This post has been edited by andrewsw: 24 August 2013 - 03:44 AM

Was This Post Helpful? 1
  • +
  • -

#3 wayans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 13

Re: move form inside splitcontainer panel

Posted 24 August 2013 - 10:25 AM

@andrewsw Thank you for your suggestion, that is what I am trying to find : the reference to the form in left panel from the form in right panel. I am in a few weeks trying VB Net, only use Ms. Access before. :helpsmilie:

This post has been edited by andrewsw: 24 August 2013 - 11:03 AM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: move form inside splitcontainer panel

Posted 24 August 2013 - 10:52 AM

Try this, although I haven't tested it myself:

At the top of the main form's class:
Public frmLeft As Form2

in Form2's Load event:
Me.FindForm.frmLeft = Me

(FindForm refers to the outer/parent form)
in your event-code above, for Form3, you can change Form2 to:
Me.FindForm.frmLeft

throughout.

There are more professional approaches, but I suspect this should work.

Ideally you would test in the Form3 events whether frmLeft Is Nothing but I suspect at this stage you are probably just interested in seeing it working.

This post has been edited by andrewsw: 24 August 2013 - 11:01 AM

Was This Post Helpful? 0
  • +
  • -

#5 wayans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 13

Re: move form inside splitcontainer panel

Posted 24 August 2013 - 07:30 PM

First I type the code in Form1 Load event :
Public frmLeft As Form2


No error message.
When I put the code in Form2_Load event:

Me.Findform.FrmLeft = Me


I got this error :
Error 1 'frmLeft' is not a member of 'System.Windows.Forms.Form'.

Then when I continue to type the code for Form3 event , I got further error message :

Quote

Error 1 'frmLeft' is not a member of 'System.Windows.Forms.Form'.
Error 2 'frmLeft' is not a member of 'System.Windows.Forms.Form'.
Error 3 'frmLeft' is not declared. It may be inaccessible due to its protection level.
Error 4 'frmLeft' is not declared. It may be inaccessible due to its protection level.


( I use VB Net 2012)

Thank you

This post has been edited by andrewsw: 24 August 2013 - 08:52 PM

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3818
  • View blog
  • Posts: 13,534
  • Joined: 12-December 12

Re: move form inside splitcontainer panel

Posted 24 August 2013 - 08:54 PM

I said to put the first line "At the top of the main form's class", not inside the Load event. If you put it there then it is not accessible outside this event.
Was This Post Helpful? 0
  • +
  • -

#7 wayans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 13

Re: move form inside splitcontainer panel

Posted 25 August 2013 - 09:24 PM

@andrewsw :
Oh I am sorry my mistake in the post ,I did already under the public class with that error:
Public Class Form1
    Public frmLeft As New Form2
    Public Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim frmRight As New Form3

        frmLeft.TopLevel = False
        frmRight.TopLevel = False
        frmLeft.Parent = SplitContainer1.Panel1
        frmRight.Parent = SplitContainer1.Panel2
        frmLeft.Show()
        frmRight.Show()
       
    End Sub

End Class


Thank you.

This post has been edited by andrewsw: 26 August 2013 - 02:48 AM

Was This Post Helpful? 0
  • +
  • -

#8 wayans  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 13

Re: move form inside splitcontainer panel

Posted 27 August 2013 - 05:11 AM

@andrewsw :
To solve my problem, I try another way, creating graphic on PictureBox. I change the form with PictureBox that I can move vertically and horizontally as I need.
A little problem I notice that at runtime using form give better graphic repaint when moving the form with graphic compare to the picturebox I use now. but I hope there is a way to resolve later.
Anyway thank you very much for your attention.
As I just a couple week learning VB Net I will have another question next time.

Best Regards,
Wayan Sugata
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1