473,516 Members | 3,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't create a click event in a tool stip item

4 New Member
I have a tool strip menu item who's collection is filled from a subroutine that loads all available com ports on the computer at for load.

I know how to generate a click event for menu items that are filled, but not if they haven't been filled already.

I guess it doesn't need to be a click event. It just needs to do something that I can get the .text and use it to configure a serial port.


Any ideas?
Apr 18 '09 #1
6 1917
tlhintoq
3,525 Recognized Expert Specialist
Ya know that part of the method being called from an event where it says:

(object sender, eventargs e)

The sender would be the menu choice that called the event. Get the text from the sender. sender.text
Apr 18 '09 #2
wgfjr
4 New Member
I don't know what the program will name them. The list isn't populated until runtime.

I tried to fake it by creating option with names that might be there, but the compiler yelled at me. also it wouldn't account for all the posible com port options.


Now the list does fill with valid com port names. All I want to do is asign the .text to the serialport1.portname
Apr 18 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
I don't understand. Com ports are named "COM1", "COM2", "COM87" etc. Besides... you don't really need to know the name of the com port in advance, do you? When you open a com port you give the serialport control the name of the com port. Just feed it the name that is selected by the user.

Maybe some of the pertinent code would help.
Apr 18 '09 #4
wgfjr
4 New Member
I'mtrying to figure out how to get the name of the port. The user can select the port from the toolstrip menu. But I am having trouble capturing the event of when they click on it. I know hao to do it from a combo box. every time the .text field is updated I would just capture the data then.

Here I can't seem to use the same method. It's like I need to know the name of the tool menu strip item in order to pull it's .text property (COM port). But none of them exist until run time.

I have no real code for this section. The rest are just click events that I asign values for baud rates, data bits, etc. All of which are known items. I can deal with them.

As soon as I can I will post my existing code.
Apr 19 '09 #5
MrMancunian
569 Recognized Expert Contributor
Hi,

I think this might be what you're looking for. At the moment you create a ToolStripMenuItem, you need to assign an AddHandler. Perhaps this piece of code might help.

Expand|Select|Wrap|Line Numbers
  1. 'assuming the toolstripmenu has been created with ToolStrip1 as name
  2. Dim a As Integer
  3. Dim NumberOfComPorts As Integer
  4.  
  5. For a = 0 to NumberOfComPorts
  6.     Dim TempToolStripItem As New ToolStripMenuItem
  7.     With TempToolStripItem
  8.       .Name = "COM" & a
  9.       .Text = "COM" & a
  10.     End With
  11.     ToolStrip1.Items.Add(TempToolStripItem)
  12.     'Create the reference to the click-event, called a handler
  13.     AddHandler ToolStrip1.Items(TempToolStripItem).Click, AddressOf ToolStripMenuItem_Click
  14. Next
  15.  
  16. Private Sub ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  17.         Dim NewToolStripMenuItem As ToolStripMenuItem = sender
  18.         Dim NewToolStripMenuItemName As String = NewToolStripMenuItem.Name
  19.         Dim NewToolStripMenuItemText as String = NewToolStripMenuItem.Text
  20. End Sub
I hope it's helpful!

Steven
Apr 19 '09 #6
wgfjr
4 New Member
Yes,

this is more like it.


Thanks,

I will try it and post a response
Apr 27 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
3494
by: Bil Muh | last post by:
Esteemede Developers, I would like to Thank All of You in advance for your sincere guidances. I am developing a software using Visual C++ .NET Standard Edition with Windows Form (.NET) template. Briefly -------------------------------------------------------------------------------------------- I need to create dynamically some...
4
5750
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
1
2453
by: Dirk Meusel | last post by:
Background: On my webform a simple datalist shows one column. The databind is done in the page_load event. In the ItemTemplate a linkbutton serves for providing the Select Command. Problem: When I click a item to be selected, the datalist applies the SelectedItemStyle on that Item, but not the SelectedItemTemplate. When I click the same...
5
1899
by: Just Me | last post by:
Given a button name Btn_5 and Index=5 I want to do something like dim zz as string = Btn_??Index??.Text or given an array of buttons, do:
6
4844
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still...
4
10756
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't not want to display this menu if a node selected on the listview but user right click over the empty space of the panel that contain the listview. ...
5
6744
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created link buttons to stay wired up to their click events. I have what is basically a simply survey question generation page. The page first displays...
7
6738
by: The Mad Ape | last post by:
Hi I have code to programatically create a label. It works but when I try to call a sub to create a tooltip it does not work. I do not get an error so have no idea what it wrong. Please review my code and tell me how to fix it. Thanks The Mad Ape
1
3522
by: Man4ish | last post by:
Hi, How Eventlistner can be used with rendred combo box. I got one example of combobox in table as follows . /* * Copyright (c) 1995 - 2008 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7405
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7547
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3265
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1620
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.