sethuramanV Posted September 1, 2003 Posted September 1, 2003 is it possible to move the cursor in the textbox as the mouse moves so that i can insert the dragged data at the mouse position. Regards. sethuramanV Quote
Octavo Posted September 1, 2003 Posted September 1, 2003 Hmmmm I've been working on this problem sethuramanV and I get it all to work, the only problem is figuring out at which point in the string to insert the text that has been moved. Using MousePosition, you can get the cursor's physical location on the screen, but that doesn't tell you where in the string the cursor is. Can anyone else help as this now has me intrigued as well. Come on there must be something simple that I'm missing here! Quote
Runtime_error Posted September 2, 2003 Posted September 2, 2003 well, one way of doing it wud be to store the Data in a string variable as soon as the drag begin, and then on each new X,Y , Draw the string. delete from the old , draw on new . c# private void DrawString() { System.Drawing.Graphics formGraphics = this.CreateGraphics(); string drawString = "Sample Text"; System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float x = 150.0f; float y = 50.0f; formGraphics.DrawString(drawString, drawFont, drawBrush, x, y); drawFont.Dispose(); drawBrush.Dispose(); formGraphics.Dispose(); } simple, u can either call the paint event to delete the string from the previous position or u can simply clear that specific location by drawing a Rectangle on it which is off same colour as ur background and same size as ur TEXT Quote
Runtime_error Posted September 2, 2003 Posted September 2, 2003 errm now i think i answered the question incorrectly. Are u dragging the text from the textbox? Quote
sethuramanV Posted September 2, 2003 Author Posted September 2, 2003 well thanks for the response. i am dragging a string from treeview into the textbox which already contains some text. i can get the mouse position w.r.t. the text box by Point pt = m_textBox.PointToClient(new Point(theDragEventArgs.X, theDragEventArgs.Y)); i am not able to proceed from that. all my tries became futile. Regards. sethuramanV Quote
Runtime_error Posted September 8, 2003 Posted September 8, 2003 textBox1.Text.Insert(startindex,value); I think that will do. If u can get the mouse pos then u can easily get the index of the new point where the drag ended and the above line should insert the value :) Quote
sethuramanV Posted September 8, 2003 Author Posted September 8, 2003 Thanks runtime_error for ur solution. how can i get the index of the point in the textbox from the position(point). Sorry.. if this is silly. i can't figure it out. kindly help me. Regards. sethuramanV Quote
Runtime_error Posted September 8, 2003 Posted September 8, 2003 Well, i am a newbie but one botch method of doing could be Getting the LEFT property of the text box then finding the difference between that and the Point where ur cursor was. So if ur curser is at 150px and ur text box is at 100 then ur curser is 50 pixels inside the textbox rite? Then i donnno maybe u could get the font width in pixels and divide that by the difference to get ur actuall number of Charachters in the Text box. Thats ur INDEX Value. There is probably a better way but i being a student i can only think of quick fixes :D int Pixeldifference = MousePos - TextBox.Left ; Get the Font Width Int indx = PixelDifference / FontWidth; textBox1.Text.Insert(indx,value); hope that helps Quote
Runtime_error Posted September 8, 2003 Posted September 8, 2003 oh wait thats not gonna work since each letter is of different width :( L l Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.