R
Rolf Welskes
Hello,
I have tried to implement dragdrop for RichTextBox under .Net 1.1.
IMPORTANT: it must be .NET 1.1 without any service pack, because of the
distribution worldwide. 2.0 is not possible.
I have implemented a sample I found.
First there should be RichTextBox.DragEnter and RichTextBox.DragDrop events.
But it is not there. Referenece says only for internal use.
So I have implemented it bei override OnDragEnter, OnDragDrop in a derived
class from the RichTextBox-Class.
//AllowDrop is set to true.
protected override void OnDragEnter(DragEventArgs e)
{
base.OnDragEnter (e);
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy ;
else
e.Effect = DragDropEffects.None ;
}
protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop(e);
int i;
String s;
// Get start position to drop the text.
i = this.SelectionStart;
s = this.Text.Substring(i);
this.Text = this.Text.Substring(0,i);
// Drop the text on to the RichTextBox.
this.Text = this.Text +
e.Data.GetData(DataFormats.Text).ToString();
this.Text = this.Text + s;
}
this works a little, but is very indifferent.
First you start to drag and see only the non-cursor on source and on target.
Then you make the same and on the source a drag is done without to leave the
mouse button.
Then it works for a bit of text. Then again the same.
In my sample I have 2 overriden RichtTextBox-Objekts of this class. Each is
source AND target.
So this is not usable.
What is the right way.
Thank You.
Rolf
I have tried to implement dragdrop for RichTextBox under .Net 1.1.
IMPORTANT: it must be .NET 1.1 without any service pack, because of the
distribution worldwide. 2.0 is not possible.
I have implemented a sample I found.
First there should be RichTextBox.DragEnter and RichTextBox.DragDrop events.
But it is not there. Referenece says only for internal use.
So I have implemented it bei override OnDragEnter, OnDragDrop in a derived
class from the RichTextBox-Class.
//AllowDrop is set to true.
protected override void OnDragEnter(DragEventArgs e)
{
base.OnDragEnter (e);
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy ;
else
e.Effect = DragDropEffects.None ;
}
protected override void OnDragDrop(DragEventArgs e)
{
base.OnDragDrop(e);
int i;
String s;
// Get start position to drop the text.
i = this.SelectionStart;
s = this.Text.Substring(i);
this.Text = this.Text.Substring(0,i);
// Drop the text on to the RichTextBox.
this.Text = this.Text +
e.Data.GetData(DataFormats.Text).ToString();
this.Text = this.Text + s;
}
this works a little, but is very indifferent.
First you start to drag and see only the non-cursor on source and on target.
Then you make the same and on the source a drag is done without to leave the
mouse button.
Then it works for a bit of text. Then again the same.
In my sample I have 2 overriden RichtTextBox-Objekts of this class. Each is
source AND target.
So this is not usable.
What is the right way.
Thank You.
Rolf