How To: VB.NET Pop-up Docking Forms

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > Programming > .NET (VB, C# & J#)

How To: VB.NET Pop-up Docking Forms

tansqrx
Background

I recently had the need to add a few panels to a program that I have been working on. The panels did not need to be shown all the time and I didn't want to spawn a new form everytime I needed to see the extra panel. Additionally, I wanted the new panels to dock to the side of the main form so they would not cover the main content. My program needed three seperate areas, a debug window, options window, and of course the main window as shown in Figure 2.

user posted image
Figure 1

After quite a bit of experimenting I decided to show/hide forms that were loaded with the main form. Another explored option was to use GDI+ to make graphic panels appear and disappear but in the end they were too complicated and I decided to go with the quicker and simplier approach. After getting several requests for code on this particular project I decided to create my own tutorial on how to make dockable pop-up forms in VB.NET.

user posted image
Firgure 2

Structure

The project consists of three forms:
frmMain.vb - Main form for the project
frmDebug.vb - Add on pop-up
frmOptions.vb - Add on pop-up

The number of forms used can be modified. I started with just the debug form but later added functionality for an options form. The work of creating, showing, and docking the forms are split amoung the three forms.

frmDebug

If you have not already done so, the first thing to do is to add a new form to your project, in my case it is the debug form. The forms apprearence has nothing special about it except in my case I decided to remove the ControlBox from the title bar and set ShowInTaskbar to false.

In the frmDebug form create three global variables:
CODE
Private _myParent As New Form
Dim _bFormLock As Boolean
Dim ptFormLocation As New Point


The _myParent form represents a link back to the main form. This is need so that if the debug form is moved and the debug form is docked with the main form, the main form will also move.

_bFormLock holds a boolean value showing if the current form is docked.

ptFormLocation is a drawing point used for showing the location of the forms.

Next create two properties:
CODE
Public Property myparent() As Form
       Get
           Return _myParent
       End Get
       Set(ByVal Value As Form)
           _myParent = Value
       End Set
   End Property

   Public Property bFormLock() As Boolean
       Get
           Return _bFormLock
       End Get
       Set(ByVal Value As Boolean)
           _bFormLock = Value
       End Set
   End Property


This of course provides a link between forms.

Add the LocationChanged function:
CODE
Private Sub frmDebug_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
       If bFormLock = True Then
           ptFormLocation.X = (Me.Location.X - Me.myparent.Width)
           ptFormLocation.Y = Me.Location.Y
           Me.myparent.Location = ptFormLocation
       End If
   End Sub


The LocationChanged function handles the task of moving the parent form (frmMain) if the child form (frmDebug) is moved and the two are docked. In this case you will notice that the x location is the width of the child from minus the width of the parent form. This puts the x location the width of the parent form to the left of the child form. The y location remains the same so the two forms will be even on the y-axis.

frmOptions

The options form is identical to the debug for with one exception, the LocationChanged function positions the form to the bottom of the child form. Notice that the function is similar except the x and y points have been changed.

CODE
Private Sub frmOptions_LocationChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LocationChanged
       If bFormLock = True Then
           ptFormLocation.X = Me.Location.X
           ptFormLocation.Y = Me.Location.Y - Me.myparent.Height
           Me.myparent.Location = ptFormLocation
       End If
   End Sub


frmDebug

The main form needs four buttons:
btnDebug - used to show the debug form
btnDebugDocking - dock the debug form
btnOptions - used to show the options form
btnOptionsDocking - dock the options form

Of course the main form is where everything is tied together. Add references for the debug and options form:
CODE
'Docking Forms
   Friend WithEvents DebugForm As New frmDebug
   Dim ptDebugFormLocation As Point
   Shared bDebugFormLock As Boolean = True
   
'Options Form
   Dim OptionsForm As New frmOptions
   Dim ptOptionsFormLocation As Point
   Shared bOptionsFormLock As Boolean = True


In my case I want the debug form to be shown as the program starts so I added an OnLoad function:
CODE
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
       frmDebug_Show()
   End Sub


The function LocationChanged, moves both child forms if the parent is moved.
CODE
Private Sub frmMain_LocationChanged(ByVal sender As System.Object, _
                                       ByVal e As System.EventArgs) _
                                       Handles MyBase.LocationChanged
       If bDebugFormLock = True Then
           ptDebugFormLocation.X = Me.Location.X + Me.Width
           ptDebugFormLocation.Y = Me.Location.Y
           DebugForm.Location = ptDebugFormLocation
       End If
       If bOptionsFormLock = True Then
           ptOptionsFormLocation.X = Me.Location.X
           ptOptionsFormLocation.Y = Me.Location.Y + Me.Height
           OptionsForm.Location = ptOptionsFormLocation
       End If
   End Sub

The function is similar to the code in the child forms except the minus is replaced by a plus function.

Two seperate event handlers are needed for each form. The creation of the debug child form:
CODE
Private Sub frmOptions_Show()
       If OptionsForm.Visible = False Then
           If bOptionsFormLock = True Then
               ptOptionsFormLocation.X = Me.Location.X
               ptOptionsFormLocation.Y = Me.Location.Y + Me.Height
               OptionsForm.StartPosition = FormStartPosition.Manual
               OptionsForm.Location = ptOptionsFormLocation
               OptionsForm.Width = Me.Width
               OptionsForm.bFormLock = True
           End If
           OptionsForm.Visible = True
           OptionsForm.myparent = Me
           Me.AddOwnedForm(OptionsForm)

           OptionsForm.Show()
           btnOptions.Text = "Options <<"
       Else
           OptionsForm.Visible = False
           OptionsForm.bFormLock = False
           btnOptions.Text = "Options >>"
       End If
   End Sub

This handles the start location of the form and part of the docking buttons operation.

Next is the btnDebugDocking.Click event. This sets the property in the debug child form bFormLock. If true then the form will dock. If false the child from can be moved freely of its parent.
CODE
Private Sub btnDebugDocking_Click(ByVal sender As System.Object, _
                                       ByVal e As System.EventArgs) _
                                       Handles btnDebugDocking.Click
       If bDebugFormLock = True Then ' To Unlock
           bDebugFormLock = False
           DebugForm.bFormLock = False

           btnDebugDocking.Text = "L"
       Else
           bDebugFormLock = True 'To Lock
           DebugForm.bFormLock = True
           ptDebugFormLocation.X = Me.Location.X + Me.Width
           ptDebugFormLocation.Y = Me.Location.Y
           DebugForm.Location = ptDebugFormLocation
           btnDebugDocking.Text = "U"
       End If


The code for the options form is once again very similar to the debug form. The only difference is in the x and y-axis point needed to place the options form. Instead of located to the right, the form is located to the bottom.

Creation:
CODE
Private Sub frmOptions_Show()
       If OptionsForm.Visible = False Then
           If bOptionsFormLock = True Then
               ptOptionsFormLocation.X = Me.Location.X
               ptOptionsFormLocation.Y = Me.Location.Y + Me.Height
               OptionsForm.StartPosition = FormStartPosition.Manual
               OptionsForm.Location = ptOptionsFormLocation
               OptionsForm.Width = Me.Width
               OptionsForm.bFormLock = True
           End If
           OptionsForm.Visible = True
           OptionsForm.myparent = Me
           Me.AddOwnedForm(OptionsForm)

           OptionsForm.Show()
           btnOptions.Text = "Options <<"
       Else
           OptionsForm.Visible = False
           OptionsForm.bFormLock = False
           btnOptions.Text = "Options >>"
       End If
   End Sub


btnOptionsDocking.Click:
CODE
Private Sub btnOptionsDocking_Click(ByVal sender As System.Object, _
                                       ByVal e As System.EventArgs) _
                                       Handles btnOptionsDocking.Click
       If bOptionsFormLock = True Then ' To Unlock
           bOptionsFormLock = False
           OptionsForm.bFormLock = False

           btnOptionsDocking.Text = "L"
       Else
           bOptionsFormLock = True 'To Lock
           OptionsForm.bFormLock = True
           ptOptionsFormLocation.X = Me.Location.X
           ptOptionsFormLocation.Y = Me.Location.Y + Me.Height
           OptionsForm.Location = ptOptionsFormLocation
           btnOptionsDocking.Text = "U"
       End If
   End Sub


Conclusion

I have found this code to be quite useful over several projects. In the future I may work on a GDI+ version of this project but that may be a ways down the road as this implemention works so well. Attached is the project that holds all the files needed for this project. Docking_Forms is written is Microsoft Visual Basic.NET 2003.

 

 

 


Reply

iGuest
Ggretat work and nice implementation

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. vb.net form start position in code - 1.89 hr back. (1)
  2. vb.net docking forms - 2.06 hr back. (1)
  3. vb dockable - 2.20 hr back. (1)
  4. vb.net pop up - 5.63 hr back. (1)
  5. vb not docked - 6.44 hr back. (1)
  6. vb.net popup - 7.38 hr back. (1)
  7. what are the properties in child form in vb .net - 8.02 hr back. (1)
  8. vb.net move forms together - 8.79 hr back. (1)
  9. docking windows vb.net - 10.62 hr back. (1)
  10. vb.net code popup -menu - 11.75 hr back. (1)
  11. dock a form on splitcontainer vb.net - 23.60 hr back. (1)
  12. vb net popup - 27.06 hr back. (1)
  13. x,y form location in vb.net - 29.03 hr back. (1)
  14. vb.net popup code - 29.87 hr back. (1)
Similar Topics

Keywords : vb, net, pop, docking, forms

  1. Fun With Javascript And Forms
    Lets have some fun with javascript! (2)
  2. Forms Or Frames?
    Which to use? (9)
    Ho do I decide if I should use a form to space out my page or a frame? Ive looked up both but Im not
    quite sure which way to go about it! My website is HTML based but the newer pages also contain
    php. Basically, I want to put a block of links on the left side but keep them seperate from the rest
    of the page! I think im meant to use forms, but do i start by defining the form? How do I
    specify which form Im working with? Thanks....
  3. Backing Up User Forms As Static HTML
    (5)
    System: Activity System for use in Universities Users: Faculty members Scenario: User fills out a
    list of activites they participated in. Example: A faculty member attended a seminar about Object
    Orientated Programming. They record that seminar into their records by filling out a form and
    adding that activity into the database and identifying it with a designed term id. Spring terms are
    different than fall terms etc etc. We want to create html snapshots of these forms that can be
    included by a simple include('oldForm.html') into another form for review. ....
  4. Pixel Art Project - Creation From Scratch
    Humanoid forms (13)
    OK. I am putting it here so I can have a record of the gradual process I am going to follow to
    create a handful of Pixel Art works. I am strating a particular Pixel Art project for which I need
    to first create a base. I will be using this to create other bases - and thus it is a bit with
    lesser details. The next set of bases I would be doing would be of more detail. So, just for
    record, here is the deviant art link to the image: http://www.deviantart.com/deviation/39169461/
    Reference photos used from stock photos and other artists to get the proportion and some am....
  5. Advanced Form Question
    Advanced Forms (0)
    Alright...this might be a little hard to understand, but I'll try to make it as easy as
    possible. http://www.directamish.com/orderform.htm What you will see here is just a form that
    has a javascript to do addition and subtraction and keeps a running total at the bottom of the page.
    I want to keep this part of the form, but I want to add some things to it and I'm not sure how.
    At the very top of the form, I want to have, say, Package 1, Package 2, Package 3 for example,
    all three in radio buttons. Below that, I want to have a list of options, quite a fe....
  6. How Do You Create Web-Forms?
    HOw the hell!!! (8)
    ok im new to the web creations scean and i ahve no idea how to do forms everything i try it tells me
    that iv not done it right but then again its proberly FP which i hate but hey u gotta do what you
    gota do ok so can anyone help me?....
  7. New Features In Visual Studio 2005 Windows Forms
    (1)
    i dunno if all of u are by now well versed with the new exciting features in visual studio 2005
    forms, but for me this article was enlightening. for the benifit of others who wre in the dark like
    me.... New Features in Visual Studio 2005 Windows Forms QUOTE The little voice in my head
    shouted "Don't do it! Don't do it!" as I contemplated using the worn out cliché
    "Good things come to those who wait" to describe the experience of designing Windows applications
    with Visual Studio 2005. However, that cliché accurately communicates the idea that bui....
  8. How To Get Two Web-forms To Work Together ?
    (7)
    Does anyone know how to get two forms to work? I have a login on the navigation bar and a
    commenting box on the middle table. However, the sumbit button in the commenting box responds the
    login form. If not, is there a way to get something like this to work: A login and a commenting
    box.....
  9. Creating Forms? :s? Help!
    (2)
    Hi seeing as i SUCK at web building i need help. ok what i'm trying to do is, if i press a link,
    a new small window will show up in which there is a form In the form you have to enter the
    following details FirstName: Last Name: Account Number: (starting with RVRP) Date Deposited (format
    MM/DD/YYYY) Date Completed (format MM/DD/YYYY) Email Address: Amazon: (choice between Amazon.com ,
    Amazon.ca , Amazon.co.uk) drop down menu would be good for this. and a submit button which will
    send the details to my email. once its done, a "warning" type window should show up sa....
  10. Switching Forms - VB.NET
    Some VB.NET Basics (2)
    When I started coding in VB.NET I was unsure of how to switch forms at a click of a button or any
    other event. So for anyone with the same problem this is for them. First you must have at least two
    forms in the project. If you do not know how to add forms to a project heres how: 1) Under the
    "Project" Menu select "Add Windows Form..." 2) In the dialog box that pops up near the bottom you
    will see "Name:" with a textbox beside it. In the text box type the name of the new form. For this
    example we will just use the default name, "Form2.vb" 3) Click "Open" You now have....
  11. Forms
    (2)
    Ah yes, the magical and dreaded form. Anyways, just a small question regarding them. I've
    checked a few pages out that talk about the "action" prompt in the form coding. What I'm trying
    to achieve is having the form email an account of mine when the user hits "submit". Now I know the
    old, easy way out of this was to have action="mailto:my.email@my.email.box.com". After reading a bit
    on this (and trying it myself), I've discovered this is not a suitable solution. What happens
    when you use mailto in the form is when submit is clicked, it opens up your default....
  12. Php Forms
    (3)
    Sorry guys but i dont know how to add php forms can some1 help me plz....
  13. Dynamic Forms
    How to.. Create Dynamic Forms (1)
    I was making a search about Dynamic Forms and I found this page info very useful. Hope it will be
    very useful even for you /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' />
    Create Dynamic Forms ....
  14. cgi forms
    (0)
    if u know how to make forms but don't know how to use cgi well go here and sign up and u will be
    able to have a form that some fills out on your site to be sent to your email addrese go here
    http://cgi.tripod.com/allforms/cgi-bin/main.cgi ....

    1. Looking for vb, net, pop, docking, forms

Searching Video's for vb, net, pop, docking, forms
advertisement




How To: VB.NET Pop-up Docking Forms



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE