Link to home
Start Free TrialLog in
Avatar of ITD_Technician
ITD_Technician

asked on

Docking a Form Window within VS 2005

Haven't been coding for some time now. Just started to familiarize myself with VS 2005.
I've been trying to get a form to dock to the side of a screen.

Found a few coding examples online, mostly for VB 5 and VB 6. And expressions like "Screen.Width" and "Form1.Width" don't seem
to work any longer. Here is an example:
http://www.freevbcode.com/ShowCode.asp?ID=5329
I tried updating it, but didn't get anywhere.

I also tried code like "Me.Dock = Dockstyle.Right", but that didn't work either.

I need the form to be dockable via the title bar when in motion. Like ICQ basically...
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Using the following code, you can dock a form to the right:

_____________________________________

        Me.Width = 200
        Me.Height = SystemInformation.WorkingArea.Height
        Me.Left = SystemInformation.WorkingArea.Width - 200
        Me.Top = 0

_____________________________________

Similarly, you can dock the form to any other screen edge.

_______________

  Nayer Naguib
Avatar of ITD_Technician
ITD_Technician

ASKER

That certainly does move it to the proper place, but it doesn't dock.
I want other applications to be able to maximize beside it
The code on the page you posted above provides very similar functionality. It only adds the ability to drag forms to screen edges, but does not provide taskbar-like behavior.

_______________

  Nayer Naguib
What you are trying to do is create what is called "application desktop toolbar". This can be done using Win32 API calls which will register your application as an "application desktop toolbar", set the position of the form, resize the desktop working area, etc...

This article provides a link to C++ source code that will do the job (if you are not familiar with Win32 C++ code, then you will not find this interesting at all):

  http://support.microsoft.com/default.aspx?scid=kb;en-us;134206

I will try to locate similar VB code for you.

_______________

  Nayer Naguib
Here's what you need to do:

1. Download source code from this page:

  http://www.codeproject.com/csharp/csdoesshell3.asp

2. Using a C# compiler, compile the source code into a class library (DLL). Using Visual Studio IDE, you can create a new C# class library project, add all of the source files, remove the duplicate AssemblyInfo.cs file (the default copy generated by the new project wizard), and compile the code. Now you should have a DLL that contains the compiled classes.

3. Open your Visual Basic project, and add the DLL file using the Add Reference command.

4. Now you can write code like that shown below to create and show a docked form:

        Dim frm As New ShellLib.ApplicationDesktopToolbar
        frm.Width = 50
        frm.Edge = ShellLib.ApplicationDesktopToolbar.AppBarEdges.Left
        frm.Show()

and to restore previos desktop work area, you can use the statement:

        frm.Close()

_______________

  Nayer Naguib
Pretty sure I was able to create the DLL properly (Started the C# interface, created a new class library project. Used Add New Item to import all the cs files from the link and compiled the DLL).

Visual Studio doesn't seem to understand ShellLib.ApplicationDesktopToolbar however.
I must have created the DLL wrong. If I Add refference to ShellBasics.dll from the demo source code, then your code works fine.
Can you walk me through the DLL creation a little better?

Thanks..
To use the compiled classes, you first need to add the DLL to the VB project that you are working on. Use the Add Reference command, browse to the DLL location and add it to your project.

_______________

  Nayer Naguib
Also is there a way I can use the DLL it creates on the form I am currently working on, rather then generating a new form on the fly
Of course. To modify an existing form, let it inherit from class ShellLib.ApplicationDesktopToolbar rather than System.Windows.Forms.Form.

_______________

  Nayer Naguib
The following line shows how to inherit from the ShellLib.ApplicationDesktopToolbar class:

Public Class myForm
    Inherits ShellLib.ApplicationDesktopToolbar

_______________

  Nayer Naguib
I get this error with that code

Base class 'ShellLib.ApplicationDesktopToolbar' specified for class 'myForm' cannot be different from the base class 'System.Windows.Forms.Form' of one of its other partial types.
ASKER CERTIFIED SOLUTION
Avatar of nayernaguib
nayernaguib
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works like a charm. For refference.

Added Refference to ShellBasics.dll from csdoesshell3_demo

Used the following code:

Public Class Form1
    Inherits ShellLib.ApplicationDesktopToolbar

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Width = 200
        Me.Edge = ShellLib.ApplicationDesktopToolbar.AppBarEdges.Left

    End Sub

End Class