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...
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...
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
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
_______________
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
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.ApplicationDeskto pToolbar
frm.Width = 50
frm.Edge = ShellLib.ApplicationDeskto pToolbar.A ppBarEdges .Left
frm.Show()
and to restore previos desktop work area, you can use the statement:
frm.Close()
_______________
Nayer Naguib
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.ApplicationDeskto
frm.Width = 50
frm.Edge = ShellLib.ApplicationDeskto
frm.Show()
and to restore previos desktop work area, you can use the statement:
frm.Close()
_______________
Nayer Naguib
ASKER
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.ApplicationDeskto pToolbar however.
Visual Studio doesn't seem to understand ShellLib.ApplicationDeskto
ASKER
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..
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
_______________
Nayer Naguib
ASKER
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.ApplicationDeskto pToolbar rather than System.Windows.Forms.Form.
_______________
Nayer Naguib
_______________
Nayer Naguib
The following line shows how to inherit from the ShellLib.ApplicationDeskto pToolbar class:
Public Class myForm
Inherits ShellLib.ApplicationDeskto pToolbar
_______________
Nayer Naguib
Public Class myForm
Inherits ShellLib.ApplicationDeskto
_______________
Nayer Naguib
ASKER
I get this error with that code
Base class 'ShellLib.ApplicationDeskt opToolbar' specified for class 'myForm' cannot be different from the base class 'System.Windows.Forms.Form ' of one of its other partial types.
Base class 'ShellLib.ApplicationDeskt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm. For refference.
Added Refference to ShellBasics.dll from csdoesshell3_demo
Used the following code:
Public Class Form1
Inherits ShellLib.ApplicationDeskto pToolbar
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Width = 200
Me.Edge = ShellLib.ApplicationDeskto pToolbar.A ppBarEdges .Left
End Sub
End Class
Added Refference to ShellBasics.dll from csdoesshell3_demo
Used the following code:
Public Class Form1
Inherits ShellLib.ApplicationDeskto
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Width = 200
Me.Edge = ShellLib.ApplicationDeskto
End Sub
End Class
__________________________
Me.Width = 200
Me.Height = SystemInformation.WorkingA
Me.Left = SystemInformation.WorkingA
Me.Top = 0
__________________________
Similarly, you can dock the form to any other screen edge.
_______________
Nayer Naguib