A component developed in C# is used by application written in VB 2005. The component includes a field for data entry of numeric values, the field becomes active for data entry upon a mouse (touch-screen) click.
When the component's data entry begins I want to activate a virtual keyboard on the screen for data entry. At end of data entry (after ENTER or ESC) I want to hide the virtual keyboard. The VB application is used in industrial environment, running on touch-screen computer without physical keyboard or mouse. The VB application includes all the necessary functions to show and hide the virtual keyboard.

How can my C# component activate such functions in the parent form?
It is possible to raise events from the C# components and let the VB code handle the keyboard upon the events, but I prefer to simplify the VB code and handle the keyboard directly by the C# component.

Any idea how to do it?
Thanks for the help.

10 Years
Discussion Span
Last Post by avnerharel

Setup a Delegate and an Event in the C# component that can be assigned by the VB code on the main form. When your component detects the condition where you want to fire something or deliver information back to the main form, it will be done through the event.

// Jerry


Hi Jerry.

My VB application is sold as open code. For commercial reasons I want the VB code to be as simple as possible.
I want to implement all the functions related to the virtual keyboard by the C# component. The idea is that the VB programmer will not have to write any event code to show and hide the virtual keyboard.

Where can I find example of simplar use of Delegate functions?



I assume that the functions to display and hide the virtual keyboard are in the VB code, and that you wish to use those functions instead of controlling it from your component ?

Is the c# component initialized in the VB form on startup, or is it dynamically created through the onClick event ? and later disposed ?

Is your onClick event on the c# component or the VB code ?
Your component's parent is the VB form. You should be able to cast the parent object as the VB form class, and call any of its public methods.

If you need to keep the keyboard logic in the VB app, you can setup an event in the C# component that will allow the VB programmer to assign an event handler.

Goes something like this: your component has an Event named onRequestVirtualKeyboard
Your VB application would assign an event handler to this event, and when you invoke this event from your component, then the VB app takes care of the keyboard management.
Likewise you can have an event such as onDoneWithKeyboard.

Your c# event can be as simple as:

public delegate void RequestKeyboard(object sender, EventArgs e);
        public event RequestKeyboard onRequestKeyboard;
        private void StartSomethingNeedingAKeyboard()
            if (onRequestKeyboard != null)
                onRequestKeyboard(this, null);

Hope this helps,



I already have the system operated as you suggested. It is working fine, but has one serious downside: the VB programmer must include event handling functions for StartEdit and EndEdit to show and hide the keyboard. The C# components are used multiple times in the VB program, some screens could have as many as 50 numeric values presented by these C# components. Currently the VB code includes event handling functions to show and hide the keyboard, for each one of these component items.
I'm looking for a way to have the keyboard functions included with the VB form, or even better, with Module1 (and used by all the VB forms). Ideally, the C# component will be able to initiate a call to the keyboard action without a need to write the event code in VB for so many times.

I'm thinking along the line of Virtual functions in C++, a function with a known signature, declared in the parent form and activated by the "child" components. The only problem here is that unlike c++, this "virtual function" has to work in reverse order (the C# component child has no information about the VB form parent in design-time). I can access the parent form from my C# component in runtime, but in design-time the signature of these keyboard functions is not known and I can't compile the C# code.

Any idea?


Have you tried using Reflection ?
You can create a delegate to handle the method signature. This will let you compile the component. Maybe you can reach into the VB form using reflection (at run time) to grab the method(s) address you need, and Invoke the delegate against the discovered method address.

Do you have ownership of the VB code ? (IOW can you make changes). Like receiving windows messages ?

Is the virtual keyboard external to the VB app (IOW can you call it directly from your component) ?

Wish I could help, but I am shooting in the dark without some sample code to go on.

// Jerry



I do have full access to the VB code.
The virtual keyboard is an ActiveX component, placed on the main form of the VB application. A few functions (subroutines) in the VB code control the keyboard with functions such as load (keyboard definition from file), show and hide.

I agree, the approach should be to invoke the VB functions from the C# components using delegate functions.

I tested the concept last night, but didn't get things right yet. When I invoke the VB function(s) from the C# component my application hangs. I didn't get all the detail correctly (with some extra work I for sure will) but the general direction is right.

Thanks for the help.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.