I'm trying to program something to read voltage from the Labview ULx library and add the voltage into an array. I tried to do so using an event structure while setting a boolean button 's mechanical action to "Latch when pressed". However, the "Latch when pressed" option seems doesn't work and the program reads the voltage and adds it to the array correctly and it freezes.
front panel
Block diagram:
When you use a Value Changed event with a latched Boolean control, you need to read the control's value inside the event structure in order to reset the latch.
Just move the Sample control's terminal inside the event structure, then it should work as you expect.
Tip: you are free to use the Latch When Pressed action if you want, but the standard action for UI buttons in the OS (Windows etc) is actually Latch When Released. You can check this by clicking on a button, dragging the mouse pointer off the button and then releasing it - the button shouldn't operate. You might want to decide which one makes more sense for your application.
Related
I've been looking for awhile now to no avail for this.
What I'm trying to do is find a way to detect if a mouse icon changes when you mouse over something.
For example: If you mouse over a link it changes from the arrow to a finger.
My plan is to grab the ID of a window, and scan it for clickable objects based on the mouse icon changing. I can grab the window, bring it to the front, and move the mouse around by setting the x,y coord of the mouse, but I don't see a way to detect if the mouse has found anything.
I would prefer this to be something built into vb.net, but if I have to use an API I'm fine with that.
The approach is wrong because the concepts are different from what you observe visually.
There's no such thing as "click" -- there's Button Down event (Windows message sent by the GUI subsystem to the application), Button Up event and Mouse Move event. If there were Button Down and Button Up with no or little Mouse Move, then the OS considers this a click.
All events are sent to the window under the mouse cursor hotspot unless the mouse input is captured by the other window.
When the cursor is moved over the window, the OS sends WM_NCHITTEST message to the window to determine, how the window treats the area under the cursor. Based on window's response Windows either performs the window operation (window move or resize etc) or passes mouse-related events to the window procedure. The procedure then decides how to react - do nothing, make visual changes, perform some action etc.
As you can see from the description, cursor change and actual actions are two different loosely related operations. There can be an action without cursor change or cursor change without an action.
i have developed custom control which inherits Button control, actually i`m creating button with one picturebox and label on Button(picturebox and label are child controls). I created same method and wired child controls to behave as clicking on parent(Button), it works but its slow no mather what i do(tried with InvokeOnClick, me.performclick, Me.OnClick(New EventArgs()), tried with same method for all events), but clicking on label or picture box is slow, i need it to be fast as clicking directly on button cause in my application is very important to be able to click on button twice in second for example, if you click on label or picturebox twice at second it will fire just one time not 2.
What i have been thinking of is to make label and picturebox invisible for event is it possible or anyother idea ?
Thanks in forward
You are doing battle with ControlStyles.StandardDoubleClick. Which is turned on for the PictureBox and Label controls but turned off for Button.
So when you are clicking rapidly on either the picturebox or the label then they'll generate the DoubleClick event instead of the Click event. You'll interpret that as "slow" since you probably didn't write a handler for that event. Subscribing the event and calling Me.OnClick is a workaround.
Just don't do this. PictureBox and Label are point-and-click convenience controls but they are extraordinarily wasteful. It takes just two lines of code in the button's OnPaint() method override to get the exact same outcome, minus the overhead and the event problems. Use e.Graphics.DrawImage() to draw the pb's image and TextRenderer.DrawText() to draw the label's text.
Using MouseDown event ensures the event is triggered once per click, regardless of click/doubleclick.
In which situations should we use "Latch until released" instead of "Switch until released"?
According to LabVIEW 2011 Help:
Latch until released—Changes the control value when you click it and
retains the value until the VI reads it once or you release the mouse
button, depending on which one occurs last. You cannot select this
behavior for a radio buttons control.
Switch until released—Changes the control value when you click it and
retains the new value until you release the mouse button. At this
time, the control reverts to its default value, similar to the
operation of a door buzzer. The frequency with which the VI reads the
control does not affect this behavior. You cannot select this behavior
for a radio buttons control.
The documentation explains it clearly enough. Switch Until Released changes the value until you release it. It is possible, however, depending on the complexity of your VI that you push a button and release it before the value is read. In this case there would be no action taken on the new value. Latch until released guarantees that the off/on transition is read at least once.
As for which you would use them for, it depends on your situation. For most buttons where a click initiates an action you would generally use Latch until released - these are buttons where users would expect to click the button to do something or to toggle something, etc. Using Switch until released in these cases would end up with some times where the user would click the button but nothing would happen.
Switch until released is generally used for real-time type controls where you would click and hold the button to sustain an action and then release it to halt the action.
As a general guide, you might think of Latch until released as ideal for discrete operations (one click, one action) and Switch until released for analog actions (action continues while the button is down).
Another big difference is that Switch When Released and Switch When Pressed events can easily be triggered using the Val(Sgnl) property node.
This is super useful when using event-loops-as-state-machines to transition programmaticly from one event (state) to the next.
The following "explaination" from the Microsoft MSDN is sematically void to me:
Occurs when the focus or keyboard user interface (UI) cues change.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.changeuicues.aspx
Can anyone provide a substantive definition... or a resource that describes this event?
Even the following references from the MSDN don't help:
http://msdn.microsoft.com/en-us/library/system.windows.forms.uicues.aspx
OR
http://msdn.microsoft.com/en-us/library/system.windows.forms.uicueseventargs.aspx
All of these assume that the reader knows what a UI Cue is...
This event is fired when the UICues change for a control.
What is a UI Cue? Take a look at the UICuse enumeration documentation:
This enumeration is used to specify which user interface cues will be displayed or changed. For example, when the user presses the ALT key, the keyboard shortcuts on the menu are displayed by underlining the appropriate character. The bitwise combination of UICues for this example would be ShowKeyboard and ChangeKeyboard.
In other words, a UI Cue is a visual indicator for the user of the software's internal state which might not otherwise be apparent. For example (different from above), when a button has "focus" (meaning pressing the Enter or Return key will initiate the associated Click event), the OS provides a "UI Cue", usually a dotted rectangle around the edges of the button, indicating that that particular button (and not one of the others on the screen) has keyboard focus.
Without these UI Cues, the user may not have way of determining the internal state of the software, rendering the behavior unpredictable (as in, when I press Enter I won't know which button will be "clicked").
According to the documentation (follow the link above), a WinForms control supports the following cues (which can be combined using bitwise logic):
ShowFocus Focus rectangles are displayed after the change.
ShowKeyboard Keyboard cues are underlined after the change.
Shown Focus rectangles are displayed and keyboard cues are underlined after the change.
ChangeFocus The state of the focus cues has changed.
ChangeKeyboard The state of the keyboard cues has changed.
Changed The state of the focus cues and keyboard cues has changed.
None No change was made.
I have fully programmed my Minesweeper; however, I was having difficulty trying to get the same result as in the original minesweeper for when a user clicks and moves the mouse around while still right clicking. You may notice that in the original Minesweeper, when a user does as explained, the tiles that the user goes to will then look blank. If the user releases the mouse, the current tile they hovered to will become the clicked tile. In my Minesweeper, the tile I click on is the only one that will look blank, and when I hover over to the next tiles, they do not get blank like the first one I clicked on. Then when I release my mouse button when over to another tile, the very first tile I clicked on is the one that gets uncovered. Here is what I already have used. I have the MouseDown event which checks to see if the game has been started to begin the game timer. It also has some color properties for tiles when I click on them and I set a boolean to true or false depending on the user left or right click. I have the MouseUp event which looks at the boolean to determin what the user had clicked on the mouse so I know if I flag or simply click to uncover. Then I have the MouseEnter and MouseLeave which are needed to yield the proper glow I want for the tiles. What should I do to get the same results as in the original Minesweeper with the MouseDown and MouseEnter into other tiles? I tried many other things such as MouseEnter, MouseMove and MouseHover, but all seem to yield the same crummy result as what I already have.
Just another piece of information, the MouseEvents are built in to a UserControl which I then use as my tile in Minesweeper. It almost as if when an event is active, another one cannot be done at the same time.
You might want to consider, DragOver and Drag related events