LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Prevent scroll on text selection drag

Solved!
Go to solution

Background:

If the text in a string control/indicator exceeds the size of the front panel element, it is possible to scroll the text by selecting with the mouse and dragging towards the boundary. This happens regardless of whether the horizontal/vertical scrollbar(s) are visible. Normally, this is a useful behavior, but I'm actually trying to find a way to prevent it from happening in LabVIEW 2016.

 

I have a UI that includes a multi-line string  and other elements that need to have their scroll positions remain in sync. I can catch and handle most other ways of scrolling, but not this one, and it causes things to get out of sync. Does anyone know of a property or way of customizing the control to stop triggering a scroll when the mouse is dragged to the edges?

I've considered other workarounds (like polling during a mouse-down and discarding near the edges) but it hasn't worked well, and has made it difficult to select text at the boundaries.

0 Kudos
Message 1 of 12
(4,007 Views)

I don't understand your requirements.  You want to disable a click/drag scrolling method but still allow the user to interact with the control?  How does the user select a row of text that extends beyond the boundary of the control?  How do they place their cursor at the end of a long line of text, if the horizontal scrollbar is not visible? 

 

If you are only interacting with the control programmatically, you could disable the control so that the user can't interact with it at all. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 12
(3,977 Views)

Hi aputman,

 

Thanks for the reply despite my poor description of the problem.

Here is a screenshot of the UI I am working on (I can't share the source code at this time) :

image.png

There are three panes: the left holds a listbox to show line numbers, the right holds an independent scrollbar, and the middle holds a string control with a visible horizontal scrollbar and no vertical scrollbar. Data can be added to the string by the user or programmatically. I need the vertical scroll position to stay synchronized for the UI to make sense.

Using mouse wheel events on the panes, value change events on the independent scrollbar, and key down events on the string, I can control almost all of the scroll behavior to my liking so that things stay in sync. But the drag/scroll behavior while selecting text does not seem to produce any event that I can use to keep things in sync -- hence, my question about preventing this behavior.

 

In fact, an equal (or better) solution would be finding some way to catch an event when the drag/scroll behavior when selecting text occurs.

0 Kudos
Message 3 of 12
(3,971 Views)

Is there a reason you can't use a multicolumn listbox or a tree?  Just wondering if there is a method to accomplish your goals that is much less Rube'esque.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 12
(3,967 Views)

Agreed on the Rube'esque-ness of this approach... it seemed simple at first but exposed a bunch of edge cases for UI logic, like the one that prompted my posting of this thread.


The reason I stayed away from some of the other front panel elements you suggested is that I still want the middle pane to 'feel' like a string/notepad when editing at run-time. This whole UI is being used in a macro/script recording and creation utility for my application.

In my early prototyping, trying to make a multicolumn listbox (e.g.) act like a string when editing at run-time was hard and would have introduced a different set of complexities and edge cases for the UI logic.

0 Kudos
Message 5 of 12
(3,960 Views)
Solution
Accepted by topic author JLJ

Give this a shot. Basically, when you have a MouseDown event, set the timeout for your Event handler to 50 ms (or 100 or whatever) and poll the Text.ScrollPos property continually until you get a MouseUp event. Kinda cludgy, but it works.

 

Also: this is an ideal case to wrap up all of the clunky Event handling inside a QControl 🙂

Message 6 of 12
(3,947 Views)

Thanks Bert, that gets me closer to the desired behavior than my other cludgy attempts. A little bit of rubber-banding as the UI catches up via the timeout, but may be good enough to live with unless another solution presents itself.

 

Funny that you should mention QControls! They were actually the inspiration for this, after I ditched an XControl prototype.

With the composite nature of the UI (multiple controls and decorations), I wasn't sure if a QControl was quite the right fit though.

In the end, I borrowed some ideas from that paradigm but in this case built all of the event handling and UI logic into a VI that will be presented in a subpanel.

0 Kudos
Message 7 of 12
(3,943 Views)

I was able to implement a multi-control Qcontrol by adding more Control references to the Initialize functions, and it works quite well so far. There's still just the one event handler that handles everything. You can only get the inheritance from one of the controls, which is unfortunate, but it's not bad.

 

On my machine with limited text a 50ms refresh seemed to not show too much rubberbanding. You might need more or less if you have some enormous strings or something.

 

Edit: Just thought of another potential way to handle this. If you filter the MouseDown? event, you could simulate text highlighting with MouseMove events and the String.Text.Selection.Start and String.Text.Selection.End properties. You'd have to manually figure out where the cursor is pointing though, which I *think* can be done with the ByteOffsetFromPoint invoke node method.

0 Kudos
Message 8 of 12
(3,940 Views)

OK, this one works without polling, but it's a tiny bit glitchy. I'm not entirely sure why.

 

I think a simpler method might be to poll ScrollPos on MouseEnter, MouseLeave, and MouseMove, as it seems to only scroll when moving. In other words, if you hold your mouse still at the corner of the string, it doesn't keep scrolling (like in MS Word or an internet browser).

Message 9 of 12
(3,931 Views)

I would recommend to look around and see if you can find a .NET text editor control with line number display.  .NET RichTextBox does not have this functionality but I'm willing to bet that someone has implemented it.

 

I think a classic table with visible row headers doesn't look half bad and you don't have to deal with the glitchiness of a synchronized scrolling string control.  You would need to implement some things in code but shouldn't be too bad.  

2019-06-25_15-36-29.png

You may also want to add kudos to this idea as well.

https://forums.ni.com/t5/LabVIEW-Idea-Exchange/String-control-indicator-constant-with-line-number-di...

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 10 of 12
(3,915 Views)