![]() ![]() It can't refer to some other object and it can't refer to no object. If you have a menu item on your form and you want to add subitems to it then you need to use a variable that actually refers to that object. You need to think about what objects your variables actually refer to. If that routine fails, the click should be aborted. ![]() That means that later, when you try to add subitems to AppleToolStripMenuItem, you're adding those subitems to a menu item that doesn't exist. Thread Starter Still learning Join Date Apr 2004 Location Gardnerville,nv Posts 3,743 RESOLVED Manually close a menustrip dropdown Hey all, I have a menu strip with a bunch of nested drop down items and before the user is allowed to click any of the children, I need to run a validation routine. You add a bunch of subitems to FruitsToolStripMenuItem and one of them has the text "Apple" on it, but you never assign that item to the AppleToolStripMenuItem property. You declare that as a property but, as far as I can tell, you never assign anything to it. You also seem to have an issue with AppleToolStripMenuItem. Don't use the New keyword unless you actually want a new object. Hopefully you can see that the middle line is not only pointless, it also creates an object, thus consuming resources, that will never be used. MsgBox("You've clicked " & itemselected.Text)Ģ) What is the syntax for AddHandler and where does it fit in (suggested by techgnome) ? Private Sub MenuItemClicked(ByVal sender As Object, ByVal e As System.EventArgs) 'EventArgs)ĭim itemselected As ToolStripMenuItem = DirectCast(sender, ToolStripMenuItem) (item, Nothing, AddressOf MenuItemClicked) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load When the user clicks on one of the sub-menu items, how can I determine which menu and sub-menu item was clicked? How can I add sub-menu items to these items? For example, how can I add sub-menu items "Delicious" and "Gala" to the "Apple" menu item? This works perfectly for adding menu items to the "Fruits" high level menu. Then in the coding area I added the following code to add dropdown items to the high level menu item called "FruitsToolStripMenuItem". In the Form1 design window I typed a high level menu item called "Fruits". Used the MenuStrip toolbox control to add MenuStrip1 to the application. Here is what I've done (using VB.NET 2010 Express):Ĭreated a new VB application. No other controls on the form.Two questions on how to create sub-menu items at runtime. I then place 3 seperate Toolstripmenuitems on the menustrip. In the above code I have taken a blank form and placed a single menustrip control at the top of the form. 'Debug.Print(m.Name) Object Reference exception Dim ms As MenuStrip = Tr圜ast ( sender, MenuStrip ) ToString )ĭim m As ToolStripMenuItem = Tr圜ast ( sender, ToolStripMenuItem ) ToolStripItemClickedEventArgs ) Handles MenuStrip1. Public Class Form1 Private Sub MenuStrip1_ItemClicked ( ByVal sender As System. ![]() ToolStripMenuItem Friend WithEvents ToolStripMenuItem3 As System. ToolStripMenuItem Friend WithEvents ToolStripMenuItem2 As System. MenuStrip Friend WithEvents ToolStripMenuItem1 As System. ResumeLayout ( False )Įnd Sub Friend WithEvents MenuStrip1 As System. Text = "ToolStripMenuItem3" ' 'Form1 ' Me. Text = "ToolStripMenuItem2" ' 'ToolStripMenuItem3 ' Me. Text = "ToolStripMenuItem1" ' 'ToolStripMenuItem2 ' Me. Text = "MenuStrip1" ' 'ToolStripMenuItem1 ' Me. IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. Dispose ()Įnd Sub 'Required by the Windows Form Designer Private components As System. If disposing AndAlso components IsNot Nothing Then components. _ Protected Overrides Sub Dispose ( ByVal disposing As Boolean ) Form 'Form overrides dispose to clean up the component list. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |