none
VB.net 要如何在UserControl中使用DirectX,並可接受滑鼠鍵盤拖拉(DirectInput) RRS feed

  • 一般討論

  •  

    我發現只要在UserControl中加入以下程式碼,嵌入此UserControl的Form就會出問題

    Private Sub UserControlGraph_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    InitializeInput()
    End Sub

    Public keyb As Microsoft.DirectX.DirectInput.Device
    Public mous As Microsoft.DirectX.DirectInput.Device
    Public Sub InitializeInput()
    keyb = New Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Keyboard)
    keyb.SetCooperativeLevel(Me, (DirectInput.CooperativeLevelFlags.Background Or DirectInput.CooperativeLevelFlags.NonExclusive))
    keyb.Acquire()
    mous = New Microsoft.DirectX.DirectInput.Device(Microsoft.DirectX.DirectInput.SystemGuid.Mouse)
    mous.SetCooperativeLevel(Me, (DirectInput.CooperativeLevelFlags.Background Or DirectInput.CooperativeLevelFlags.NonExclusive))
    mous.Acquire()
    End Sub

    以下為Form的堆疊問題

     

    於 Microsoft.DirectX.DirectInput.Device.SetCooperativeLevel(IntPtr hwnd, CooperativeLevelFlags flags)
    於 Microsoft.DirectX.DirectInput.Device.SetCooperativeLevel(Control parent, CooperativeLevelFlags flags)
    於 R3SiP.UserControlGraph.InitializeInput() 於 C:\Users\530585\Documents\Visual Studio 2010\Projects\R3SiP\R3SiP\UserControlGraph.vb: 行 9
    於 R3SiP.UserControlGraph.UserControlGraph_Load(Object sender, EventArgs e) 於 C:\Users\530585\Documents\Visual Studio 2010\Projects\R3SiP\R3SiP\UserControlGraph.vb: 行 2
    於 System.Windows.Forms.UserControl.OnLoad(EventArgs e)
    於 System.Windows.Forms.UserControl.OnCreateControl()
    於 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    於 System.Windows.Forms.Control.CreateControl()
    於 System.Windows.Forms.Control.ControlCollection.Add(Control value)
    於 System.Windows.Forms.Form.ControlCollection.Add(Control value)
    於 System.Windows.Forms.Design.ControlDesigner.DesignerControlCollection.Add(Control c)

     

    請問該如何才能在UserControl中加入滑鼠及鍵盤操作呢

    因為我想要寫出可以拖拉DirectX圖形的程式



    2012年1月11日 上午 02:08

所有回覆