Keyboard input does not reach WebView2 when embedding a C# WinForms window inside Delphi 7 using SetParent

13 hours ago 1
ARTICLE AD BOX

I am integrating a modern web interface into a legacy Delphi 7 desktop application by hosting a C# WinForms executable that uses WebView2.

The C# application works correctly when run standalone. However, when I embed its window inside a Delphi panel using the Windows API SetParent, the WebView renders correctly, but keyboard input does not reach the WebView text fields.

Mouse input works, but typing does not.

Symptoms

When clicking inside the chat input field inside WebView2:

The text caret appears inside the input field The mouse works normally However, typing on the keyboard sends the characters to the previously focused Delphi control instead of the WebView

Example behavior:

Click a Delphi edit box Click the WebView input field Type text The text appears in the Delphi edit instead of the WebView

Delphi:

SetParent(FAgenteHandle, pnlAgenteHost.Handle); Style := GetWindowLong(FAgenteHandle, GWL_STYLE); Style := Style and not WS_POPUP; Style := Style or WS_CHILD or WS_VISIBLE; SetWindowLong(FAgenteHandle, GWL_STYLE, Style); SetWindowPos( FAgenteHandle, 0, 0, 0, pnlAgenteHost.ClientWidth, pnlAgenteHost.ClientHeight, SWP_NOZORDER or SWP_FRAMECHANGED );

C#

public partial class Agente : Form { private readonly WebView2 web = new WebView2(); public Agente() { InitializeComponent(); FormBorderStyle = FormBorderStyle.None; ShowInTaskbar = false; web.Dock = DockStyle.Fill; web.TabStop = true; Controls.Add(web); } protected override async void OnLoad(EventArgs e) { base.OnLoad(e); await web.EnsureCoreWebView2Async(null); web.Source = new Uri("https://example.com"); } }
Read Entire Article