Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Docking a Form Window within VS 2005

Posted on 2006-04-01
14
Medium Priority
?
837 Views
Last Modified: 2012-05-05
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...
0
Comment
Question by:ITD_Technician
  • 8
  • 6
14 Comments
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16353023
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
0
 

Author Comment

by:ITD_Technician
ID: 16354819
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
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16355180
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 14

Expert Comment

by:nayernaguib
ID: 16355372
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
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16355645
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
0
 

Author Comment

by:ITD_Technician
ID: 16356496
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.
0
 

Author Comment

by:ITD_Technician
ID: 16356507
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..
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16356513
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
0
 

Author Comment

by:ITD_Technician
ID: 16356519
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
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16356562
Of course. To modify an existing form, let it inherit from class ShellLib.ApplicationDesktopToolbar rather than System.Windows.Forms.Form.

_______________

  Nayer Naguib
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16356585
The following line shows how to inherit from the ShellLib.ApplicationDesktopToolbar class:

Public Class myForm
    Inherits ShellLib.ApplicationDesktopToolbar

_______________

  Nayer Naguib
0
 

Author Comment

by:ITD_Technician
ID: 16356613
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.
0
 
LVL 14

Accepted Solution

by:
nayernaguib earned 800 total points
ID: 16356709
Click the exclamation mark that appears just below the line containing the error, and select "Change class 'myForm' to inherit from 'ShellLib.ApplicationDesktopToolbar'.

_______________

  Nayer Naguib
0
 

Author Comment

by:ITD_Technician
ID: 16357323
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Starting up a Project

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question