From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Occasional Nugget 01/26/2012

It's been a while since I've posted one of these.  But I discovered this trick earlier this week (which ended up being the solution to a tricky UI issue I had), so I had to share it.  Have you ever noticed the "Byte Offset from Point" method of the String class?

 

byteoffset.png

 

Yeah, I hadn't noticed it either.  But it turns out that this nifty little method will tell you which character is being displayed in a string control at a particular coordinate.  In my case, I was drawing a string image within a picture control, and I needed to know when the user was hovering over certain text in the picture with his mouse.  So I took the mouse coordinates over the picture, converted them into coordinates on a dummy string control I had in another VI with the same text in it, and got the hovered-over character.  Pretty cool!

 

This method has been publicly available since at least LabVIEW 8.6...I didn't check any earlier.  The demo VI (saved in 8.6) is attached below. 

Message 1 of 15
(7,140 Views)

Weird!

=====================
LabVIEW 2012


0 Kudos
Message 2 of 15
(7,132 Views)

I fell into and out of love with this one.  To see one reason why move the mouse to the far right of the first line.

Message 3 of 15
(7,125 Views)

@Darin.K wrote:

I fell into and out of love with this one.  To see one reason why move the mouse to the far right of the first line.


Hah, I hadn't noticed that.  Well, rough around the 'edges' I guess.  (groan)

 

Thankfully this issue doesn't seem to affect my picture control use case.

Message 4 of 15
(7,119 Views)

Is that a bug?

 

I guess as a workaround you could detect which line the mouse is on, get that line, then check if the character is the first one in the next line and not the last character of the current line.

=====================
LabVIEW 2012


0 Kudos
Message 5 of 15
(7,117 Views)

@Steve Chandler wrote:

Is that a bug?


I just filed CAR 335004 about this issue.  So for now, anyway, it's a bug.  🙂

0 Kudos
Message 6 of 15
(7,106 Views)

@Steve Chandler wrote:

Is that a bug?

 

I guess as a workaround you could detect which line the mouse is on, get that line, then check if the character is the first one in the next line and not the last character of the current line.


 

I think that was what Darren was think when he wrote "(grone)".

 

 

Ben

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 7 of 15
(7,100 Views)

@Ben wrote:


 

I think that was what Darren was think when he wrote "(grone)".

 

 


I wish, actually he was referring to the quite bad pun that proceeded "groan".  Once again people, I try to tell you that comedy is best left to us trained professionals.  Smiley Very Happy

Message 8 of 15
(7,091 Views)

@Darin.K wrote:

@Ben wrote:


 

I think that was what Darren was think when he wrote "(grone)".

 

 


I wish, actually he was referring to the quite bad pun that proceeded "groan".  Once again people, I try to tell you that comedy is best left to us trained professionals.  Smiley Very Happy


So of course I had to look.

 

A trained C-el could do better (Groan)


"Should be" isn't "Is" -Jay
0 Kudos
Message 9 of 15
(7,081 Views)

Hello Darren,

I missed your weekly nuggets so much!

Good to see you back!

Sletrab

 

Message 10 of 15
(7,011 Views)