REPOST: Popup form on button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin McGuire

    #16
    Re: REPOST: Popup form on button

    Comments inline. Thanks Brian, Hex, and Armin.
    Colin

    "hexathioorthoo xalate" <ruler@REMOVESP AM.clara.co.uk> wrote in message news:<106952925 9.8024.0@damia. uk.clara.net>.. .[color=blue]
    > Brian, I'm not sure your code does exactly what he wants. This is the
    > confusion I think: from his posting I believe he wants to "select" buttons
    > on the popup form while the mouse button is down, and further only display
    > the popup form while the mouse button is down. If the mouse button is ever
    > released, regardless of where it is, then the popup form is hidden/disposed
    > of.
    >[color=green][color=darkred]
    > > > When the mouse button is depressed over Button1, I want the
    > > > popup form (an instance of formPopup) to show. If the mouse
    > > > button is released anywhere, the cursor could be anywhere,
    > > > even over another application or on the desktop or somewhere else,
    > > > I want the popup form to be hidden. The code I have means that
    > > > if I move the cursor away from the display form, then release
    > > > the mouse button, the form isn't always hidden. I also want
    > > > to trap various events in the instance of formPopup, such as
    > > > mouseenter etc for controls on that form.[/color][/color]
    >
    > Colin, could you reply to confirm your exact desired behaviour please.
    >[/color]


    I did want to select buttons while the mouse button was down. I did
    want the popup to disappear whenever the mouse button was released.
    What Brian has written behaves more like a slick Windows programme and
    this is what I will use. What Hex has written is what I asked for. I
    asked for the wrong thing :(

    Thank you both again
    Colin

    Comment

    • Colin McGuire

      #17
      Re: REPOST: Popup form on button

      Comments inline. Thanks Brian, Hex, and Armin.
      Colin

      "hexathioorthoo xalate" <ruler@REMOVESP AM.clara.co.uk> wrote in message news:<106952925 9.8024.0@damia. uk.clara.net>.. .[color=blue]
      > Brian, I'm not sure your code does exactly what he wants. This is the
      > confusion I think: from his posting I believe he wants to "select" buttons
      > on the popup form while the mouse button is down, and further only display
      > the popup form while the mouse button is down. If the mouse button is ever
      > released, regardless of where it is, then the popup form is hidden/disposed
      > of.
      >[color=green][color=darkred]
      > > > When the mouse button is depressed over Button1, I want the
      > > > popup form (an instance of formPopup) to show. If the mouse
      > > > button is released anywhere, the cursor could be anywhere,
      > > > even over another application or on the desktop or somewhere else,
      > > > I want the popup form to be hidden. The code I have means that
      > > > if I move the cursor away from the display form, then release
      > > > the mouse button, the form isn't always hidden. I also want
      > > > to trap various events in the instance of formPopup, such as
      > > > mouseenter etc for controls on that form.[/color][/color]
      >
      > Colin, could you reply to confirm your exact desired behaviour please.
      >[/color]


      I did want to select buttons while the mouse button was down. I did
      want the popup to disappear whenever the mouse button was released.
      What Brian has written behaves more like a slick Windows programme and
      this is what I will use. What Hex has written is what I asked for. I
      asked for the wrong thing :(

      Thank you both again
      Colin

      Comment

      • Brian

        #18
        Re: REPOST: Popup form on button

        Colin,

        I went and read your first post and finally figured out what you wanted
        (should have done that in the first place). Place this into your form mouse
        up event: It will handle the mouse up event as long as the mouse is within
        the form. I haven't figured it out (yet) when the mouse is off the form. It
        will get you 90% where you what to be, i think.


        Private Sub Form1_MouseUp(B yVal sender As Object, ByVal e As
        System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseUp

        If Not f Is Nothing Then Button1_MouseUp (sender, e)

        End Sub



        "Colin McGuire" <colinandkaren@ lycos.co.uk> wrote in message
        news:ab6cea37.0 311230133.7c3a6 066@posting.goo gle.com...[color=blue]
        > Comments inline. Thanks Brian, Hex, and Armin.
        > Colin
        >
        > "hexathioorthoo xalate" <ruler@REMOVESP AM.clara.co.uk> wrote in message[/color]
        news:<106952925 9.8024.0@damia. uk.clara.net>.. .[color=blue][color=green]
        > > Brian, I'm not sure your code does exactly what he wants. This is the
        > > confusion I think: from his posting I believe he wants to "select"[/color][/color]
        buttons[color=blue][color=green]
        > > on the popup form while the mouse button is down, and further only[/color][/color]
        display[color=blue][color=green]
        > > the popup form while the mouse button is down. If the mouse button is[/color][/color]
        ever[color=blue][color=green]
        > > released, regardless of where it is, then the popup form is[/color][/color]
        hidden/disposed[color=blue][color=green]
        > > of.
        > >[color=darkred]
        > > > > When the mouse button is depressed over Button1, I want the
        > > > > popup form (an instance of formPopup) to show. If the mouse
        > > > > button is released anywhere, the cursor could be anywhere,
        > > > > even over another application or on the desktop or somewhere else,
        > > > > I want the popup form to be hidden. The code I have means that
        > > > > if I move the cursor away from the display form, then release
        > > > > the mouse button, the form isn't always hidden. I also want
        > > > > to trap various events in the instance of formPopup, such as
        > > > > mouseenter etc for controls on that form.[/color]
        > >
        > > Colin, could you reply to confirm your exact desired behaviour please.
        > >[/color]
        >
        >
        > I did want to select buttons while the mouse button was down. I did
        > want the popup to disappear whenever the mouse button was released.
        > What Brian has written behaves more like a slick Windows programme and
        > this is what I will use. What Hex has written is what I asked for. I
        > asked for the wrong thing :(
        >
        > Thank you both again
        > Colin[/color]


        Comment

        • Brian

          #19
          Re: REPOST: Popup form on button

          Here's the final code. And it works!


          Dim WithEvents f As formPopup

          Private Sub Button1_MouseDo wn(ByVal sender As Object, ByVal e As
          System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseDo wn
          Debug.WriteLine ("Button1_Mouse Down")

          f = New formPopup()

          f.Size = New Size(80, 80)
          f.BackColor = Color.Yellow

          f.Show()

          '-- Trap button1 messages
          Button1.Capture = True

          End Sub

          Private Sub Button1_MouseUp (ByVal sender As Object, ByVal e As
          System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseUp
          Debug.WriteLine ("Button1 mouseup")

          '-- Kill menu if it exists
          If Not f Is Nothing Then
          '-- Release capture
          Button1.Capture = False
          f.Hide()
          f.Close()
          f = Nothing
          End If

          End Sub


          '-- Resets button1 capture back to true if mouse left the context menu
          '-- without the user releasing the button
          Private Sub Mouseleft() Handles f.MouseLeft
          Button1.Capture = True
          End Sub




          Private Sub Button1_MouseMo ve(ByVal sender As Object, ByVal e As
          System.Windows. Forms.MouseEven tArgs) Handles Button1.MouseMo ve

          '-- See if the user is over the context menu.
          '-- If so, release button1 capture so the
          '-- context menu can receive its events.
          If Not f Is Nothing Then
          Dim pt As New Point()
          Dim pt2 As Point
          pt2 = Cursor.Position ()
          pt = f.Location
          Dim rect As New Rectangle(pt.X, pt.Y, f.Width, f.Height)
          '-- If over the menu, release capture.
          If rect.Contains(p t2.X, pt2.Y) Then
          Button1.Capture = False
          End If
          End If

          End Sub



          End Class



          Public Class formPopup
          Inherits System.Windows. Forms.Form

          Event MouseLeft()

          Private Sub formPopup_Load( ByVal sender As Object, _
          ByVal e As System.EventArg s) Handles MyBase.Load
          Dim b1 As New Button()
          b1.Size = New Size(15, 15)
          b1.Location = New Point(10, 10)
          b1.BackColor = Color.Gray
          Me.Controls.Add (b1)
          Me.FormBorderSt yle = FormBorderStyle .None




          AddHandler b1.MouseEnter, AddressOf subMEnter
          AddHandler b1.MouseLeave, AddressOf subMLeave
          AddHandler b1.MouseUp, AddressOf subMUp

          '-- Add new handler for form mouse leave
          AddHandler Me.MouseLeave, AddressOf subformLeave

          '-- Optional, if you want to form to
          '-- die when the user lifts the button up
          AddHandler Me.MouseUp, AddressOf fMouseUp


          Dim b2 As New Button()
          b2.Size = New Size(15, 15)
          b2.Location = New Point(30, 10)
          b2.BackColor = Color.Gray
          Me.Controls.Add (b2)



          AddHandler b2.MouseEnter, AddressOf subMEnter
          AddHandler b2.MouseLeave, AddressOf subMLeave

          End Sub

          '-- Raise a event if user didn't release button over the menu
          '-- and they moved it back over the form or another window
          Private Sub subformLeave(By Val sender As Object, ByVal e As
          System.EventArg s) Handles MyBase.MouseLea ve
          RaiseEvent MouseLeft()
          End Sub

          '************** *************** ***********
          '-- Optional, if you want to form to
          '-- die when the user lifts the button up
          Private Sub fMouseUp(ByVal sender As Object, ByVal e As
          System.Windows. Forms.MouseEven tArgs) Handles MyBase.MouseUp

          '-- Close the form if that's what you want
          Me.Close()
          Debug.WriteLine ("fMouseUp")

          End Sub

          '************** *************** **********


          Private Sub subMUp(ByVal sender As Object, ByVal e As MouseEventArgs)

          '-- Do you want to do this whe an user lifts over a button? If not,
          remove this.
          Me.Close()

          Debug.WriteLine ("MouseUp")

          End Sub

          Private Sub subMLeave(ByVal sender As Object, ByVal e As EventArgs)

          Dim b As Button = CType(sender, Button)
          b.BackColor = Color.Gray
          End Sub

          Private Sub subMEnter(ByVal sender As Object, _
          ByVal e As EventArgs)
          Dim b As Button = CType(sender, Button)
          b.BackColor = Color.Blue

          End Sub








          Comment

          Working...