I have been writing a little application where Form1 opens, checks that a config file is present and correct, and then hides in the Task Bar until an API call is received.
When this happens I would like a new Form to open in the bottom right corner and show various details, but am having some issues. When I use ShowDialog to open the form the form doesn’t always honor the TopMost to try and get the form to appear on top of all other windows, however if I use Show instead, this honors the TopMost, but the form style is messed up as can be seen below.
The standard form looks like:
Caller Number: XXXXXXXX
Caller Name: XXXXXXXX
XXXXXXXX
Code Examples
Form2 form2 = new Form2();
form2.TopMost = true;
form2.TopLevel = true;
form2.ShowDialog();
Above: Doesn’t always open on-top of everything
Form2 form2 = new Form2();
form2.TopMost = true;
form2.TopLevel = true;
form2.Show();
My Current code is:
private void checkCalls(object source, System.Timers.ElapsedEventArgs e)
{
var client = new RestClient("http://apiurl.com");
client.Authenticator = new HttpBasicAuthenticator(api_username, api_password);
var request = new RestRequest("/", Method.GET);
// async with deserialization
var asyncHandle = client.ExecuteAsync<Call>(request, response =>
{
if (response.Data == null)
{
if (incoming_call == true && notify_type == "Pop-Up")
{
if (caller.InvokeRequired)
{
caller.Invoke(new EventHandler(delegate {
Console.WriteLine("Hidden via Invoke");
caller.Hide();
}));
}
else
{
Console.WriteLine("Hidden without Invoke");
caller.Hide();
}
}
incoming_call = false;
}
else if(incoming_call == false)
{
incoming_call = true;
if (notify_type == "Pop-Up")
{
//Console.WriteLine("Openning Window");
if (caller.InvokeRequired)
{
caller.Invoke(new EventHandler(delegate
{
Console.WriteLine("Opening Window via Invoke");
caller.Show();
caller.TopMost = true;
caller.TopLevel = true;
}));
}
else
{
Console.WriteLine("Opening Window");
caller.Show();
caller.TopMost = true;
caller.TopLevel = true;
}
}
}
});
}
And some Logs:
Opening Window Hidden without Invoke Opening Window Hidden without Invoke
Above, opens like (hard to see, but the Text Boxes should be greyed out as Disabled and Readonly, and there is black text next to each Text Field which is now invisible, but has a white background):
screenshot http://img546.imageshack.us/img546/5517/screenshot20120708at222.png
Thanks in advance!
Change the type of form to FixedDialog. If problem persists, try changing your
caller.Hide()tocaller.SetOpacity(0), and yourcaller.Show()tocaller.SetOpacity(1)Force a refresh of the form whenever you show the form.