[prev in list] [next in list] [prev in thread] [next in thread]
List: mono-winforms-list
Subject: Re: [Mono-winforms-list] MaskedTextBox.GetCharFromPosition Method
From: AATDark <AATDark () aol ! com>
Date: 2007-05-13 9:19:22
Message-ID: 1179047962.2908.6.camel () ubuntu-zero
[Download RAW message or body]
Hi
I implemented a test programm which demonstrates the GetCharFromPosition
in TextBoxBase.cs The GetCharFromPosition is running well and has the
nearly the same behavior as the MS Method.
But there is a small different: I think mono displays the font
differntly.
Yours
Berni
> Hi
>
> Attention: THIS IS NOT FOR COMMIT!!
>
> As Attachment the Testdiff file ( working fine on Windows XP .NET SP2 but
> not on mono cygwin)
> And the current GetCharFromPoint in TextBoxBase.diff
>
> Hope this helps
>
> Yours
> Berni
> -----Ursprüngliche Nachricht-----
> Von: Jackson Harper [mailto:jackson@ximian.com]
> Gesendet: Montag, 7. Mai 2007 17:55
> An: aatdark@aol.com
> Cc: mono-winforms-list@lists.ximian.com
> Betreff: Re: [Mono-winforms-list] MaskedTextBox.GetCharFromPosition Method
>
> On Sat, 2007-05-05 at 16:44 -0400, aatdark@aol.com wrote:
> > hi
> > I expirienced a major problem:
> >
> > I run my function againt the one from MS and itereatet
> > the point.X coordinate from 0 to 90
> >
> >
> > It seems to be that MS uses an other font or such thing. I testet this
> > and the only difference is the GdiCharSet=1 in mono
>
> Yes, fonts will be different between different machines. You can't rely
> on the user having the same size font on every machine. What you should
> do, is explicitly set the font size for the textbox in your tests.
>
>
> Do you mind sending your tests to the list? It's hard for me to tell
> exactly what is going on from the test output, without seeing the tests.
>
> Jackson
>
>
> > Problem: Look at the 17A and 12A.
> > In my code the A startet at the X coordinate 17 and at MS's code it
> > startet at 12
> >
> > text = "XXABCQEWRY";
> > Mono
> > 0 X
> > 1 X 2 X 3 X 4 X 5 X
> > 6 X 7 X 8 X 9 X 10 X
> > 11 X 12 X 13 X 14 X 15 X
> > 16 X 17 A 18 A 19 A 20 A
> > 21 A 22 A 23 A 24 A 25 B
> > 26 B 27 B 28 B 29 B 30 B
> > 31 B 32 C 33 C 34 C 35 C
> > 36 C 37 C 38 C 39 C 40 Q
> > 41 Q 42 Q 43 Q 44 Q 45 Q
> > 46 Q 47 Q 48 E 49 E 50 E
> > 51 E 52 E 53 E 54 E 55 E
> > 56 W 57 W 58 W 59 W 60 W
> > 61 W 62 W 63 W 64 W 65 W
> > 66 R 67 R 68 R 69 R 70 R
> > 71 R 72 R 73 R 74 Y 75 Y
> > 76 Y 77 Y 78 Y 79 Y 80 Y
> > 81 Y 82 Y 83 Y 84 Y 85 Y
> > 86 Y 87 Y 88 Y 89 Y
> >
> >
> >
> >
> >
> > MS
> > 0 X
> > 1 X 2 X 3 X 4 X 5 X
> > 6 X 7 X 8 X 9 X 10 X
> > 11 X 12 A 13 A 14 A 15 A
> > 16 A 17 A 18 A 19 B 20 B
> > 21 B 22 B 23 B 24 B 25 B
> > 26 C 27 C 28 C 29 C 30 C
> > 31 C 32 C 33 Q 34 Q 35 Q
> > 36 Q 37 Q 38 Q 39 Q 40 E
> > 41 E 42 E 43 E 44 E 45 E
> > 46 E 47 E 48 W 49 W 50 W
> > 51 W 52 W 53 W 54 W 55 W
> > 56 W 57 R 58 R 59 R 60 R
> > 61 R 62 R 63 R 64 R 65 R
> > 66 Y 67 Y 68 Y 69 Y 70 Y
> > 71 Y 72 Y 73 Y 74 Y 75 Y
> > 76 Y 77 Y 78 Y 79 Y 80 Y
> > 81 Y 82 Y 83 Y 84 Y 85 Y
> > 86 Y 87 Y 88 Y 89 Y
> >
> >
> > I used the following code
> > LineTag tag = document.FindTag(p.X,p.Y,out index,false);
> > return tag.Text()[lenght-1]
> >
> > Does anyone know an workaround ?
> >
> > Yours,
> > Berni
> >
> > -----Original Message-----
> > From: Jackson Harper <jackson@ximian.com>
> > To: aatdark@aol.com
> > Cc: mono-winforms-list@lists.ximian.com
> > Sent: Sat, 5 May 2007 8:28 pm
> > Subject: Re: [Mono-winforms-list] MaskedTextBox.GetCharFromPosition
> > Method
> >
> >
> >
> > TextControl::FindTag takes pixel coordinates and returns a line tag
> >
> > aswell as a char index.
> >
> >
> >
> >
> >
> > On Sat, 2007-05-05 at 08:45 -0400, aatdark@aol.com wrote:
> >
> > > Hi
> >
> > > I have written lots of nunit tests for the Function and they are all
> >
> > > runnning well on MS .NET 2.0
> >
> > >
> >
> > > No i'm proceding with step 2.
> >
> > >
> >
> > > for now i try to get the correct line with
> >
> > > Line line = document.GetLineByPixel(p.Y,false);
> >
> > >
> >
> > >
> >
> > > but the problem is: How can i get the char index from the position in
> >
> > > pixels?
> >
> > > I can only use the
> >
> > > LineTagToCharIndex
> >
> > >
> >
> > >
> >
> > >
> >
> > > if i know the char index.
> >
> > >
> >
> > > Because there could be different fonts. The only solution seems to be
> >
> > > to call the Grapics.MeasureText method for each letter.
> >
> > >
> >
> > > for example if the Text is:
> >
> > > HiTestText
> >
> > > I have to measure
> >
> > > H
> >
> > > Hi
> >
> > > HiT
> >
> > > HiTe
> >
> > > ...
> >
> > >
> >
> > > But this seems to be terrible slow?
> >
> > > Anyone a better solution for this ?
> >
> > >
> >
> > > Yours,
> >
> > > Berni
> >
> > >
> >
> > > -----Original Message-----
> >
> > > From: Jackson Harper <jackson@ximian.com>
> >
> > > To: aatdark@aol.com
> >
> > > Cc: mono-winforms-list@lists.ximian.com
> >
> > > Sent: Thu, 3 May 2007 8:43 pm
> >
> > > Subject: Re: [Mono-winforms-list] MaskedTextBox.GetCharFromPosition
> >
> > > Method
> >
> > >
> >
> > > On Thu, 2007-05-03 at 13:58 -0400, aatdark@aol.com wrote:
> >
> > >
> >
> > > > hi
> >
> > >
> >
> > > > concerning 1.)
> >
> > >
> >
> > > > Is there already an excisiting nunit file forthe MaskedTextBox ? I
> >
> > >
> >
> > > > can't find one
> >
> > >
> >
> > > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > You should probably start by unit testing TextBoxBase, I would just add
> >
> > >
> >
> > > your tests to TextBoxTest at first, then we can add some more to
> >
> > >
> >
> > > MaskedTextBox later. But it is best to test from the bottom up. Since
> >
> > >
> >
> > > you will have to implement this feature from the bottom up.
> >
> > >
> >
> > >
> >
> > >
> >
> > > Cheers,
> >
> > >
> >
> > > Jackson
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > yours
> >
> > >
> >
> > > > berni
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > -----Original Message-----
> >
> > >
> >
> > > > From: Jackson Harper <jackson@ximian.com>
> >
> > >
> >
> > > > To: aatdark@aol.com
> >
> > >
> >
> > > > Cc: mono-winforms-list@lists.ximian.com
> >
> > >
> >
> > > > Sent: Thu, 3 May 2007 7:17 pm
> >
> > >
> >
> > > > Subject: Re: [Mono-winforms-list] MaskedTextBox.GetCharFromPosition
> >
> > >
> >
> > > > Method
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > These methods just need to be implemented in the base TextBoxBase
> class.
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > All you should need to do is:
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > 1. Write lots of unit tests
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > 2. Implement using TextControl::LineTagToCharIndex
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > 3. Remove the notyet ifdef in MaskedTextBox
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > 4. Send your patches to the list
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > Please note, don't proceed to step 2 before completing step 1.
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > Good luck!
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > Jackson
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > On Thu, 2007-05-03 at 13:33 -0400, aatdark@aol.com wrote:
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > Hi
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > Is anyone working at the MaskedTextBox.GetCharFromPosition Method
> at
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > the moment?
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > I think implementing this will affect TextControl.cs class Document
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > too.
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > I'm going to try it if nobody is on it
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > yours
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > berni
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> ______________________________________________________________________
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > AOL now offers free email to everyone. Find out more about what's
> free
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > from AOL at AOL.com.
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > _______________________________________________
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > > http://lists.ximian.com/mailman/listinfo/mono-winforms-list
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > ______________________________________________________________________
> >
> > >
> >
> > > > AOL now offers free email to everyone. Find out more about what's free
> >
> > >
> >
> > > > from AOL at AOL.com.
> >
> > >
> >
> > > >
> >
> > >
> >
> > > > _______________________________________________
> >
> > >
> >
> > > > Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
> >
> > >
> >
> > > > http://lists.ximian.com/mailman/listinfo/mono-winforms-list
> >
> > >
> >
> > >
> >
> > >
> >
> > >
> >
> > > ______________________________________________________________________
> >
> > > AOL now offers free email to everyone. Find out more about what's free
> >
> > > from AOL at AOL.com.
> >
> > >
> >
> > > _______________________________________________
> >
> > > Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
> >
> > > http://lists.ximian.com/mailman/listinfo/mono-winforms-list
> >
> >
> >
> >
> > ______________________________________________________________________
> > AOL now offers free email to everyone. Find out more about what's free
> > from AOL at AOL.com.
> >
> > _______________________________________________
> > Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-winforms-list
["GetPosiotnTestGUI.cs" (GetPosiotnTestGUI.cs)]
using System;
using System.Windows.Forms;
using System.Drawing;
namespace winformstest
{
public class Start : Form
{
public static void Main()
{
Application.Run(new Start());
}
TextBox t;
public Start()
{
t = new TextBox();
t.Font = new Font("Times New Roman",36);
t.Text = "Hallo\r\nxxxxx\r\nThis is a sample text";
t.Multiline = true;
t.MouseClick+= new MouseEventHandler(Clicked);
t.Dock = DockStyle.Fill;
Controls.Add(t);
}
public void Clicked(object sender,MouseEventArgs args)
{
MessageBox.Show(""+t.GetCharFromPosition(new Point(args.X,args.Y)));
}
}
}
["TextBoxBase.cs.diff" (TextBoxBase.cs.diff)]
Index: TextBoxBase.cs
===================================================================
--- TextBoxBase.cs (Revision 76713)
+++ TextBoxBase.cs (Arbeitskopie)
@@ -769,6 +769,40 @@
public void Undo() {
document.undo.Undo();
}
+ public virtual char GetCharFromPosition(Point p)
+ {
+ if(p.X<0&&p.Y<0)
+ p = new Point(0,0);
+ Line line = document.GetLineByPixel(p.Y,false);
+
+ //Console.WriteLine(p+ " " +line.Text);
+ if(p.X==0)
+ return line.Text[0];
+ int index=0;
+ if(p.X<=line.tags.start)
+ p.X = line.tags.start+1;
+ //Console.WriteLine(line.tags.start);
+ LineTag tag = document.FindTag(p.X,p.Y,out index,false);
+ if(tag==null)
+ return line.Text[0];
+ //Console.WriteLine(tag + " " + index);
+ return tag.Text()[index-1];
+
+ string text = line.Text;
+ Graphics g = CreateGraphics();
+ //Console.WriteLine("\n" + line.Text + " " + p + " " +document.viewport_x + " " + this.Font);
+ for(int i =0; i< text.Length;i++)
+ {
+ SizeF size = g.MeasureString(text.Substring(0,i),this.Font);
+ size.Width +=document.viewport_x;
+ //Console.WriteLine(text.Substring(0,i) + " " +size.Width);
+ if(size.Width>p.X)
+ {
+ return text[i-1];
+ }
+ }
+ return line.Text[line.Text.Length-1];
+ }
#endregion // Public Instance Methods
#region Protected Instance Methods
@@ -1334,7 +1368,7 @@
return;
}
}
-
+
#endregion // Protected Instance Methods
#region Events
_______________________________________________
Mono-winforms-list maillist - Mono-winforms-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winforms-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic