This code displays a problem when run

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • **Developer**

    #1

    This code displays a problem when run

    I've been asking about a Menu problem I have without results.

    So here is a test case I've developed that shows the problem.

    Simply create a soultion with one project containg one form and replace the
    form code with this.

    Run it, right click and select Edit/Paste Special/Test1

    Then try to do that again

    I beleive that Test1 will not show the second time!

    How come?



    Thanks





    Public Class FormlTest

    Inherits System.Windows. Forms.Form

    #Region "Windows Form Designer generated code "

    Public Sub New()

    MyBase.New()

    InitializeCompo nent()

    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

    If disposing Then

    If Not components Is Nothing Then

    components.Disp ose()

    End If

    End If

    MyBase.Dispose( disposing)

    End Sub

    Private components As System.Componen tModel.IContain er

    Friend WithEvents MenuItemEdit As System.Windows. Forms.MenuItem

    Friend WithEvents MenuItemPasteSp ecial As System.Windows. Forms.MenuItem

    Private WithEvents ContextMenuEdit or As System.Windows. Forms.ContextMe nu

    Private Sub InitializeCompo nent()

    Me.ContextMenuE ditor = New System.Windows. Forms.ContextMe nu

    Me.MenuItemEdit = New System.Windows. Forms.MenuItem

    Me.MenuItemPast eSpecial = New System.Windows. Forms.MenuItem

    '

    'ContextMenuEdi tor

    '

    Me.ContextMenuE ditor.MenuItems .AddRange(New System.Windows. Forms.MenuItem( )
    {Me.MenuItemEdi t})

    '

    'MenuItemEdit

    '

    Me.MenuItemEdit .Index = 0

    Me.MenuItemEdit .MenuItems.AddR ange(New System.Windows. Forms.MenuItem( )
    {Me.MenuItemPas teSpecial})

    Me.MenuItemEdit .Text = "Edit"

    '

    'MenuItemPasteS pecial

    '

    Me.MenuItemPast eSpecial.Index = 0

    Me.MenuItemPast eSpecial.Text = "Paste Special"

    '

    'FormlTest

    '

    Me.AutoScaleBas eSize = New System.Drawing. Size(6, 14)

    Me.BackColor = System.Drawing. Color.Blue

    Me.ClientSize = New System.Drawing. Size(768, 437)

    Me.Name = "FormlTest"

    End Sub

    #End Region

    Private Sub FormlEditor_Mou seUp(ByVal sender As Object, ByVal e As
    MouseEventArgs) Handles MyBase.MouseUp

    If e.Button = MouseButtons.Ri ght Then ContextMenuEdit or.Show(Me, New
    Point(e.X, e.Y))

    End Sub

    Private Sub ZZ_Click(ByVal sender As Object, ByVal e As System.EventArg s)

    End Sub

    Private Sub ContextMenuEdit or_Popup(ByVal sender As Object, ByVal e As
    System.EventArg s) Handles ContextMenuEdit or.Popup

    Dim lMsg As String

    Dim jnk

    MenuItemPasteSp ecial.MenuItems .Clear()

    MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test1 ", AddressOf
    ZZ_Click))

    MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test2 ", AddressOf
    ZZ_Click))

    End Sub

    End Class








  • Chris

    #2
    Re: This code displays a problem when run

    **Developer** wrote:[color=blue]
    > I've been asking about a Menu problem I have without results.
    >
    > So here is a test case I've developed that shows the problem.
    >
    > Simply create a soultion with one project containg one form and replace the
    > form code with this.
    >
    > Run it, right click and select Edit/Paste Special/Test1
    >
    > Then try to do that again
    >
    > I beleive that Test1 will not show the second time!
    >
    > How come?
    >
    >
    >
    > Thanks
    >
    >
    >
    >
    >
    > Public Class FormlTest
    >
    > Inherits System.Windows. Forms.Form
    >
    > #Region "Windows Form Designer generated code "
    >
    > Public Sub New()
    >
    > MyBase.New()
    >
    > InitializeCompo nent()
    >
    > End Sub
    >
    > Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    >
    > If disposing Then
    >
    > If Not components Is Nothing Then
    >
    > components.Disp ose()
    >
    > End If
    >
    > End If
    >
    > MyBase.Dispose( disposing)
    >
    > End Sub
    >
    > Private components As System.Componen tModel.IContain er
    >
    > Friend WithEvents MenuItemEdit As System.Windows. Forms.MenuItem
    >
    > Friend WithEvents MenuItemPasteSp ecial As System.Windows. Forms.MenuItem
    >
    > Private WithEvents ContextMenuEdit or As System.Windows. Forms.ContextMe nu
    >
    > Private Sub InitializeCompo nent()
    >
    > Me.ContextMenuE ditor = New System.Windows. Forms.ContextMe nu
    >
    > Me.MenuItemEdit = New System.Windows. Forms.MenuItem
    >
    > Me.MenuItemPast eSpecial = New System.Windows. Forms.MenuItem
    >
    > '
    >
    > 'ContextMenuEdi tor
    >
    > '
    >
    > Me.ContextMenuE ditor.MenuItems .AddRange(New System.Windows. Forms.MenuItem( )
    > {Me.MenuItemEdi t})
    >
    > '
    >
    > 'MenuItemEdit
    >
    > '
    >
    > Me.MenuItemEdit .Index = 0
    >
    > Me.MenuItemEdit .MenuItems.AddR ange(New System.Windows. Forms.MenuItem( )
    > {Me.MenuItemPas teSpecial})
    >
    > Me.MenuItemEdit .Text = "Edit"
    >
    > '
    >
    > 'MenuItemPasteS pecial
    >
    > '
    >
    > Me.MenuItemPast eSpecial.Index = 0
    >
    > Me.MenuItemPast eSpecial.Text = "Paste Special"
    >
    > '
    >
    > 'FormlTest
    >
    > '
    >
    > Me.AutoScaleBas eSize = New System.Drawing. Size(6, 14)
    >
    > Me.BackColor = System.Drawing. Color.Blue
    >
    > Me.ClientSize = New System.Drawing. Size(768, 437)
    >
    > Me.Name = "FormlTest"
    >
    > End Sub
    >
    > #End Region
    >
    > Private Sub FormlEditor_Mou seUp(ByVal sender As Object, ByVal e As
    > MouseEventArgs) Handles MyBase.MouseUp
    >
    > If e.Button = MouseButtons.Ri ght Then ContextMenuEdit or.Show(Me, New
    > Point(e.X, e.Y))
    >
    > End Sub
    >
    > Private Sub ZZ_Click(ByVal sender As Object, ByVal e As System.EventArg s)
    >
    > End Sub
    >
    > Private Sub ContextMenuEdit or_Popup(ByVal sender As Object, ByVal e As
    > System.EventArg s) Handles ContextMenuEdit or.Popup
    >
    > Dim lMsg As String
    >
    > Dim jnk
    >
    > MenuItemPasteSp ecial.MenuItems .Clear()
    >
    > MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test1 ", AddressOf
    > ZZ_Click))
    >
    > MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test2 ", AddressOf
    > ZZ_Click))
    >
    > End Sub
    >
    > End Class
    >
    >
    >
    >
    >
    >
    >
    >[/color]


    This code should fix your problem. Looks like you have to refresh the
    menu with MenuItemPasteSp ecial after you make a change like that....

    Private Sub ContextMenuEdit or_Popup(ByVal sender As Object, ByVal e
    As System.EventArg s) Handles ContextMenuEdit or.Popup


    MenuItemPasteSp ecial.MenuItems .Clear()

    MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test1 ",
    AddressOf ZZ_Click))

    MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test2 ",
    AddressOf ZZ_Click))

    MenuItemEdit.Me nuItems.Clear()

    Me.MenuItemEdit .MenuItems.Add( Me.MenuItemPast eSpecial)

    End Sub

    Comment

    • **Developer**

      #3
      Re: This code displays a problem when run

      I wonder why that works because you're removing and then adding
      MenuItemPasteSp ecial which displayed OK. It's the items of
      MenuItemPasteSp ecial that didn't.

      In any event, that does solve the problem as I presented it but typically
      one would not want to clear MenuItemEdit because it would have many items on
      it.

      I wonder what made you think of that. Do you have any other ideas that may
      sove the more general problem?

      Thanks


      "Chris" <no@spam.com> wrote in message
      news:%23yv990Oo FHA.1196@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > **Developer** wrote:[color=green]
      >> I've been asking about a Menu problem I have without results.
      >>
      >> So here is a test case I've developed that shows the problem.
      >>
      >> Simply create a soultion with one project containg one form and replace
      >> the form code with this.
      >>
      >> Run it, right click and select Edit/Paste Special/Test1
      >>
      >> Then try to do that again
      >>
      >> I beleive that Test1 will not show the second time!
      >>
      >> How come?
      >>
      >>
      >>
      >> Thanks
      >>
      >>
      >>
      >>
      >>
      >> Public Class FormlTest
      >>
      >> Inherits System.Windows. Forms.Form
      >>
      >> #Region "Windows Form Designer generated code "
      >>
      >> Public Sub New()
      >>
      >> MyBase.New()
      >>
      >> InitializeCompo nent()
      >>
      >> End Sub
      >>
      >> Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      >>
      >> If disposing Then
      >>
      >> If Not components Is Nothing Then
      >>
      >> components.Disp ose()
      >>
      >> End If
      >>
      >> End If
      >>
      >> MyBase.Dispose( disposing)
      >>
      >> End Sub
      >>
      >> Private components As System.Componen tModel.IContain er
      >>
      >> Friend WithEvents MenuItemEdit As System.Windows. Forms.MenuItem
      >>
      >> Friend WithEvents MenuItemPasteSp ecial As System.Windows. Forms.MenuItem
      >>
      >> Private WithEvents ContextMenuEdit or As System.Windows. Forms.ContextMe nu
      >>
      >> Private Sub InitializeCompo nent()
      >>
      >> Me.ContextMenuE ditor = New System.Windows. Forms.ContextMe nu
      >>
      >> Me.MenuItemEdit = New System.Windows. Forms.MenuItem
      >>
      >> Me.MenuItemPast eSpecial = New System.Windows. Forms.MenuItem
      >>
      >> '
      >>
      >> 'ContextMenuEdi tor
      >>
      >> '
      >>
      >> Me.ContextMenuE ditor.MenuItems .AddRange(New
      >> System.Windows. Forms.MenuItem( ) {Me.MenuItemEdi t})
      >>
      >> '
      >>
      >> 'MenuItemEdit
      >>
      >> '
      >>
      >> Me.MenuItemEdit .Index = 0
      >>
      >> Me.MenuItemEdit .MenuItems.AddR ange(New System.Windows. Forms.MenuItem( )
      >> {Me.MenuItemPas teSpecial})
      >>
      >> Me.MenuItemEdit .Text = "Edit"
      >>
      >> '
      >>
      >> 'MenuItemPasteS pecial
      >>
      >> '
      >>
      >> Me.MenuItemPast eSpecial.Index = 0
      >>
      >> Me.MenuItemPast eSpecial.Text = "Paste Special"
      >>
      >> '
      >>
      >> 'FormlTest
      >>
      >> '
      >>
      >> Me.AutoScaleBas eSize = New System.Drawing. Size(6, 14)
      >>
      >> Me.BackColor = System.Drawing. Color.Blue
      >>
      >> Me.ClientSize = New System.Drawing. Size(768, 437)
      >>
      >> Me.Name = "FormlTest"
      >>
      >> End Sub
      >>
      >> #End Region
      >>
      >> Private Sub FormlEditor_Mou seUp(ByVal sender As Object, ByVal e As
      >> MouseEventArgs) Handles MyBase.MouseUp
      >>
      >> If e.Button = MouseButtons.Ri ght Then ContextMenuEdit or.Show(Me, New
      >> Point(e.X, e.Y))
      >>
      >> End Sub
      >>
      >> Private Sub ZZ_Click(ByVal sender As Object, ByVal e As System.EventArg s)
      >>
      >> End Sub
      >>
      >> Private Sub ContextMenuEdit or_Popup(ByVal sender As Object, ByVal e As
      >> System.EventArg s) Handles ContextMenuEdit or.Popup
      >>
      >> Dim lMsg As String
      >>
      >> Dim jnk
      >>
      >> MenuItemPasteSp ecial.MenuItems .Clear()
      >>
      >> MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test1 ", AddressOf
      >> ZZ_Click))
      >>
      >> MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test2 ", AddressOf
      >> ZZ_Click))
      >>
      >> End Sub
      >>
      >> End Class
      >>
      >>
      >>
      >>
      >>
      >>
      >>
      >>[/color]
      >
      >
      > This code should fix your problem. Looks like you have to refresh the
      > menu with MenuItemPasteSp ecial after you make a change like that....
      >
      > Private Sub ContextMenuEdit or_Popup(ByVal sender As Object, ByVal e As
      > System.EventArg s) Handles ContextMenuEdit or.Popup
      >
      >
      > MenuItemPasteSp ecial.MenuItems .Clear()
      >
      > MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test1 ", AddressOf
      > ZZ_Click))
      >
      > MenuItemPasteSp ecial.MenuItems .Add(New MenuItem("Test2 ", AddressOf
      > ZZ_Click))
      >
      > MenuItemEdit.Me nuItems.Clear()
      >
      > Me.MenuItemEdit .MenuItems.Add( Me.MenuItemPast eSpecial)
      >
      > End Sub[/color]


      Comment

      Working...