1
Good staff,
I have a window in Toolbox WindowStyle="ToolWindow"
which only serves to give information to the user what is happening on BackgroundWorker
But I am having a problem, I for example have this following code that is in the Activated event:
private void WindowDocumentPriceCheck_Activated(object sender, EventArgs e)
{
this.Activated -= WindowDocumentPriceCheck_Activated;
BackgroundWorker workerFillTheLists = new BackgroundWorker();
workerFillTheLists.DoWork += this.workerFillTheLists_DoWork;
workerFillTheLists.RunWorkerCompleted += this.workerFillTheLists_RunWorkerCompleted;
this.windowWaitForWorker = new WindowWaitForWorker("Informação", "Por favor aguarde!");
this.windowWaitForWorker.WindowStartupLocation = WindowStartupLocation.CenterScreen;
this.windowWaitForWorker.Closed += this.WindowWaitForWorker_Closed;
workerFillTheLists.RunWorkerAsync();
// Quero que o utilizador não tenha a hipotesses de carregar nos botões da janela anterior dai estar com ShowDialog();
this.windowWaitForWorker.ShowDialog();
}
The problem is when the Window windowWaitForWorker
closes it not from the previous window.
I’ve tried several things, from this add the event Closed
activate or give Focus and nothing
private void WindowWaitForWorker_Closed(object sender, EventArgs e)
{
this.Activate();
this.Topmost = true; // important
this.Topmost = false; // important
this.Focus();
this.textBoxBarCode.Focus();
}
Here’s the code that’s behind the WindowWaitForWorker
public partial class WindowWaitForWorker : Window
{
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x00080000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
/// <summary>
/// Consctuctor that will receive the title and message to show
/// </summary>
/// <param name="title">Title for the window</param>
/// <param name="message">Message for the user</param>
public WindowWaitForWorker(string title, string message)
{
InitializeComponent();
this.Title = title;
this.textBoxMessage.Text = message;
this.Loaded += this.WindowWaitForWorker_Loaded;
}
/// <summary>
/// Updates the message for the user to see
/// </summary>
/// <param name="message">Message for the user</param>
public void UpdateMessage(string message)
{
this.textBoxMessage.Text = message;
}
private void WindowWaitForWorker_Loaded(object sender, RoutedEventArgs e)
{
var hwnd = new WindowInteropHelper(this).Handle;
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
}
}
Nothing I’ve tried has worked, because I wanted the window to have Focus as soon as the WindowWaitForWorker
is closed AKA when the work of BackgroundWorker