Is there a way to match the label.mousedown x and y parameter to a specific character in the string?
there may be a more elegant way, but if you need an answer this morning:
Assuming the label is left aligned…
[code] dim p as new picture (me.width, me.height)
p.Graphics.TextFont = me.TextFont
p.Graphics.TextSize= me.Textsize
dim t as string
dim char as string
dim p1, p2 as integer
dim temp as string
t = me.Text
for m as integer = 1 to len(t)-1
p1 = p.Graphics.stringwidth(left(t,m))
p2 = p.Graphics.stringwidth(left(t,m+1))
if x >= p1 and x <=p2 then
char = mid(t,m+1,1)
end if
next
msgbox char[/code]
(Oddly, I don’t see a way to change the font and size in the IDE under 2015R4, but…)
assuming label is left aligned.
[code]Function checkPosition(x as integer) As integer
dim p as new Picture(Label1.Width,Label1.Height)
p.Graphics.TextFont = Label1.TextFont
p.Graphics.TextSize = Label1.TextSize
dim theText as Text = Label1.Text.totext
dim size as integer
dim position as integer
for each char as Text in theText.Characters
size=size+ceil( p.Graphics.StringWidth(char) )
position=position+1
if size>=x then
return position
end if
next
End Function[/code]
I was too slow I Think
[quote=236994:@Rob Egal]assuming label is left aligned.
[code]Function checkPosition(x as integer) As integer
dim p as new Picture(Label1.Width,Label1.Height)
p.Graphics.TextFont = Label1.TextFont
p.Graphics.TextSize = Label1.TextSize
dim theText as Text = Label1.Text.totext
dim size as integer
dim position as integer
for each char as Text in theText.Characters
size=size+ceil( p.Graphics.StringWidth(char) )
position=position+1
if size>=x then
return position
end if
next
End Function[/code]
I was too slow I Think[/quote]
Hi. Thanks, but I get an error on dim theText as Text.
[quote=236992:@Jeff Tullin]there may be a more elegant way, but if you need an answer this morning:
Assuming the label is left aligned…
[code] dim p as new picture (me.width, me.height)
p.Graphics.TextFont = me.TextFont
p.Graphics.TextSize= me.Textsize
dim t as string
dim char as string
dim p1, p2 as integer
dim temp as string
t = me.Text
for m as integer = 1 to len(t)-1
p1 = p.Graphics.stringwidth(left(t,m))
p2 = p.Graphics.stringwidth(left(t,m+1))
if x >= p1 and x <=p2 then
char = mid(t,m+1,1)
end if
next
msgbox char[/code]
(Oddly, I don’t see a way to change the font and size in the IDE under 2015R4, but…)[/quote]
Thanks, this works. The font and size can be reached by the cog wheel icon.
Also there is no need to create picture of a specific size (me.width,me.height) for example.
just create it at any tiny size (10,10)… the answers are still the same, but the internal overhead for the dummy picture is smaller
[quote=237009:@Dave S]Also there is no need to create picture of a specific size (me.width,me.height) for example.
just create it at any tiny size (10,10)… the answers are still the same, but the internal overhead for the dummy picture is smaller[/quote]
Yes, absolutely but it help me vision-wise
You can even do (1,1) which I usually take.
I am sure it works as I did the project for. I would go for my example as it’s faster + less code.