Audax321 Posted July 19, 2003 Posted July 19, 2003 Hello, I have some code under the ContextMenu's popup event that should change the text property of a menuitem at runtime... but it only does it the first time. After that it refuses to change the text property... Any help would be great...:confused: Quote
*Experts* mutant Posted July 19, 2003 *Experts* Posted July 19, 2003 What do you mean refuses, you get an error or what? If its an error then what is it? Quote
*Experts* Volte Posted July 19, 2003 *Experts* Posted July 19, 2003 Paste your code here, please. We really can't help you without knowing even vaguely what could be causing the problem. Quote
Audax321 Posted July 19, 2003 Author Posted July 19, 2003 Don't have my code with me right now, but it is basically this: ContextMenu_Popup(variables...) Handles ContextMenu.Popup If(true) Then mnuItem.text = "Hello" Elseif(true) Then mnuItem.text = "World" End if End Sub Now, lets say the IF statement is true when the contextmenu is first popped up, the text on mnuItem will change to HELLO. But, if I go popup the menu again with the ELSEIF statement true and the IF statement FALSE, the text on mnuItem will not change... it will remain HELLO. I used message boxes to check if the code is running the proper if statement and it is... but the text won't change on the menu item... It's really strange because I never had a problem doing this in VB6. Quote
AndreRyan Posted July 19, 2003 Posted July 19, 2003 This should work fine ContextMenu_Popup(variables...) Handles ContextMenu.Popup If mnuItem.Text="World" Then mnuItem.text = "Hello" Else mnuItem.text = "World" End if End Sub Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Audax321 Posted July 20, 2003 Author Posted July 20, 2003 (edited) Hello, Thanks for the reply... I put that exact code in and when I accessed the menu the first time it changed the text to HELLO because I set it to WORLD at design time, but if I access the menu item a second time, it doesn't change the text to WORLD like it should. It keeps it as HELLO. I'm not sure why it is doing this. I've done this numerous times in VB6 so it should work in here, but it won't update it.... I have no clue.. :confused: EDIT: I just noticed this also. The menu that I am working with is not on the main level of the context menu. For example, the tree of the context menu looks like this: -ContextMenu -mnuItem1 -mnuItem2 So, mnuItem2 is in a submenu of ContextMenu. I am trying to change the text on mnuItem2. Here is the strange part... if I try to change the text of mnuItem1, the above code works fine. The code doesn't work for mnuItem2 though. I can even disable mnuItem2, I just can't change its text regardless of whether it is enabled or not... Edited July 20, 2003 by Audax321 Quote
Leaders dynamic_sysop Posted July 20, 2003 Leaders Posted July 20, 2003 why not do something like this : Dim x As Integer = 0 '/// make an integer thats available to all sub ( so it will keep counting ) '////////////////////// Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ContextMenu1.Show(Button1, New Drawing.Point(0, 15)) End Sub Private Sub ContextMenu1_Popup(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup If x <> 0 Then If MenuItem1.Text = "HELLO" Then MenuItem1.Text = "WORLD" End If If MenuItem2.Text = "GOODBYE" Then MenuItem2.Text = "CYA" End If End If x = 1 End Sub Quote
Audax321 Posted July 20, 2003 Author Posted July 20, 2003 Well, I have the ContextMenu set as the contextmenu for a NotifyIcon. And I'm not sure what you mean by having an x variable. It still won't allow me to change the text property of a menuitem that is not on the main level of the context menu more than once... Quote
AndreRyan Posted July 20, 2003 Posted July 20, 2003 Try placing a Break Point in the Popup function to see when it fires Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Audax321 Posted July 20, 2003 Author Posted July 20, 2003 Hello, I put the break point in and the code is run before the menu pops up. I have other code in there that changes the menuitem.enabled property of some of the controls and that code works fine. It just has a problem with the menuitem.text property. THanks... Quote
Audax321 Posted July 23, 2003 Author Posted July 23, 2003 Okay this is odd: This will not work because MenuItem2's text will not update. Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup Static x as integer x = x + 1 If (MenuItem1.Text = "Menu1") Then MenuItem1.Text = "Menu2" Else MenuItem1.Text = "Menu1" End If MenuItem2.Text = x End Sub BUT, this will work: Private Sub ContextMenu1_Popup(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ContextMenu1.Popup Static x as integer x = x + 1 If (MenuItem1.Text = "Menu1") Then MenuItem1.Text = "Menu2" Else MenuItem1.Text = "Menu1" End If MenuItem2.enabled = False MenuItem2.Text = x MenuItem2.enabled = True End Sub Notice how in the second one I disable the control then enable it. I am guessing this causes VB to redraw the control? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.