Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!

Posted

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

Posted

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

Posted

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 :)

Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...