X
XmlAdoNewbie
Hi All,
I would like to put a method for copy, cut and paste into my
application and this seems to be easy enough except that it's not
working the way i would like it to, I thought someone might be able to
give me a bit of insight and for that I say Thank You in advance!
this is what I have so far.
private void CutText()
{
try
{
Clipboard.SetDataObject(this.ActiveControl.Text);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
private void PasteText()
{
try
{
// Create a new instance of the DataObject interface.
IDataObject data = Clipboard.GetDataObject();
// If the data is text, then set the text of the
// control to the text in the Clipboard.
if (data.GetDataPresent(DataFormats.Text))
this.ActiveControl.Text = data.GetDataDataFormats.Text).ToString();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
private void CopyText()
{
try
{
Clipboard.SetDataObject(this.ActiveControl.Text);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
Here is my problem.
Firstly, I am assuming that the "activecontrol" has a text property
which by all rights it may not. I haven't had an error yet however.
Secondly, I can copy and cut ALL the text in the activecontrol but i
can't copy or cut the "SelectedText" for instance, if my activecontrol
says "Hello World" i can't select "World" and just copy what i have
selected. It takes the whole string.. the same goes for cutting the
text.
If anyone has any insight about this that would be great. It seems
fairly trivial however I am just a beginner with C# and would like to
do it the "right" way!
Thank you
Erin
I would like to put a method for copy, cut and paste into my
application and this seems to be easy enough except that it's not
working the way i would like it to, I thought someone might be able to
give me a bit of insight and for that I say Thank You in advance!
this is what I have so far.
private void CutText()
{
try
{
Clipboard.SetDataObject(this.ActiveControl.Text);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
private void PasteText()
{
try
{
// Create a new instance of the DataObject interface.
IDataObject data = Clipboard.GetDataObject();
// If the data is text, then set the text of the
// control to the text in the Clipboard.
if (data.GetDataPresent(DataFormats.Text))
this.ActiveControl.Text = data.GetDataDataFormats.Text).ToString();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
private void CopyText()
{
try
{
Clipboard.SetDataObject(this.ActiveControl.Text);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
Here is my problem.
Firstly, I am assuming that the "activecontrol" has a text property
which by all rights it may not. I haven't had an error yet however.
Secondly, I can copy and cut ALL the text in the activecontrol but i
can't copy or cut the "SelectedText" for instance, if my activecontrol
says "Hello World" i can't select "World" and just copy what i have
selected. It takes the whole string.. the same goes for cutting the
text.
If anyone has any insight about this that would be great. It seems
fairly trivial however I am just a beginner with C# and would like to
do it the "right" way!
Thank you
Erin