每当我试着像这样说出媒体播放器的音量时:
Private Sub SndMasterSlider_ValueChanged(sender As Object, e As EventArgs) Handles SndMasterSlider.ValueChanged
Player1.settings.volume = SndMasterSlider.Value
End Sub
我收到此错误:An exception of type 'System.Windows.Forms.AxHost.InvalidActiveXStateException' occurred in AxInterop.WMPLib.dll but was not handled in user code
答案 0 :(得分:2)
假设Slider是TrackBar
控件,你将在创建表单时获得该异常(你没有说明在哪里,但我敢打赌那是在哪里)。这是因为Designer代码将设置Value
,从而在创建AxWMP
控件之前触发ValueChanged事件:
Me.TrackBar1.Value = 50
即使正在创建表单,也会触发事件。您可以设置一个标志来指示何时处理ValueChanged
事件,手动添加处理程序或仅使用当用户实际移动拇指时将触发的Scroll
事件。
Private Sub TrackBar1_Scroll(...
AxWMP.settings.volume = TrackBar1.Value
End Sub