本文整理汇总了C#中ListBox.Update方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.Update方法的具体用法?C# ListBox.Update怎么用?C# ListBox.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListBox
的用法示例。
在下文中一共展示了ListBox.Update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTargets
/// <summary>
/// Scans each of the communication ports listed in the registry to determine if it is connected to target hardware and generates a list
/// of the target configuration information and the communication settings for each target that is located.
/// </summary>
/// <param name="targetConfigurationList">The list containing the target configuration information for any targets connected to the PTU.</param>
/// <param name="communicationSettingList">The communication settings associated with each target that was found.</param>
/// <param name="listBoxTargetsFound">The <c>ListBox</c> control on which the target names are to be displayed.</param>
/// <param name="statusInformation">The control on which the status information is to be displayed.</param>
/// <returns>A flag to indicate whether one or more targets were found; true, if targets were found, otherwise, false.</returns>
public bool GetTargets(ListBox listBoxTargetsFound, Control statusInformation, out List<TargetConfiguration_t> targetConfigurationList,
out List<CommunicationSetting_t> communicationSettingList)
{
// Instantiate to output parameters.
communicationSettingList = new List<CommunicationSetting_t>();
targetConfigurationList = new List<TargetConfiguration_t>();
CommunicationApplication communicationInterface;
// Flag to indicate whether target hardware was found; true, if one or more targets were found, otherwise, false.
bool targetFound = false;
if (Parameter.CommunicationType == Parameter.CommunicationTypeEnum.Both || Parameter.CommunicationType == Parameter.CommunicationTypeEnum.RS232)
{
// -----------------------------------------------------------------
// Scan each serial communication (COM) port listed in the Registry.
// -----------------------------------------------------------------
// Get the list of available serial COM ports from the registry.
RegistryKey root = Registry.LocalMachine;
CommunicationSetting_t communicationSetting = new CommunicationSetting_t();
// Set the protocol to serial communication.
communicationSetting.Protocol = Protocol.RS232;
// Initialize the serial communication parameters.
communicationSetting.SerialCommunicationParameters.SetToDefault();
TargetConfiguration_t targetConfiguration;
using (RegistryKey serialCommunication = root.OpenSubKey(RegistryKeySerialCommunication))
{
// Scan each port in the Registry.
foreach (string valueName in serialCommunication.GetValueNames())
{
// Filter out those '\HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM' keys that are not to be included in the search.
switch (valueName)
{
// Skip those registry keys defined here.
case SerialCommRegistryKeyWinachsf0:
continue;
default:
// Process the key.
break;
}
string value = serialCommunication.GetValue(valueName).ToString();
communicationSetting.Port.Name = value;
communicationSetting.Port.FullSpecification = value.PadRight(ComDeviceTotalCharacters) + " - " + valueName;
communicationSetting.Port.Type = (communicationSetting.Port.FullSpecification.Contains(VirtualComPort)) ? PortType.VCP : PortType.COM;
// Determine the port identifier, this is a 16 bit Unicode string representation of the serial port number e.g. for physical and virtual
// COM ports this takes the form: 1, 2, 3 ... etc.
switch (communicationSetting.Port.Type)
{
case PortType.COM:
case PortType.VCP:
communicationSetting.PortIdentifier = communicationSetting.Port.Name.Remove(0, communicationSetting.Port.Type.ToString().Length);
break;
default:
throw new ArgumentException("FormSelectTargetLogic.LocateTargetHardware()", "communicationSetting.Port.Type");
}
statusInformation.Text = Resources.TextSearchingForTargetOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
statusInformation.Update();
// Instantiate the appropriate type of communication interface.
communicationInterface = new CommunicationApplication();
try
{
if (communicationInterface.ScanPort(communicationSetting, out targetConfiguration) == true)
{
targetConfigurationList.Add(targetConfiguration);
listBoxTargetsFound.Items.Add(targetConfiguration.SubSystemName + " - (COM" + communicationSetting.PortIdentifier + ")" );
listBoxTargetsFound.Update();
statusInformation.Text = Resources.TextTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
statusInformation.Update();
communicationSettingList.Add(communicationSetting);
targetFound = true;
}
}
catch (Exception)
{
statusInformation.Text = Resources.TextNoTargetFoundOn + CommonConstants.Space + communicationSetting.Port.FullSpecification;
statusInformation.Update();
continue;
}
}
}
}
//.........这里部分代码省略.........