locked
Desktop Background form RRS feed

  • Question

  • Hi ,

    i have created a custom os in .netframework for that i want to create a form that should have the capability to stay back as a desktop background .

     

    for example when a application is started it should be capable of opening that in top of the desktop form also when the desktop form is clicked the application running on the top of the desktop form should not go back side.

    How can i create such a desktop form in vb.net Please help ....iam looking forward for somebod to helpme.


    Thankyou
    Thursday, November 18, 2010 5:54 PM

Answers

  • Ok, don't worry. Do the following steps:

     

    1 - Create a New Windows Forms application:

    2 - Add a new class to the project called FormEx.vb

    3 - Paste this code to the FormEx.vb file:

    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
      Public Partial Class FormEx
    
        Inherits Form
        'Member variables
    
        Private m_DesktopAttached As Boolean
        Private m_PreviousParent As IntPtr
    
        'Set Parent Window - We will use this to set ProgMan as the Window Parent
        <DllImport("user32.dll")> _
        Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
        End Function
    
        'Find any Window in the OS. We will look for the parent of where the desktop is (ProgMan)
        <DllImport("User32.dll")> _
        Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
        End Function
    
        Public Sub New()
          InitializeComponent()
        End Sub 
    
        <Browsable(True), DefaultValue(False), Category("Layout")> _
        <Description("Determines wether the Form is attached to the Desktop.")> _
        Public Property DesktopAttached() As Boolean
          Get
            Return m_DesktopAttached
          End Get
          Set
            m_DesktopAttached = value
            Me.MinimizeBox = Not value
    
            If Not DesignMode Then
    			If value Then
    				m_PreviousParent = SetParent(Me.Handle, FindWindow("Progman", Nothing))
    			Else
    				SetParent(Me.Handle, m_PreviousParent)
    			End If
    		End If
          End Set
        End Property
    
        Private Sub InitializeComponent()
          Me.SuspendLayout()
          '
          'FormEx
          '
          Me.ClientSize = New System.Drawing.Size(640, 480)
          Me.Name = "FormEx"
          Me.ResumeLayout(False)
    
        End Sub
    
        Private Sub FormEx_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
      End Class

    4 - Change Form1.vb code so it looks like this:

    Public Class Form1
      Inherits FormEx
    
    End Class

    5 - Click over FormEx text in Form1.vb file, it will appear a little square under the letter 'x' of FormEx. Select this little square and then choose the option that changes to inherit from WindowsApplication1(or whatever project name you select).FormEx

    6 - Build the Project.

    7 - Open the Form1 designer (after the build, close and re-open the designer if any error occurs)

    8 - Now you should see a new property in the properties window for the form called DesktopAttached. Set it to true or false to make it attached to the desktop or not.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Tuesday, November 23, 2010 7:52 PM
  • Hi selvabha, I've written an article on code project that extends the native Form's capabilites and one of these capabilities is the ability of a form to attach itself to the desktop:

    FormEx

    The article is written for the C# language, however, you can add the source code for the form in C# to your VB project with no problem, all you have to do is inherit from FormEx, instead of Form.

     

    I hope this helps.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Thursday, November 18, 2010 7:27 PM
  • Hi selvabha, just paste the entire code in this website that it will make the conversion for you:

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    You'll also need to put the code of KeyStateCheck.cs file so you can use all features of the form.

    In any case, I don't know if this will work in wince, I'm not sure if the same native Windows APIs apply to that.

    This is the code only to attach to the desktop:

    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    Namespace FormExNS
    	Public Partial Class FormEx
    		Inherits Form
    		'Member variables
    		Private m_DesktopAttached As Boolean
    		Private m_PreviousParent As IntPtr
    
    		'Set Parent Window - We will use this to set ProgMan as the Window Parent
    		<DllImport("user32.dll")> _
    		Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
    		End Function
    
    		'Find any Window in the OS. We will look for the parent of where the desktop is (ProgMan)
    		<DllImport("User32.dll")> _
    		Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
    		End Function
    
    		Public Sub New()
    			InitializeComponent()
    		End Sub
    
    
    		''' <summary>
    		''' Gets or Sets the value indicating wether the Form is attached to the Desktop.
    		''' </summary>
    		<Browsable(True), DefaultValue(False), Category("Layout")> _
    		<Description("Determines wether the Form is attached to the Desktop.")> _
    		Public Property DesktopAttached() As Boolean
    			Get
    				Return m_DesktopAttached
    			End Get
    			Set
    				m_DesktopAttached = value
    				Me.MinimizeBox = Not value
    
    				If value Then
    					m_PreviousParent = SetParent(Me.Handle, FindWindow("Progman", Nothing))
    				Else
    					SetParent(Me.Handle, m_PreviousParent)
    				End If
    			End Set
    		End Property
    	End Class
    End Namespace
    
    

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Tuesday, November 23, 2010 6:13 PM
  • Sorry, I have no experience with WinCE, so the appropriate class name for the WinCE desktop is unknown to me. To dinf the apropriate name, you can:

    1 - Find a tool like Visual Studio Spy++. Spy++ can show a variety of details of any window (including desktop). If there is a version fo CE, use it. First use your current VS Spy++ to find out how to find ProgMan, then try it in the WinCE the same way (if there is a WinCE Spy++).

    2 - Google it

     

    About the second question:

    You can use the SetParent function in the same way, and make your form, the parent of ceserver main form. To get the handle of ceserver.exe to use in the SetParent function, you can do either:

    1 - System.Diagnostics.Process.GetProcessesByName("ceserver.exe")(0).MainWindowHandle

    2 - Use FindWindow in combination with Spy++ tool, the same way of the desktop technique I explaind earlier.

     

    I'm glad to be of help.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, November 24, 2010 11:42 AM

All replies

  • Hi selvabha, I've written an article on code project that extends the native Form's capabilites and one of these capabilities is the ability of a form to attach itself to the desktop:

    FormEx

    The article is written for the C# language, however, you can add the source code for the form in C# to your VB project with no problem, all you have to do is inherit from FormEx, instead of Form.

     

    I hope this helps.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Thursday, November 18, 2010 7:27 PM
  • Hi Franco,

    can you give me the source code in VB.net Because in wince i cannot use your dll directly.

    so if you are available can u paste the code here to attach a form to desktop in windows Xp.

    if u are having only for c# can u provide what functions should i use here because i tried to view the source code in vb.net 2008 it is showing lot of errors could u please help me on this part

     

     


    Thankyou
    Tuesday, November 23, 2010 6:00 PM
  • Hi selvabha, just paste the entire code in this website that it will make the conversion for you:

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    You'll also need to put the code of KeyStateCheck.cs file so you can use all features of the form.

    In any case, I don't know if this will work in wince, I'm not sure if the same native Windows APIs apply to that.

    This is the code only to attach to the desktop:

    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
    Namespace FormExNS
    	Public Partial Class FormEx
    		Inherits Form
    		'Member variables
    		Private m_DesktopAttached As Boolean
    		Private m_PreviousParent As IntPtr
    
    		'Set Parent Window - We will use this to set ProgMan as the Window Parent
    		<DllImport("user32.dll")> _
    		Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
    		End Function
    
    		'Find any Window in the OS. We will look for the parent of where the desktop is (ProgMan)
    		<DllImport("User32.dll")> _
    		Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
    		End Function
    
    		Public Sub New()
    			InitializeComponent()
    		End Sub
    
    
    		''' <summary>
    		''' Gets or Sets the value indicating wether the Form is attached to the Desktop.
    		''' </summary>
    		<Browsable(True), DefaultValue(False), Category("Layout")> _
    		<Description("Determines wether the Form is attached to the Desktop.")> _
    		Public Property DesktopAttached() As Boolean
    			Get
    				Return m_DesktopAttached
    			End Get
    			Set
    				m_DesktopAttached = value
    				Me.MinimizeBox = Not value
    
    				If value Then
    					m_PreviousParent = SetParent(Me.Handle, FindWindow("Progman", Nothing))
    				Else
    					SetParent(Me.Handle, m_PreviousParent)
    				End If
    			End Set
    		End Property
    	End Class
    End Namespace
    
    

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Tuesday, November 23, 2010 6:13 PM
  • Hi Franco,

    Please dont get angry i created a window form application in windows xp because  i just want to check whether it was running in winxp first.Then i added ur following code and i build it but nothing happens just the form runs it fails to attach to Desktop.

    What am I making wrong.Iam very sorry for this sill question .please guide me.

     

    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices

    Namespace FormExNS
        Public Partial Class FormEx

     
            Inherits Form
            'Member variables

            Private m_DesktopAttached As Boolean
            Private m_PreviousParent As IntPtr

            'Set Parent Window - We will use this to set ProgMan as the Window Parent
            <DllImport("user32.dll")> _
            Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
            End Function

            'Find any Window in the OS. We will look for the parent of where the desktop is (ProgMan)
            <DllImport("User32.dll")> _
            Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
            End Function

            Public Sub New()
                InitializeComponent()
            End Sub

             

            <Browsable(True), DefaultValue(False), Category("Layout")> _
            <Description("Determines wether the Form is attached to the Desktop.")> _
            Public Property DesktopAttached() As Boolean
                Get
                    Return m_DesktopAttached
                End Get
                Set
                    m_DesktopAttached = value
                    Me.MinimizeBox = Not value

                    If value Then
                        m_PreviousParent = SetParent(Me.Handle, FindWindow("Progman", Nothing))
                    Else
                        SetParent(Me.Handle, m_PreviousParent)
                    End If
                End Set
            End Property

          
     

            Private Sub InitializeComponent()
                Me.SuspendLayout()
                '
                'FormEx
                '
                Me.ClientSize = New System.Drawing.Size(640, 480)
                Me.Name = "FormEx"
                Me.ResumeLayout(False)

            End Sub

            Private Sub FormEx_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            End Sub
        End Class
    End Namespace

     


    Thankyou
    Tuesday, November 23, 2010 7:29 PM
  • Ok, don't worry. Do the following steps:

     

    1 - Create a New Windows Forms application:

    2 - Add a new class to the project called FormEx.vb

    3 - Paste this code to the FormEx.vb file:

    Imports System.Collections.Generic
    Imports System.ComponentModel
    Imports System.Data
    Imports System.Drawing
    Imports System.Text
    Imports System.Windows.Forms
    Imports System.Runtime.InteropServices
    
      Public Partial Class FormEx
    
        Inherits Form
        'Member variables
    
        Private m_DesktopAttached As Boolean
        Private m_PreviousParent As IntPtr
    
        'Set Parent Window - We will use this to set ProgMan as the Window Parent
        <DllImport("user32.dll")> _
        Private Shared Function SetParent(hWndChild As IntPtr, hWndNewParent As IntPtr) As IntPtr
        End Function
    
        'Find any Window in the OS. We will look for the parent of where the desktop is (ProgMan)
        <DllImport("User32.dll")> _
        Public Shared Function FindWindow(lpClassName As [String], lpWindowName As [String]) As IntPtr
        End Function
    
        Public Sub New()
          InitializeComponent()
        End Sub 
    
        <Browsable(True), DefaultValue(False), Category("Layout")> _
        <Description("Determines wether the Form is attached to the Desktop.")> _
        Public Property DesktopAttached() As Boolean
          Get
            Return m_DesktopAttached
          End Get
          Set
            m_DesktopAttached = value
            Me.MinimizeBox = Not value
    
            If Not DesignMode Then
    			If value Then
    				m_PreviousParent = SetParent(Me.Handle, FindWindow("Progman", Nothing))
    			Else
    				SetParent(Me.Handle, m_PreviousParent)
    			End If
    		End If
          End Set
        End Property
    
        Private Sub InitializeComponent()
          Me.SuspendLayout()
          '
          'FormEx
          '
          Me.ClientSize = New System.Drawing.Size(640, 480)
          Me.Name = "FormEx"
          Me.ResumeLayout(False)
    
        End Sub
    
        Private Sub FormEx_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
      End Class

    4 - Change Form1.vb code so it looks like this:

    Public Class Form1
      Inherits FormEx
    
    End Class

    5 - Click over FormEx text in Form1.vb file, it will appear a little square under the letter 'x' of FormEx. Select this little square and then choose the option that changes to inherit from WindowsApplication1(or whatever project name you select).FormEx

    6 - Build the Project.

    7 - Open the Form1 designer (after the build, close and re-open the designer if any error occurs)

    8 - Now you should see a new property in the properties window for the form called DesktopAttached. Set it to true or false to make it attached to the desktop or not.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Tuesday, November 23, 2010 7:52 PM
  • Hi

     

    Thankyou very much for ur help it works in xp. but it is not wotking for windowsCe.I found what the problem is

     

    Question 1:

    m_PreviousParent = SetParent(Me.Handle, FindWindow("ProgMan", Nothing))

     

    How you are finding Desktop-->lpClassName as ProgMan

    Because for wince it may change That's why iam asking you.How Can i find that?

    Question 2:

     

    Also i need an another way.iam not having Explorer.exe My custom shell is ruuning

    Iam having two applications one is the  form and another is a ceserver.exe application I always need Ceserver.Exe should stay above my form .Also iam not having source code for ceserver.exe

    what should i do.Sounds so simple right?

     

    Iam pleased for your help...........................Thankyouvery much

     

     

     


    Thankyou
    Wednesday, November 24, 2010 10:45 AM
  • Sorry, I have no experience with WinCE, so the appropriate class name for the WinCE desktop is unknown to me. To dinf the apropriate name, you can:

    1 - Find a tool like Visual Studio Spy++. Spy++ can show a variety of details of any window (including desktop). If there is a version fo CE, use it. First use your current VS Spy++ to find out how to find ProgMan, then try it in the WinCE the same way (if there is a WinCE Spy++).

    2 - Google it

     

    About the second question:

    You can use the SetParent function in the same way, and make your form, the parent of ceserver main form. To get the handle of ceserver.exe to use in the SetParent function, you can do either:

    1 - System.Diagnostics.Process.GetProcessesByName("ceserver.exe")(0).MainWindowHandle

    2 - Use FindWindow in combination with Spy++ tool, the same way of the desktop technique I explaind earlier.

     

    I'm glad to be of help.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, November 24, 2010 11:42 AM
  • Thanks Franco,

    Tommorow i will tr it and Message u.............Thank u


    Thankyou
    Wednesday, November 24, 2010 4:14 PM
  • Fabio, do you have an example of how to do this that works with Windows 7? I've tried it and my form just vanishes as soon as I set the parent to the Program Manager window (regardless of whether I use the title or class name when calling FindWindow)

     

    Thanks, and sorry for bumping an old thread!


    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Friday, January 7, 2011 4:08 PM
  • Hey Chris, no problem. I can't see here on my side, but win Windows 7, you can try to modify  the class name that is "Progman". I wasn't aware that it had changed on Windows 7, so far no one has reported this problem to me. I may or may not be able to check this later, but in the mean time try this:

     

    Open up Spy++ (Under Visual Studio Tools folder of start menu), use the findWindow tool and drag the cursor to the desktop. Then see it's properties and use it's "Class Name" in the place of Progman. It might not work. Also try to check which is the last item of the List in the Windows List. Please report back here if you found the solution before I do.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, January 7, 2011 6:19 PM
  • Hi Fabio,

    Thanks for the reply but it is not that the class name or window title has changed, ProgMan is still the class name of the desktop window in Windows 7 but trying to set that as my form's parent just makes the form vanish.

     


    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Friday, January 7, 2011 7:45 PM
  • Yeah, I understand that, but perhaps the behaviour has changed, maybe to achieve the same behaviour you need to set it as child of another window, that's why I asked you to set those. In any case, check if you already don't have an app that acts like a desktop wallpaper, it might be hiding your app. I'll try to reproduce your problem.

    Also try calling BringToFront after the call to set parent window. This might solve it.

     

    Please let me know the results.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, January 7, 2011 7:51 PM
  • Hmm this is odd - I just tried it on my home PC (which is also Windows 7) and it worked perfectly when I just set the parent window of my form to the ProgMan window (no need to call BringToFront). The only difference between my home PC setup and the Windows 7 PC I was testing on at work is that at work the background image is set via Group Policy, I can't see why that would affect this though... I will try using BringToFront on the work PC on Monday and see what happens there though, thanks for the suggestion. Will let you know how it goes.


    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Friday, January 7, 2011 8:45 PM
  • Ah I have got it working - sorry it was my fault the code didn't work, nothing wrong with your code. It seems that if you set the Opacity property of a form to anything other than 100% and then try and use this code it makes the form invisible (no idea why but hey). I was using an opacity of 85% to make my app blend in with the background a bit better, but I found that setting it back to 100% made it work perfectly :) thanks for the useful code and for trying to help fix this stupid little issue!

    Cheers

    Chris


    My website: www.cjwdev.co.uk My blog: cjwdev.wordpress.com
    Friday, January 7, 2011 9:09 PM
  • No problem Chris, and thanks for your input. It's odd that the opacity interferes with the behaviour of my code, I shall investigate that and check why this is happening and if there is a workaround. Using opacity is great with this feature so you can add widgets to the desktop, so that is a killer!!

     

    Thanks again for letting me know.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, January 7, 2011 9:24 PM
  • Hi Fábio,

    if I add a TollStrip in Form1 (where is present " Inherits FormEx" and DesktopAttached = True) and then add a ToolStripButton, when I press this button a second form (Form2, without "Inherits FormEx") doesn't open.

    This is the code:

    Public Class Form1
      Inherits FormEx
    
      Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        Form2.Show()
      End Sub
    End Class
    

    While, if I add a Label in Form1, I can open the second form (Form2).

    Can you help me.

    Thanks,

    Lido

    Thursday, January 20, 2011 7:49 AM
  • Hi Lido, the reason why the form is not beeing shown, is because the Click event handler is not beeing called at all, so the Form2.Show() is not beeing called. I'm investigating why this is happening, but it's really difficult because the problem seems to be in the code of ToolStripItem which is where ToolStripButton inherits from. So it's very difficult to diagnose it, as the code is not exactly open, so it's a little hard to debug.

    I'll post here any findings.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Thursday, January 20, 2011 12:46 PM
  • Thanks,

    it's a bad problem for me. I'm writing an application based on FormEx, but it's important that ToolStripButton works. Do you know, while I'm waiting for an answer from you about the bug, another solution to put a form behind all the others (as it was a desktop). Infact I must "replace" my desktop, or better I must cover it with a form, from which to run (with ToolStripButton) some other forms. My "desktop form" never must cover other forms.

    Regards,

    Lido

    Friday, January 21, 2011 7:02 AM
  • I'm sorry LidoP, but that's the only solution that's reliable (others exist, but you can't make sure the form is always bottom most, or invulnerable to Windows+D). It sets the desktop as parent of the FormEx. This bug is really from the ToolStripItem, I'm still trying to understand the problem (I'm stepping through the code of the ToolStripItem) but it has a really weird behavior. If you use a regular button for example, it works fine (perhaps you can experiment hosting other controls like panel or buttons over the toolBox, it would be a workaround, and it could just be enough).

    The biggest problem here, is that even if I find the root cause of the bug, it will be difficult to solve it, as we can't change the ToolStripButton code, at best we can inherit from it and hope that we will be able to override the buggy behaviour. I'll even try to contact Microsoft as soon as I find the root of it so they may give me a suggestion for the workaround.

     

    I'll update here if I have further info.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, January 21, 2011 12:44 PM
  • Hi Fabio,

    other problems. Also ToolStripMenuItem doesn't work.

    In this case I had a MenuStrip and then some ToolStripMenuItem. These doesn't appear. The situation don't change if I put MenuStrip (or ToolStrip) in a Panel.

    Regards,

    Lido

    Friday, January 21, 2011 5:03 PM
  • Yeah, I know, they all inherit from ToolStripItem, which is the root of the problem.
    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, January 21, 2011 5:29 PM
  • I've open an issue on microsoft connect, if you wish to track it, please follow this link:

    https://connect.microsoft.com/VisualStudio/feedback/details/637481/toolstripitem-does-not-trigger-click-event-when-parent-form-is-pinned-to-desktop?wa=wsignin1.0

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Monday, January 24, 2011 3:35 PM
  • Hi, while Microsoft does not respond to this, I found a workaround. I don't know if it's the best way to do it, but it seemed to work fine. You'll need to inherit from ToolStrip and create your own and use it instead of regular ToolStrip:

    public class ToolStripEx : ToolStrip
      {
        protected override void WndProc(ref Message m)
        {
          base.WndProc(ref m);
          if (m.Msg == 33)
          {
            m.Result = (IntPtr)1;
          }
        }
      }
    

    Please let me know if this solves your problem.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Tuesday, January 25, 2011 11:19 PM
  • Hi,

    thanks for your rapid response. In the coming days I will test your code and I will let you know.

    I am not so good as you could think looking my project of desktop replacement, so I ask you how can I use your code.

    Generally I use form design (and I don't add controls at run time). In other words I simply drag the controls in the form.

    Regards,

    Lido

    Wednesday, January 26, 2011 7:35 AM
  • Another thing: I know only VB.

    Thanks again

    Lido

    Wednesday, January 26, 2011 7:41 AM
  • Hi Lido, no problem. I'll run you through it. It's really simple.

    1 - In Solution Explorer, Right-Click on your project (not the solution) and chooe Add->Class...

    2 - Name the class, I would suggest ToolStripEx.vb

    3 - Paste the following code to the file:

    Public Class ToolStripEx
      Inherits ToolStrip
    
      Sub New()
        MyBase.New()
      End Sub
    
      Sub New(ByVal ParamArray items() As ToolStripItem)
        MyBase.New(items)
      End Sub
    
      Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        MyBase.WndProc(m)
        If m.Msg = 33 Then
          m.Result = New IntPtr(1)
        End If
      End Sub
    End Class
    

    4 - Build the project.

     

    You're done, now the new ToolStrip (ToolStripEx) should be available from the toolbox. It should be first item of the toolBox after the Pointer item. You can drag it to your form and it should work exactly the same way the other toolBox works, but now the ToolStrip should fire the click event when it's attached to the desktop.

     

    I hope this solves your problem.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, January 26, 2011 12:05 PM
  • Hi Fabio,

    I have added ToolStripEx.vb and I have copied your code. I have built the project but in my toolbox there isn't any new item. I have checked in "choose toolbox items" too, but there isn't ToolStripEx control.

    Thanks for your availability.

    Lido

    Wednesday, January 26, 2011 2:57 PM
  • I don't know what you might be doing wrong, I tested it here and it worked. Make sure you're adding the file to the correct project (if there is more than one project in the same solution) and make sure the project is built without errors.

    Also try to check each step to make sure you completed it correctly. On the Toolbox, it's the first category (YourSolution Components), which comes before Common Controls and All Windows Forms. It's not necessary to choose the toolbox items.

    Also try using it from a new test project to see if you get the same results.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, January 26, 2011 4:33 PM
  • Now it's OK.

    You're really good, thanks.

    For ToolStripMenu can I change your code in:

    Public Class ToolStripMenuEx
     Inherits ToolStripMenu
    
     Sub New()
      MyBase.New()
     End Sub
    
     Sub New(ByVal ParamArray items() As ToolStripItem)
      MyBase.New(items)
     End Sub
    
     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
      MyBase.WndProc(m)
      If m.Msg = 33 Then
       m.Result = New IntPtr(1)
      End If
     End Sub
    End Class
    
    
    Regards,
    Lido

    Wednesday, January 26, 2011 5:51 PM
  • I'm glad to be of help.

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, January 26, 2011 6:05 PM
  • Please, could you also answer to the last question in the previous post about ToolStripMenuEX, so I finish my project.

    Thanks

    Lido

    Wednesday, January 26, 2011 6:19 PM
  • You don't need to change ToolStripMenu, in fact, ther is no such thing. There is the ToolStripMenuItem (which is used by MenuStrip and ToolStrip), but we don't need to handle that. Maybe you're refering to MenuStrip, which in case, yes, you can use the same code, but instead, inherit from MenuStrip, not ToolStripMenu.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, January 26, 2011 6:34 PM
  • Oh, and for the MenuStrip, you should remove this portion:

     Sub New(ByVal ParamArray items() As ToolStripItem)
     MyBase.New(items)
     End Sub
    


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Wednesday, January 26, 2011 6:44 PM
  • My project is going well, thanks for everything.

     

    Lido

    Thursday, February 3, 2011 8:02 AM
  • Glad to be of help!


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Thursday, February 3, 2011 1:34 PM
  • Hi Fabio,

    I have two questions for you:

    1. when I press SHOW DESKTOP in the Windows Task Bar my FormEx (maximised without border, then as it was a new desktop) becomes a normal windows (always without border); how can I do to prevent it?
    2. ToolStrip (including ToolStripEx) doesn't show ToolTipText; how can I solve it?
    Thank's

    Lido

    Thursday, February 17, 2011 7:40 AM
  • Hi Lido.

     

    1. I can't observe your behaviour. I have set the form with fixed border, set Desktop Attached to true and set the window state to maximized. No change on the behaviour. Which windows are you using?

     

    2. I beleive the same buggy implementation of ToolStrip happens with tooltip. Perhaps, you should create your own tooltip control (or maybe find one already implemented around the internet) so you can use tool tips. I can try to check if there is a workaround for the tool tip, but there is no garantee I will find a solution.

     

    Regards,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Friday, February 18, 2011 9:18 PM
  • Hi Fabio,

    1. you shoud set the form with FormBorderStyle = None (I'm using Windows Server 2003)
    2. I hope to solve the bug of MenuStrip/ToolStrip to use the "automatic" tooltip feature of ToolStripButton (properties ToolTipText) without insert a separate ToolTip control for each button

    This is my Desktop Form:

    FormBorderStyle = None
    DesktopAttached = True
    WindowsState = Maximised
    MinimiseBox = False

    Regards,

    Lido

    Saturday, February 19, 2011 9:51 AM
  • Hi Fabio,

    1. problem 2 (ToolStrip - including ToolStripEx - doesn't show ToolTipText) solved: I think it was a problem with VB 2010 program
    2. problem 1 (when I press SHOW DESKTOP in the Windows Task Bar my FormEx - maximised without border, then as it was a new desktop - becomes a normal windows - always without border): still unresolved
    Regards,

    Lido

    Monday, February 21, 2011 7:23 AM
  • Hi Lido, I still don't get the problem (I made a mistake when said I using Fixed border, I was actually using no border). What is the behaviour you have before and after pressing show window?

    Regads,

    Fábio


    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    Monday, February 21, 2011 2:23 PM