C# WPF: webbrowser modal dialog close from win32 app - c#

I am curious as to if this is even possible, but basically what I need is when opening a System.Windows.Forms.WebBrowser Modal Dialog from a WPF application I need to catch a value passed back from the page to WPF and keep a window up or close it based on the value that I return. Is this even possible or am I going to have to about in a different way?
Thanks, Andrew

surely is possible, just create the dialog, register an event handler for a custom event you have created in your second form and show it as modal, then inside your form you do what you need to do and when something happens you fire the event the main form has registered to, in the custom EventArgs class used in your event you can pass the value main form needs to get. from the main form you check the value and you do nothing or close the popup....

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. .

How to pop up a message box when user clicks anywhere within the form window in Visual Studio?

I'm fairly new to Visual Studio in C#.
I was wondering how to pop up a message box when the user clicks anywhere within the form window.
Basically, I don't want them accessing and interacting with the program unless they have a password.
Code for the Form1() is really simple right now:
public Form1()
{
InitializeComponent();
}
The actual interface has a bunch of buttons and settings (buttons and settings I don't want the user to be able to interact with unless they have verified themselves).
regarding the 1st questions.
You usually create a second model form , that is transparent and is on top of your form.
Handle the on-click event of the transparent form .
Regarding the second questions- you should rethink your design , maybe do not show the sensitive form at all untill a user has typed the password.
By the way , you have not specified what tech do you use?
is it desktop (winforms / wpf , other)/ web (web forms, asp mvc, other) ?
recommended reading for client side windows programming.
http://msdn.microsoft.com/en-us/library/dd492132.aspx
Edit:
In order to put a form on top of another form , you use a model dialog.
http://msdn.microsoft.com/en-us/library/39wcs2dh(v=vs.110).aspx
In order to create a form transparent
http://msdn.microsoft.com/en-us/library/czke9azk(v=vs.110).aspx
Also , it still depends on your UI technology.
Provided links are form winforms, other technology may require a different approach.
Edit:
As another answer pointed out , you could also bind to the original forms click event , but you will also have to bind to every child control click event recursively.
Click on form and press F4 key that show property window then click on event button there you click on click event that show in .cs file of form .
Make function like
private void Form1_Click(object sender, EventArgs e)
{
MessageBox.Show("Click");
}

What events are triggered when ShowDialog(ParentForm) is called in C#

Simple question. I have a MainForm and a settingsForm. The settings form is initialized once and then shown every time the user clicks a button. I need it to do something when this button is clicked.
m_inputSettings.ShowDialog(this); //edit settings selected, so show that form
This is the MainForm calling the settings form, which it does fine. But I need the SettingsForm to do something every time this happens. Presently, I cant figure out if this call actually triggers any events I can set handlers for. Does it trigger an event? If not, is there another way I can tell my SettingsForm to do something every time this call happens?
Note: Any code in the mainform after that line doesn't get executed until the SettingsForm returns, but that is intentional.
Thanks.
Edit: One of the things I want my form to do it select a specific control when this happens, but it seems that that is impossible until after the form is done loading everything.
You can override the OnVisibleChanged method in your settings form. Make sure to call base.OnVisibleChanged though as to not screw up any potential observers of the event (and anything else the base class may do inside of that method.)
FormShown event - raised only once when form is displayed first time.
OnPaint / OnActivate - every time form is activated, but these events raised even when you switch with other application, which probably you don't want to do.
If you are changing form visbility, then you can use OnVisibleChanged
If you are minimizing the form, you can use OnSizeChanged / OnLocationChanged event.
If none suits you, make a public property and set false when form is closed / hidded, and set true before showing it. OnActivate, use this property to do your task.
Maybe use VisibleChanged event.
Override OnShown() event in your form this will raise only once after the form is opened
The disadvantage of OnVisibleChanged is it will also get raised when the form is closed.
On Paint , On Activate and OnEnter will raise before form is shown to the user.

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.

c# winform programming

I have two forms; one called 'win' and the other called 'loss'. There is a button on 'win' form which displays the 'loss' form. When this button is clicked both forms are visible. When I close the 'loss' form and then click the button on the 'win' form again I get the following exception:
An unhandled exception has occured: Unable to access a disposed object ..object :form
Please could someone point me in the right direction so I can resolve this?
It is because your 'loss' form is already closed and has been disposed, so it cannot be used anymore. You need to create a new instance of the form, like so (don't know how exactly your code looks):
this.loss = new LossForm();
this.loss.Show();
You can verify IsDisposed property of form, before referencing it.
E.g. button click handler on 'win' form:
if (loss.IsDisposed)
return;
// do stuff with loss form
Update: I think it's better not to share control between forms.
You can run 'loss' form as Dialog. And read all needed properties after dialog closed.
You can subscribe to 'loss' form events and process them in 'win' form.
It's not a very good model your going for but you could hook into the formClosing event, cancel it and then hide the form instead. That means the form wont be automatically disposed and you could call show again.
Put some time aside to research MVC architecture - it looks complicated at first, but it really does help.

Categories

Resources