PDA

View Full Version : پیدا کردن موقعت cursor در textbox



adib202
یک شنبه 08 شهریور 1388, 15:55 عصر
سلام
چطور میشه موقعیت cursor رو توی text box مشخص کنیم؟
یا بهتر بگم ایندکس حرفی که کرسر کنارش هست چنده؟
ممنون از کلیه دوستان

rostamkhani
دوشنبه 09 شهریور 1388, 13:35 عصر
سلام


textBox1.SelectionStart


TextBox چندتا تابع داره که برای دریافت مکان cursor و شماره خط cursor میتونی استفاده کنی نمونه ای که گذاشتم اینو به شما نشون میده.


private void textBox1_MouseMove(object sender, MouseEventArgs e)
{
listBox1.Items.Clear();
int curentIndex = textBox1.GetCharIndexFromPosition(e.Location);
Point p = textBox1.GetPositionFromCharIndex(curentIndex);
listBox1.Items.Add("Curent Index = " + curentIndex.ToString());
listBox1.Items.Add("Location = " + p.ToString());
listBox1.Items.Add("Line Number = " + textBox1.GetLineFromCharIndex(curentIndex).ToStrin g());
listBox1.Items.Add("Curent Char = " + textBox1.Text[curentIndex].ToString());
}

adib202
پنج شنبه 12 شهریور 1388, 09:55 صبح
ممنون از راهنماییتون rostamkhani