Fatal Shocks

May 14, 2007

How to get the Caret Position in a TextBox/TextArea using C#

Filed under: Uncategorized — Hasan Maqbool @ 6:58 am

I have been in an ultimate need of having the curson position (more appropriately caret postion) for an Urdu Auto Complete Text Aea. Finally, after a little R&D i came up with a solution. Have a look of the solution.

what I had to do is,

Import the System.Runtime.InteropServices and import the user32.dll as follows.

[DllImport(“user32.dll”)]

private static extern int getCaretPos(ref Point pt);

After importing the dll, next step is to make a method which uses this imported dll to have the cursor position.

For example, I made the method as follows

 

public Point GetCaretXYPosition
{
get

{
Point pt = Point.Empty;
GetCaretPos(ref pt);
//I have commented as i was my requirement. Not necessarily, it will be required by everyone.

//pt.X -= 100;
//pt.Y += 20;

return pt;
}
}

Thats it, it is all about how to get the cursor posistion in a TextBox/TextArea.

February 12, 2007

Ruby

Filed under: Uncategorized — Hasan Maqbool @ 10:43 am

It has been really great to have a scripting language like Ruby. It is really great to work in Ruby. Ruby is so dynamic. It has got the potential to break the high walls of conventional programming styles. You don’t need to declare variables in the conventional Programming Language styles. Syntax is quite elegant.

For example, if somone wants to put something on the console

Say I want to put my name in there, what I need to do is

>>puts “Hasan Maqbool”

and it will work.

Similarly, strings are so much powerful like you can say,

>>”Hasan Maqbool”.length

Output on the console will be 13.

This statement returns the length of the string which invoked the method. There are many more string methods like reverse.

>>”Hasan”.reverse

it reverses the strings like nasaH etc.

Blog at WordPress.com.