TileControl.ItemClick event vs TileControl.ItemPress event - vb.net

I'm trying to figure out what the difference of a click and a press event on a devexpress tile control is.
According to the online documentation:
TileControl.ItemClick Event Fires when an end-user clicks a TileItem
within the TileControl.
...
Remarks
Handle the ItemClick event to respond to an end-user clicking any item
within the current TileControl object. You can also use handle the
TileItem.ItemClick event to respond to clicking an individual
TileItem. This event can be raised in code via the
TileItem.PerformItemClick method. The TileItem.ItemClick event is
fired before the ItemClick event.
The ItemClick event comes after the ItemPress event when the left
mouse button is released. If an item is being dragged, the ItemClick
event is never fired.
' ' ' ' ' ' ' ' ' ' '
TileControl.ItemPress Event Fires when an end-user presses a TileItem within the current
TileControl.
...
Remarks
Tile items have two event types to respond to an end-user clicking
them at runtime: item press and item click events. Immediately after
an end-user clicks a tile item, tile item press events are fired.
First, the TileItem.ItemPress event is raised. After that, the
ItemPress event is fired.
This is probably very obvious to a more experienced developer but I'm very confused about this and don't understand when to use click/press. When should I use "ItemPress"?

in vb.net when a control is clicked, it means that you have fired two events, the mousedown and the mouseup event and i think, in your case, and as mentioned in the documentation, ItemClick Remark int last section:
The ItemClick event comes after the ItemPress event when the left
mouse button is released. If an item is being dragged, the
ItemClick event is never fired.
when you release the mouse left button after pressing it, and if you have not dragged the Tile Item an Itemclick event will be fired, else the ItemPress event will be pressed.

Related

When using Selenium's click_and_hold method exactly what conditions or actions cause the mouse click to release?

I've had several occasions in my selenium tests where I decided to use Selenium's click_and_hold() (source code here) method on some element. The source code makes it look like it will stay pressed indefinitely but there are definitely some actions, such as a simple click, that cause the held click to be released. Obviously calling release will release the held click too, but does anyone have a grasp on exactly what actions/conditions (either from the script or the page itself) will cause the held click to be released?
I've linked to the documentation for the python bindings, but I assume this would be the same no matter what language is used to write the script. Please let me know if this assumption is incorrect!
release()
release(on_element) releases a held mouse button on an element. If on_element is None releases on current mouse position which is defined as:
def release(self, on_element=None):
"""
Releasing a held mouse button on an element.
:Args:
- on_element: The element to mouse up.
If None, releases on current mouse position.
"""
if on_element:
self.move_to_element(on_element)
if self._driver.w3c:
self.w3c_actions.pointer_action.release()
self.w3c_actions.key_action.pause()
else:
self._actions.append(lambda: self._driver.execute(Command.MOUSE_UP, {}))
return self
release() is invoked by default by different methods of the ActionChains implementation. Some of them are as follows:
release(): Releasing a held mouse button on an element.
drag_and_drop(source, target): Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button.
drag_and_drop_by_offset(source, xoffset, yoffset): Holds down the left mouse button on the source element, then moves to the target offset and releases the mouse button.
click_and_hold()
click_and_hold() holds down the left mouse button on an element.
So you saw it right, the source code confirms the same that it will stay pressed indefinitely unless release() is directly invoked or invoked through other methods. However there can be other actions / events which may cause the hold down left mouse button to be released implicitly. These actions / events can be a result of any of the HTML DOM Events. HTML DOM events allow JavaScript / AjaxCalls to register different event handlers on elements in an HTML document. Some of the mostly encountered events are:
HTML DOM UiEvent: Events that are triggered from the user interface belongs to the UiEvent Object.
onload Event: The onload event occurs when an object has been loaded.
onresize Event: The onresize event occurs when the browser window has been resized.
onscroll Event: The onscroll event occurs when an element's scrollbar is being scrolled.
HTML DOM FocusEvent: Events that occur when elements gets or loses focus, belongs to the FocusEvent Object.
onblur Event: The event occurs when an element loses focus
onfocus Event: The event occurs when an element gets focus
onfocusin Event: The event occurs when an element is about to get focus
onfocusout Event: The event occurs when an element is about to lose focus
The Event Object: All event objects in the DOM are based on the Event Object.
onchange Event: The onchange event occurs when the value of an element has been changed.
HTML DOM MouseEvent: Events that occur when the mouse interacts with the HTML document belongs to the MouseEvent Object.
onmousedown Event: The onmousedown event occurs when a user presses a mouse button over an element.
onmouseup Event: The onmouseup event occurs when a user releases a mouse button over an element.
HTML DOM DragEvent: Events that occur when elements are dragged and/or dropped, belongs to the DragEvent Object.
ondrag Event: The ondrag event occurs when an element or text selection is being dragged.
ondragstart Event: The ondragstart event occurs when the user starts to drag an element or text selection.
HTML DOM TransitionEvent: Events that occur when a CSS transition runs, belongs to the TransitionEvent Object.
transitionend Event: The event occurs when a CSS transition has completed
key_up()
The key_up() method also releases a modifier key. As an example:
ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()
This usecase
Without any visibility to your usecase of implementing click_and_hold() it is to be noted that, key_down() is a method which performs a modifier key press and it does not release the modifier key and subsequent interactions may assume it's kept pressed. Note that the modifier key is never released implicitly. Either key_up(theKey) or send_keys(Keys.NULL) must be called to release the modifier.
Generally any action that results in a mouse up event being called.
Click will call a mouse down event and then a mouse up event (As shown in the Code)
Click_and_hold() will only perform the mouse down part. If you then call anything else that triggers the mouse up event, the mouse click will be released.
Remember selenium is just passing a list of actions over to the driver binary that is controlling the browser using the JSON wire protocol. The commands you use in code are translated into JavaScript actions before being passed over the wire so the driver binary controlling the browser probably doesn't have much in the way of context of exactly what the original commands before they were broken down were.

Adding event handlers to object

Is there a way to add keydown and keyleft event handler to image object in a user form? I can only see mouseup/down/move,error,dragover,dropandpaste.
I notice with an option button, the event keydown/keyleft is available but not for image.
Thanks in advance
You can't add event handlers that don't exist for that control type (other than by subclassing, but the image control doesn't receive focus anyway), but an image control can't receive the focus, and therefore can't receive keystrokes anyway.
You talk about KeyDown and KeyLeft events. While some controls have KeyDown, KeyPress and KeyUp events, there aren't any controls that have a KeyLeft event. Do you perhaps mean to capture the KeyDown event, and then detect whether the Down arrow or Left arrow was the key that pressed down?
However, there are a few options:
Wire up the KeyDown or KeyPress event (depending upon which type of key information you require) for the UserForm, and then act upon the image control. This is probably only of use if you're happy for keypresses to be handled by the form, regardless of which other control might be selected.
Add a proxy control, say a TextBox that does receive KeyDown and KeyPress events, and place it behind the image control. That way, when the user tabs to the textbox, you can add a border to the image to make it look like it is selected, and then have the textbox key events act upon the image. If a user clicks on the image, instead of tabbing between controls, you can set the image's click event to give the textbox the focus, and again, handle the key events for the textbox as a proxy for the image control.
It depends on what are you trying to achieve which you didn't specify.
Image obviously doesn't have Key-events so it can't be used directly.
One possible solution could be to use Frame control which has a Picture property and has KeyDown event, so you can catch key-downs when the frame has focus. Example:
Private Sub FrameWithPicture_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
' Compare KeyCode with predefined vbKey-Constansts, e.g. for key-left:
If KeyCode = vbKeyLeft Then
' left arrow key was pressed, do somthing
Else
' all other keys were pressed, do something else
End If
End Sub
Or you could add Image control to this frame and when key-down event occurs on the frame, then perform some action on this image like this: FrameWithImage.Controls.Item(0).BackColor = vbRed etc. HTH

How can I get mouse location on a button?

VB.NET
Visual Studio
I have several buttons that I add at runtime, and I have a MouseDown event handler for the click event. Left click works just fine, but the right click event fires, but doesn't do what I need it to.
If e.Button = Windows.Forms.MouseButtons.Right Then
If sender.Bounds.Contains(e.Location) = True Then
ContextMenuStrip.Show(Cursor.Position)
End If
End If
I shortened this to make it easier to read.
When I look at e.Location, it shows the mouse location in relation to the button.
So if my button is at 400, 600, the location of the mouse should be in that area, but the mouse location comes back with 20, 30 because it is at 20,30 inside the button.
How can I do this right click event properly?
MouseDown event raises when the mouse is down on your control, so the mouse is surely in your control bounds and you don't need to check if the button contains e.Location.
To show the context menu strip, if you assign the context menu strip to ContextMenuStrip property of your control, then you don't need to do anything and the menu will show automatically. But if for any reason you want to handle MouseDown event, you can use either of these options:
ContextMenuStrip1.Show(DirectCast(sender, Control), e.Location)
ContextMenuStrip1.Show(MousePosition)
Note: Just for learning purpose if you want to check if e.Location is in your button, you can use either of these options:
Button1.ClientRectangle.Contains(e.Location)
Button1.Bounds.Contains(Button1.Parent.PointToClient(Button1.PointToScreen(e.Location)))
Or some other combinations using PointToClient, PointToScreen, RectangleToClient, RectangleToScreen methods of controls.

Detect MouseUp after Leaving MouseDown Control

Using VB.NET, Short of adding a mouseup event to every control in my form, does anybody know a way to trigger a mouseup event regardless of where the cursor is located or what control the cursor is in?
Or is there a way to see if the mouse left button is up, that way I can do on enter, if mouseup then...
Or is there a way to see if the mouse left button is up, that way I can do on enter, if mouseup then...
There is a static property on the Control class - Control.MouseButtons which returns, in the form of a flag based enum, which buttons on the mouse are currently pressed.
var pressedButtons = Control.MouseButtons;
if (!pressedButtons.HasFlag(MouseButtons.Left))
{
// Left mouse button is not down, so do stuff
}

How would I differentiate from Click and Double Click while using a C1FlexGrid

I want to use the double click and click events for c1flexgrid in vb.net, but when I double click it only goes to the click event handler and never fires the double click event.
How can I separately handle the click and double click events?
As stated in MSDN :
Pressing a mouse button when the cursor is over any particular clickable control raises the events in following order:
MouseDown event.
Click event.
MouseClick event.
MouseUp event.
MouseDown event.
DoubleClick event.
MouseDoubleClick event.
MouseUp event.
Two single clicks that occur close enough in time, as determined by the mouse settings of the user's operating system, will generate a MouseDoubleClick event instead of the second MouseClick event.
Therefore,
Check your mouse settings.