|
Hi All,
I have 2 main Form classes - ParentForm and ChildForm in the same exe.
ChildForm has a bunch of numeric up-down controls on it.
I create an instance of ChildForm, set TopLevel = true and do SetParent with
the ParentForm as the parent handle (doing this enables the non client area of
ChildForm to stay highlighted when its selected).
Now the problem is I need to know when the mouse has left the ChildForm entirely.
The Leave event for the ChildForm is never fired.
If we listen to the MouseLeave event it gets fired if the mouse hovers
over any of the numeric controls and also when the mouse goes to the parent form. Is there any way I can differentiate between these 2 cases ?
Also note that we need to cover the case where some other external application
(say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clicked
EDIT UPDATE : Thanks to all for the replies ! Have asked the same question on the MSDN Forums - http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/51e040a5-77f9-4b43-a462-1b5e3a13b90a/?prof=required[^]
TIA
modified on Monday, April 11, 2011 12:00 PM
|
|
|
|
|
private void Form1_MouseLeave(object sender, EventArgs e)
{
Point point = this.PointToClient(Cursor.Position);
if (!this.ClientRectangle.Contains(point))
MessageBox.Show("Ding");
}
Hope that helps
"You get that on the big jobs."
|
|
|
|
|
Hi Rob,
Thanks for the code snippet - it works perfectly when the mouse leaves the ChildForm and moves into the ParentForm !
Howeverm for the second casse i mentioned - "some other external application (say Task Manager with always on top as true) is positioned exactly above the child form and is clicked" , the Mouse Leave event on the ChildForm is not triggered. Is there some other event i need to be listening to for this ?
|
|
|
|
|
I think it is hard to solve. And then your mouse could walk into a dropped-down menu or context menu too.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hey Luc,
Regarding the context menus and tool strip/main menus we can listen to their Activated events, so i don`t think that should be an issue
The tricky part is to differentiate between my applications client area and other windows that may be place directly above it.
In that case, MosueLeave gets fired and the even if the user hovers over the other window, the Cursor is still within the client area boundaries !
One would expect WinForms to provide some notifications for such a basic event but i haven`t (yet) found anything helpful in the Win32 API layer as well.
|
|
|
|
|
Hi TIA
You could start playing around with the form's Deactivate event but it probably wont completely resolve your issue. Also I'm sure you, or someone else has a good argument to implement this but it is unusual behaviour and may confuse the user.
Regards
Rob
"You get that on the big jobs."
|
|
|
|
|
Hi Rob,
Yes Deactivated would work when the user actually activates another window thus deactivates my window.
However, the behavior i`ve described does not really seem unusual - for example if the user is working
with my application - and the mouse enters/leaves the child windows and the parent window ,
then certain parts of the UI are highlighted accordingly - thus reducing user confusion
|
|
|
|
|
TyrionTheImp wrote: Also note that we need to cover the case where some other external application (say notepad or Task Manager with always on top as true) is positioned exactly above the child form and is clicked Do you instead want to handle the Control.LostFocus [^] event?
/ravi
|
|
|
|
|
Hey Ravi,
Thanks for the reply - will try it in combination with the code suggested by Rob earlier.
|
|
|
|
|
plz give one small program in window base application in c#.net.
example: menustrip,any one controls,any onecontainer etc....
becuse our college is daily one presentation with example in any one topic in c#.net.soplz help me
|
|
|
|
|
Have a search around the Code Project articles. There are thousands of articles that should be able to help.
By the way - we tend not to give people programs in the forums. You may want to remember that in future.
|
|
|
|
|
Tried anything yet?
Try something and post whatever issues you run into - someone will help you.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
CP has a huge list of articles. Check these[^] articles. Take a look at the list under Article Filters. There are a lot of things that might interest you.
|
|
|
|
|
How will we be helping you by doing your work for you? Why don't you try to build something and ask questions if you run into problems?
/ravi
|
|
|
|
|
CodeProject is huge. you will get solution with sample download. try It my friend . Code project will not disappoint you.
|
|
|
|
|
Hello,
I have created application which uses Command line arg. I made it Single Instance using Mutex. When another instance of application starts, I want command line arg should be send to first (single) instance.
I cannot use Pipelining because I am using .net 3.0 framework. Socket programming is also not permissible.
In C# form based application we can use WM_COPY, but I am not able to override WndProc in WPF.
IPC using process name would be preferred over FindWindow.
Thanks in advance.
|
|
|
|
|
You should really have asked this in the WPF forum. That's the place for WPF questions.
Pranit Kothari wrote: I am not able to override WndProc in WPF
Why not? It's as simple as:
void Window1_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper((this).Handle);
source.AddHook(new HwndSourceHook(WndProc));
}
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
} The normal way to do this though is to use a Mutex, as in:
private static Mutex mutex = new Mutex(true, "SomeUniqueIdentifierSuchAsAGuid");
private bool CheckSingleInstance()
{
return mutex.WaitOne(TimeSpan.Zero, true);
}
|
|
|
|
|
Whatever .NET version you're having, you can use pipes using P/Invoke, i.e. calling the native Win32 functions directly. You would need CreateNamedPipe, CloseHandle, ConnectNamedPipe, DisconnectNamedPipe, ReadFile, WriteFile, CreateFile; and you don't need to override WndProc, you can have a separate thread reading from the pipe. That is how I did singleton apps right from the start. A class that does it all would take some 200 lines of code.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Hello,
How can I see the SQL generated by DataAdapter.Update(dataset) - if any.
Here's a bit of context: I have a (typed) table adaptor (generated using Visual C# 2008) that fills a table from a query on a join (i.e. select all rows from a table that have a counterpart in another table). I managed to handle insertions (i.e. insert in the other table). Now for deletion...I set the DeleteCommand. I remove all the rows from the dataset and I call Update(). Nothing happens. Not even an exception. Either there's a problem with my DeleteCommand or it's never called. How can I find out ?
Thanks,
Jean-Louis
|
|
|
|
|
Start the Sql profiler and connect to the server that you want to trace. Alternatively, you could add a trace yourself.
Start here[^]
I are Troll
|
|
|
|
|
I don't have SQL Profiler at the moment, I was wondering if it's possible to do it from within the program, e.g. if there is a logging facility built in datasets.
J-L
|
|
|
|
|
AFAIK not, but you should be able to start a trace using TSQL-commands, without having the Profiler. The statements are listed here[^], with some short explanation.
I are Troll
|
|
|
|
|
DataAdapters can only do very simple things -- e.g. working with only one table, with a primary key -- I don't think they have the smarts to Update joined data.
Experienced developers don't use them.
|
|
|
|
|
> DataAdapters [...] -- I don't think they have the smarts to Update joined data.
That's why I provide an InsertCommand (which works fine) and a DeleteCommand (which isn't called ). I won't need an UpdateCommand because I'm actually managing two listboxes to update an underlying link table.
> Experienced developers don't use them.
I'm not that experienced yet I'm learning and trying to do things the proper .NET way, e.g. use DataSets instead of raw SQL. Also, typed datasets look like a good idea.
What would you recommend ?
J-L
|
|
|
|
|
Jean-Louis Leroy wrote: the proper .NET way, e.g. use DataSets instead of raw SQL.
That's the lazy way; it leads to poor quality and frustrations like you have now.
Jean-Louis Leroy wrote: What would you recommend ?
Just use SQL; it sounds like you know how.
Read this[^].
|
|
|
|