Reputation: 532
I need to call ShowDialog()
on my Form
without it actually displaying the dialog (keep Visible
set to false
). Unfortunately, there is no VisibleChanged
event like there is on the full framework. I also can't override the the Visible
property. The closest I can come up with is to override OnLoad
and call Hide
in a new thread (since the form's visibility is set after it is loaded). This is obviously a crazy hack (not to mention is looks really bad since you can see a form being drawn and then hidden on the screen) but I really can't seem to figure out another way to do this. Any ideas?
Edit: I need to call ShowDialog()
because I'm working with a buggy third party library which only works when invoked within a form like this and in my scenario I have no need or desire for any UI. I've confirmed the bug with the third party but they don't currently have any resources to fix the issue so I'm stuck with some crazy workaround this.
Edit2: Here's some more specific info about my issue:
This works:
MyForm_OnLoad(...)
{
thirdPartyLib.StartUp(MyCallback);
}
private void MyCallback(...)
{
// Do some work with the data passed in.
}
This does not:
public static void Main()
{
thirdPartyLib.StartUp(MyCallback);
// Sleep for a bit to allow the library to fire the callback.
// Normally, the callback is triggered several times a second.
Thread.Sleep(20000);
}
private void MyCallback(...)
{
// This callback is never invoked by the library.
}
So the only way I can get things to work is by using the library in a Form
. Unfortunately I don't want to display a form in my application so I'm trying to use the form to appease the library but not display anything to accommodate my application. I'm open to suggestions.
Note that the compact framework winforms API does not support opacity nor does it have an OnShown
event (nor VisibleChanged
).
Edit3: Sorry guys, I'm not intending to be vague I just didn't want to get lost in details that didn't seem relevant. The third party library captures images from a special camera hooked up via USB. The callback function gets fired with a couple different parameters to indicate the current status and image data from the camera.
Upvotes: 1
Views: 764
Reputation: 811
Here's a way to minimize the form since you don't have FormWindowState.Minimized available in compact framework.
http://christian-helle.blogspot.com/2007/06/programmatically-minimize-application.html
Upvotes: 0
Reputation: 67178
It sounds like the third-party library is using Windows Messages for dispatching, though you're still not being terribly clear on what the actual problem is and seem to be too focused on the approach you have decided on, which I still think is wrong.
If the reason you need the control in a Window is becasue it is using Windows Messages for dispatching, then you can probably get around the issue with a MessageWindow to sink the messages or through your own calls to GetMessage/TranslateMessage/DispatchMessage.
Again, tell us what the actual root problem is, not the difficulties you're having with the solution you're trying to implement.
Upvotes: 1