我正在玩弄 BASS .NET,但我无法弄清楚如何在我的项目中让 Combo 框在 SelectedIndexChanged 事件发生时返回一个整数。也许我错过了一些东西,或者我的代码的某些部分无法访问。
我的基本目标是根据选择的驱动程序类型用驱动程序名称填充列表框。
无论如何,我整天都在做,不知道发生了什么。非常感谢任何建议
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//BASS references
using Un4seen.Bass;
using Un4seen.BassAsio;
using Un4seen.Bass.AddOn.Midi;
namespace VibeCraft
{
public partial class vcSettings : Form
{
BASS_DEVICEINFO dvInfo;
public vcSettings()
{
InitializeComponent();
}
public void SetDriverType()
{
int driverList = Bass.BASS_GetDeviceCount();
switch (cmbDrvType.SelectedIndex)
{
//Clear Names when No sound is selected
case 0:
for (int i = driverList; i >= 0; i--)
{
lstDriverList.Items.Remove(driverList);
}
break;
//get Device names for DirecX Driver type
case 1:
for (int i = driverList; i < Bass.BASS_GetDeviceCount(); i++)
{
dvInfo = Bass.BASS_GetDeviceInfo(i);
Bass.BASS_GetDeviceInfo(i, dvInfo);
lstDriverList.Items.Add(dvInfo.name);
}
break;
//Get Device names for ASIO Driver type
case 2:
//TODO:
//logic for populating the ASIO driver list.
break;
default:
cmbDrvType.SelectedIndex = 1;
break;
}
}
private void cmbDrvType_SelectedIndexChanged(object sender, EventArgs e)
{
SetDriverType();
}
}
}
感谢您的所有支持,我找出了我出错的地方,在我增加索引的 for 循环中,我从一个等于哨兵值的值开始。driverList 的值已经是 3,所以它没有增加,因为我正在比较它。这是我更新的代码。
public void SetDriverType(int selectedType)
{
int driverList = Bass.BASS_GetDeviceCount();
switch (selectedType)
{
//Clear Names when No sound is selected
case 0:
for (int i = driverList; i >= 0; i--)
{
lstDriverList.Items.Remove(driverList);
}
break;
//get Device names for DirecX Driver type
case 1:
for (int i = 0; i < Bass.BASS_GetDeviceCount(); i++)
{
dvInfo = Bass.BASS_GetDeviceInfo(i);
//Bass.BASS_GetDeviceInfo(i, dvInfo);
lstDriverList.Items.Add(dvInfo.name);
}
break;
//Get Device names for ASIO Driver type
case 2:
//TODO:
//logic for populating the ASIO driver list.
break;
}