Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 10


A combo box’s SelectedItem property contains the selected item expressed as
text, which code can convert to other object types as needed:

 ' Get the selected bit rate as an Integer.


Dim myBitRate As Integer = _
CInt(cmbBitRate.SelectedItem)

' Get the selected flow-control method as a Handshake object.

Dim myHandshake As Handshake = _
DirectCast(cmbHandshaking.SelectedItem, Handshake)

Console.WriteLine(myBitRate)
Console.WriteLine(myHandshake.ToString)

 // Get the selected bit rate as an Integer.


int myBitRate = (int)(cmbBitRate.SelectedItem);

// Get the selected flow-control method as a Handshake object.

Handshake myHandshake = (Handshake)(cmbHandshaking.SelectedItem);
Console.WriteLine(myBitRate);
Console.WriteLine(myHandshake.ToString());
Chapter 9 showed how code can select an item from a combo box by setting its
SelectedItem property to match a retrieved user setting. If a statement attempts
to set SelectedItem to a value that doesn’t exist in the combo box, the combo
box ignores the statement and the combo box’s SelectedIndex property remains
unchanged.

$ 3  
  " 3
08


Many applications need to pass data to other modules or notify other modules
that an event has occurred. For example, a routine that executes on receiving
COM-port data might need to pass the received data to the application’s form
for displaying.
The AccessFormMarshal routine in this chapter showed how a DataReceived
routine can pass data to a form in another thread. In the example, the routine
explicitly named the instance of the form and the AccessFormMarshal routine.
Free download pdf