Loaded event for WebBrowser control in winforms - c#

I need to access the below property of WebBrowser control when it is loaded completely.
webBrowser1.ActiveXInstance
this is null if the control is not loaded completely.
What property/event can I check like Form_Load?

There is WebBrowser.LoadComplete event for top-level only (the WebBrowser here I guess). If you're looking for an non top-level element, DocumentCompleted event occurs for all elements.
As ActiveXInstance is inherited from WebBrowserBase, there is also the Control.HandleCreated event, being fired when the control is displayed for the first time, though I don't know if it is applicable here.
(Sadly I'm not able to give the class and event links, but should be possible to find them yourself, right?)

Related

Form events not fired when other control is in place

I have an application that contains a form with multiple controls.
I have subscribed to the form mouse up event. However when I click on the form if thewre is an other control placed on the form the event is not fired.
So, I would like to capture an form event on the form (even when an control is in place). Is this possible?
Thanks in advance.
As far as i know windows forms doesn't implement the concept of event bubbling. So you should manually tweak controls to handle the event. You can do it manually looping through all controls, or you can create some kind of wrapper for your form/container to subscribe to the event automatically. You may check general implementation of this idea here. .

Keydown event not firing in user control obj

I have a user control which is not declared in the designer. I have a button that I want to have create this user control when I click it - it should initialize the user control and insert it in the main UI.
However, it happens that the user control has a key press event on it, which is not firing.
Why does this happen?
I already tried to attach the event on the user control itself but it seems that it's not firing at all. Is there some kind of bug?
It is very hard to fix problems with code that you can't see, but in WPF, there are often reasons why Bubbling events like the KeyDown event don't fire. Occasionally certain controls may make use of these events and set them as handled internally, thereby stopping them from bubbling up any further.
The normal solution on these occasions is to use the related Tunneling events instead, which are raised before the Bubbling methods and not used internally by controls. So, while I can't guarantee that this will fix your problem, it is certainly worth trying to handle the UIElement.PreviewKeyUp event instead of the UIElement.KeyUp event.

Silverlight 4 Key Event at Control Level

I have a Silverlight control (ChildWindow) that I want to receive all key down events. The problem is that if I simply say
this.KeyDown += new KeyEventHandler(EventDetailsPopup_UC_KeyDown)
it won't work because the event is routed to all of its child controls. How do I receive Key or Mouse events from the UserControl or ChildWindow level? Thanks
You do not describe what you mean by "it won't work", but I can at least give you some background.
Silverlight supports the concept of Routed Events. When a routed event is fired on a child control, it is passes up the logical tree, firing on the control's parent, then the parent's parent etc ... until the root visual is met. The list of routed events is detailed on this MSDN page. This is called bubbling.
It looks like you want to prevent a child control from seeing this event? i.e. you want to cancel it by setting it as handled. Unfortunately this is not possible because the child control will always receive the event first. To support this you require a feature called tunneling, where a 'preview' event first tunnels from parent to child before the bubbling event is fired. This is a WPF-specific feature as described in the MSDN page referenced above.
Or if "wont work" means that you are not getting the event.
It may be beacause some child element has setted Handled parameter of eventarguments to true.
But you can still register for listening handled events in code lets say in constructor of your childwindow:
this.AddHandler(KeyDownEvent, (KeyEventHandler)YourHandlerFunction, true);

Remove original event behaviour of WinForm Control

I would like to remove the original event behavior of controls within a form (similar to design mode).
So, when the user clicks on the button, i only want to capture that event. I do not want the original button event to be fired. Is this somehow possible?
I am looking for a generic solution. So it should work with any form and any control within the form.
Reason: I wrote a form validation rules designer. It uses reflection to enumerate all form-types in the entry assembly. The user can then select a form type, the designer creates that form, enumerates the controls, and embedds the form in the designer panel.
clicking on a control, opens a formular designer panel, and the user can now create a formular for that control and saves the formular to a DB.
When the form is then opened in the normal "runtime" mode, it loads its validation formulars.
Events are not in fact disabled in the Winforms designer. The designer executes the constructor of the form through Reflection, everything in the InitializeComponent() method executes, including the event subscriptions. Wherever this might cause a problem, the controls check the DesignMode property (prevents a Timer from starting for example) or by custom designers. The form is displayed underneath a transparent layered window on top of which the selection rectangle and drag handles are painted. Which prevents issues with mouse clicks and keyboard focus.
You probably ought to look at this magazine article to get this working for you.
From what I understand from your question, I guess, you can still use the "DesignMode" property for this as well. In your event handling routine, you may want to bypass execution by checking on this property:
if (this.DesignMode) return;
as the first statement in your event handling block of code.

Silverlight UserControl Parent is Always Null in its constructor. Any recommendations?

I have a user control that I have set as the Source of a Silverlight Frame. When I get the Parent of the user control in it's constructor, it returns Null. Is there an event of UserControl that is called after the control is loaded in the frame?
What about the Loaded event. If I understand your question correctly the Loaded event should be what you need to attach a handler for. That event fires after the object has been constructed, and added to the visual tree. So at that point it should have it's parent references set correctly.

Categories

Resources