How to send mousedown message to a component or control? - c#

Is there a way to send message (like mousedown) to a control?
My purpose is that when you click GridView, prevent mousedown behavior itself and bypass mousedown message to RepositoryItem.

From your question: "My purpose is that when you click GridView, prevent mousedown behavior itself and bypass mousedown message to RepositoryItem."
It sounds like you want to control the behavior of the Mouse Down event on the control. Right?
If that's the case, on the Winforms designer, look at the properties panel. On there is also a selection for the form events for a control. You can scroll down and find the Mouse Down event and add an event handler. Then do whatever filtering you need including not even processing the message at all.
You also mentioned that it's a DevExpress control. I recall that some of their controls were wired up a little differently so the DevExpress website might have some additional clues.

Related

How to know when user has a text entry control focused in other applications

The purpose is for an on screen keyboard, I would like to know if the user has focused (clicked on or tabbed into) a control that allows text input so the keyboard can optionally automatically popup. I assume there is a windows message that I hook that gives me hWind of active controls when focus changes, then perhaps there is another pinvoke that alows me to check for control type based on hWind?, unfortunately thats the extent of my knowledge on the subject.
You can get just the event when something got the focus with the GotFocus event: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus.aspx
You can apply it to all Forms.

C#: Temporarily capture OnClick event in parent control

I have a Windows Forms application and I want to be able to show a 'post-it note' type thing when the user does a specific action.
For example: The user does something which automatically hides a control.
My application should:
o Pop up a post it note which explains what happened.
o Hide the post it note again when the user clicks anywhere on the form.
I have implemented the post it note as a simple panel with a label in it, which shows and hides when specific things happen.
However, I can't seem to capture the OnClick event of the parent UserControl. The parent control is a nested control, containing a split container, one side of which contains the panel and a tab control, each of which contains a user control with various things in it.
Apart from handling the click event of every single child control, can anyone think of an event that I can capture on the parent control that I can use to hide the post it note when the user clicks anywhere in the parent control?
Thanks,
Rik
That's what the Capture property was designed to do. Set it to true when you pop up the note. Any mouse events will now be directed to your control, even if the mouse moves outside of the window. This is also the way that, for example, the combobox dropdown list works. Keep in mind that it is only good for one click.
If the popup contains any controls itself then mouse capture isn't the solution. Make it an owned form instead and simply call Close() in an event handler for the Deactivate event.
There is bubling of events in windows form, while you click on child event, the event is raised for child, and then for parent. Unless you specify "handleEvnet" property to true. So just leave it false, untill event reaches parent.

Raising event from custom control added dynamically to the form

I have a custom control that can be added multiple times to a form. There can be multiples occurrences of this custom control on the same form. These controls are added and removed by the user. The user can right click on some control inside the custom control to reveal a menu.
When selecting an item from this menu, an event should be raised on the form. I made a custom event and realized that it could't be usable if the control was added dynamically, because the form doesn't know it. I can't add an event handler referring to a control that doesn't exist. Is there some other way to raise an event on the form from custom control that doesn't require the form to know it? By the way, my custom controls are added to a FlowLayoutPanel.
Thanks for the help!
You just wire up the event handler in the code when you add the control e.g.
MyButton.Click += ButonClickEventHandler;
Page.Controls.Add(MyButton)
Agree with Ben - otherwise, there are messy ways of doing it (depending on how your control is set up). For example INotifyPropertChanged Inerface or through Windows API messaging (and listener) - but unless you have a very strange set up, then as Ben said, simply add a handler when you add the control. You can always use a generic callback method and use custom event args to identify which has triggered it.

WPF usercontrol not allowing lostfocus to change on seperate control

This one is a bit tricky to explain.
I have a usercontrol with some textboxes. I also have a menu just above this usercontrol in the same window. Whenever I tab away, the LostFocus fires correctly on the textbox, and this is what I want. Strangely enough, if I click the Menu button on top of my window, the LostFocus event does not fire on the textbox. Is there an elegant way to make sure that my menu properly allows LostFocus to fire on any controls which last had focus?
I also want to avoid having to Update BindingExpressions otherwise I would likely be doing this for N textboxes, which is undesirable.
I can't imagine it is too difficult to achieve this.. I just don't understand how this doesn't work: in most other situations LostFocus always fires.
Any ideas? Thank you.
Is the menu WPF as well or Winforms / UnManaged? If either of the two then the lost focus event does not fire. This can play havoc with WPF controls as many time a save or other data function is being performed from the menu. To counter this I have had to implement multiple ways to combat this. The easiest way was to implement a mouse leave event on the user control itself and perform any actions you require manually in code.

Drag, Drop and Delete

I have a question about drag and drop in WinForms. I know how to enable the user to drag and drop controls around inside the form, but what I'm now trying to do is enable them to drag a LinkLabel ontop of a"Recycle Bin" icon inside my Form and when it detects that something has been dropped onto the Recycle Bin icon, that control will be removed from the Form.
How would I detect if something's been dropped on another control? Would I still use Control.DragEnter & Control.DragDrop?
Thank you
yes, DragEnter and DragDrop is the right way to go, also you need to handle DragOver.
Typically, in these handler you specify what kind of drag-drop is allowed, and in DragDrop do your staff of deleting.
Here is the helpful link for you which can explain you about the DragDrop.
http://www.codeproject.com/KB/combobox/LarryDragAndDrop.aspx
You require to work on following Events:
1. MouseDown 2.DragEnter 3. DragDrop

Categories