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

VB6迁移至VB.NET:添加ShockwaveFlash控件报错咨询

Fixing "Value of type 'String' cannot be converted to 'System.Windows.Forms.Control'" When Adding ShockwaveFlash in VB.NET

The error you’re hitting boils down to a critical difference between VB6 and VB.NET’s Controls.Add method: VB6 let you pass a ProgID string to dynamically spawn a control, but VB.NET requires an actual Control object instead. That’s why your old VB6 syntax breaks here.

Here’s how to fix this properly:

Step 1: Confirm Required References

First, make sure your VB.NET project has the correct interop assemblies for the ShockwaveFlash control:

  • AxShockwaveFlashObjects (the Windows Forms wrapper for the control)
  • ShockwaveFlashObjects (the underlying COM interop assembly)

You can add these via the Toolbox (right-click → Choose Items → COM Components → select "Shockwave Flash Object") or through your project’s References dialog.

Step 2: Rewrite the Control Creation Code

Replace your existing code with this VB.NET-compatible version:

Public WithEvents ShockwaveFlash1 As AxShockwaveFlashObjects.AxShockwaveFlash

' Put this in your form's initialization method (like Form_Load or the form's constructor):
ShockwaveFlash1 = New AxShockwaveFlashObjects.AxShockwaveFlash()
With ShockwaveFlash1
    .Name = "ShockwaveFlash1"
    .Parent = Me
    ' Set essential display properties (adjust values as needed):
    .Location = New System.Drawing.Point(10, 10)
    .Size = New System.Drawing.Size(400, 300)
    .Visible = True
End With
Me.Controls.Add(ShockwaveFlash1)

Why This Works

  • Instead of passing a ProgID string to Controls.Add, we directly instantiate the AxShockwaveFlash control with New.
  • We explicitly set key properties (name, parent, position, size) before adding it to the form’s controls collection.
  • The WithEvents declaration still functions exactly like it did in VB6, so you can handle the control’s events without extra changes.

Quick Troubleshooting Note

If the control fails to render, try calling ShockwaveFlash1.CreateControl() right after adding it to the controls collection. In most cases, the Parent assignment and Controls.Add will handle this automatically, but it’s a handy fallback.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:29:31