New topic: 

Inaccurate Listbox Insertion point on click

<http://forums.realsoftware.com/viewtopic.php?t=47352>

         Page 1 of 1
   [ 1 post ]                 Previous topic | Next topic          Author  
Message        jaysedai          Post subject: Inaccurate Listbox Insertion 
point on clickPosted: Wed Mar 20, 2013 5:22 pm                         
Joined: Thu Apr 06, 2006 1:19 pm
Posts: 6                Maybe there's a built in or really simple way to do 
this, but I haven't found it.  What I'm trying to do is insert the cursor 
exactly where I click in the Cell of a listbox.  Obviously if the Cell is 
already in edit mode it works fine, but this code is for clicking on any cell.  

My problem is that it doesn't seem to be calculating the variable width of some 
characters very well.  For example if the Cell contents are
2345678923456789234567892345678923456789234567892345678923456789
the character widths are pretty similar and the accuracy is pretty good. 

But if it's something more like:
WWWWWWWWWWWWWWiiiiiiiiiiiiiiiiiiiiiiiiiiiiii  
it gets off, the further you click to the right the less accurate it becomes.

Here is my hack-y code (I've been coding in RB/RS for years, but only a bit 
here and there, and I'm not a coder by trade anyway):

Code for CellClick:
dim myWidth as double
dim p as new picture(1,1,32)
dim i as integer

me.EditCell(row,column)


for i = 1 to me.activeCell.text.len
  dim charExamined as string
  dim widthCharExamined as double
  charExamined = left(me.ActiveCell.text,i)
  widthCharExamined = p.graphics.StringWidth(charExamined)
  
  myWidth = widthCharExamined
  if myWidth = x or myWidth > x then
  if i < me.ActiveCell.Text.Len then
  me.ActiveCell.SelStart = i
  me.ActiveCell.SelLength = 0
  else
  me.ActiveCell.SelStart = 0
  me.ActiveCell.SelLength = 0
  end
  Exit
  end
  me.ActiveCell.SelLength = 0
next

Any suggestions?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 1 post ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to