WPF form controls(Next button, cancel button) gets disabled in background - c#

I've a WPF page that contains next and cancel navigation to subsequent pages. Next button gets enabled based on certain validations. On click of another button in the page, another .exe gets opened and the 1st page goes to background. After finishing the tasks in opened exe, if the 1st page is not clicked, Next button and close button stay disabled. Once I click on the form, they get enabled.
I checked that if the 1st form is in background, CanExecuteChanged function gets called only when the form is clicked manually.
How to make the 1st form active again after the 2nd exe is closed?

Related

Set Parent for the dialog box when the same dialog box can be opened from both WPF and WinForm application

I have an application which have 2 modules (one made from WinForms and other made of WPF). I have an Export Button on both of the modules.
Export button is used to Export the grid to Excel File and save on my local.
I have a common method (ExportToExcel()) for exporting grid to excel when Export button is clicked.
Now as i have said my application has both WPF and WinForms used, now when the user clicks on Export Button on 1st module(WinForms) the Export dialog box opens, Now if the user clicks on Export Button of 2nd Module(WPF) the issue was thrown Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process. which i have corrected applying threading as shown in below code using thread.SetApartmentState(ApartmentState.STA).
Now the issue after using threading and setting ApartmentState to STA is that the parent has been removed from the Export dialog box, which should be the particular module(1st or 2nd) from where the Export button was clicked and dialog box was opened, right now the parent for the dialog box is windows not the application modules(1st or 2nd).
Another issue is that as the parent is not set for the Export Dialog box , if the user clicks on Export button multiple times multiple Export dialog box get opened, which is not correct, once the export button is clicked and the dialog box gets opened, user should not be able to click on export box again until and unless user completes operation on dialog box or closes it.
My requirement is, the parent for the dialog box should be the one module from where the dialog box is opened and user should not be able to perform any operation on the application until the dialog box operation is completed.
Code for Export button click
public void ExportToExcel(UltraGrid gridToExport, UltraGridExcelExporter ultraGridExcelExporter, string name)
{
Thread thread = new Thread((ThreadStart)(() =>
{
// code to open dialog box and perform operation on it.
}));
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
I'm not sure what you said but try this:
//You need to enable (IsMdiContainer)
//Example, in your WindowsForms set:
this.IsMdiContainer = true;
WpfMenu formMenu = new WpfMenu();
formMenu.MdiParent = this;
formMenu.Show();
This makes "forms Menu", be a child of your Forms that is being executed, I believe it works for WPF too

How do I click the cross button (the cancel button) on the sub form and go to the main form?

I know how to close a sub form and go to main form by clicking "close" button under file menu bar, but I don't know how to cancel a subform and go to main form by clicking the cross button --"cancel" which is located on the upper right corner.
and then back to the main form
Update:
I have tried go to form property, under Event,there is an item called, FormClosing, write a click event funcation name,i.e cancel_Click, and then press enter. Then I can write code under cancel_click, but it rises another problem. Since I want use same code here as the one under "close" on the menu (both can redirect back to the main form), when I close on menu bar, it appears two main form. How can I fix this?
use Form.Closing event and then do what ever you want to do. link
Set the FormClosing event for the sub-form to go to the main form. Set the FormClosing event for the main form to exit the program.

Saving State of Radio Button in Windows Form Application

I want to save state of radio button in windows form application in visual studio. When I have selected a particular radio button and click next, next form loads and when I return to the previous form, all radio buttons are deselected i.e. the previous state has been not saved. SO how can I resolve this.
The methods I'm using are this.Hide() and form2.Show() after creating an object for form 2.
You can save the selected radio button the Session variable when you leave the first form and then restore the selection from the Session variable on the Page_Load function upon return to the first form.

Handle button which has drill-down menu

So i have a UI that when you right click on a button, it opens a screen with 3 other buttons on it. How do i get the event system to not override the last button clicked (being what i right clicked to open the screen) when i click down on the button that is opened. The only way i can think to do it is to store the button that was right clicked in another variable. I was wondering if there was a way to prevent the event system from overriding the last button pressed. So that my code will run off what was right clicked and not the button that was clicked.

Clicking Back Browser UpdatePanel

I have an issue where by I click on a asp Button which opens up a UpdatePanel pop up with two other buttons on, to confirm or to cancel the submit request basically.
Now I do the follow:-
Click "Submit" then it opens up the popup (which is actually a UpdatePanel made to look like a popup) I then click on Cancel with performs a _Click to make the asp Panel within the UpdatePanel to .Visible = false. I then click on a different link and click my back button on my browser. The state of the page is with the popup on with the Confirm and Cancel buttons, but the buttons do not do anything once clicked.

Categories

Resources