You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB开发APT 200系列POS软件:顾客屏显示数组越界问题求助

解决VB POS软件第二屏幕索引越界问题

错误原因

Screen.AllScreens(1)报错索引越界,核心是系统当前仅识别到1个屏幕(数组长度为1,有效索引仅为0),直接访问索引1超出了数组边界。常见诱因包括:

  • 顾客显示屏未被系统正确识别(硬件连接松动、驱动缺失或设置错误)
  • 显示设置中未启用扩展模式(若设为复制模式,系统仍判定为单屏幕)
  • 硬编码索引值,未做单屏幕场景的容错处理

解决方案

1. 先校验屏幕数量再访问

修改代码,先判断是否存在第二屏幕,避免直接硬编码索引:

' 先检测系统是否识别到多个屏幕
If Screen.AllScreens.Length > 1 Then
    Dim secondaryDisplay As Screen = Screen.AllScreens(1)
    Dim customerscreen As New Form()

    ' 配置顾客窗体显示属性
    customerscreen.StartPosition = FormStartPosition.Manual
    customerscreen.Location = secondaryDisplay.Bounds.Location
    customerscreen.WindowState = FormWindowState.Maximized
    customerscreen.FormBorderStyle = FormBorderStyle.None

    customerscreen.Show()
Else
    ' 单屏幕场景的容错提示
    MessageBox.Show("未检测到第二显示器,请检查硬件连接或显示设置。")
End If

2. 精准定位非主屏幕

如果屏幕识别顺序存在变动可能,可遍历所有屏幕,定位非主屏幕的显示器:

Dim secondaryDisplay As Screen = Nothing
' 遍历屏幕列表,找到非主屏幕的设备
For Each s As Screen In Screen.AllScreens
    If Not s.Primary Then
        secondaryDisplay = s
        Exit For
    End If
Next

If secondaryDisplay IsNot Nothing Then
    Dim customerscreen As New Form()

    customerscreen.StartPosition = FormStartPosition.Manual
    customerscreen.Location = secondaryDisplay.Bounds.Location
    customerscreen.WindowState = FormWindowState.Maximized
    customerscreen.FormBorderStyle = FormBorderStyle.None

    customerscreen.Show()
Else
    MessageBox.Show("未找到第二显示器,请排查:1. 硬件连线是否牢固;2. 显示设置是否启用扩展模式;3. 显示屏驱动是否正常安装。")
End If

3. 硬件与系统设置排查

  • 检查APT200系列POS机的顾客屏接口(如HDMI/VGA)连接状态,确认无松动
  • 进入Windows显示设置,查看是否显示两个屏幕,并将模式设置为扩展这些显示器(而非复制)
  • 打开设备管理器,确认顾客屏对应的驱动已正确安装,无未知设备标记

内容的提问来源于stack exchange,提问作者AjKu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 05:37:22