本文整理匯總了C#中System.Windows.Forms.IDataObject.SetData方法的典型用法代碼示例。如果您正苦於以下問題:C# IDataObject.SetData方法的具體用法?C# IDataObject.SetData怎麽用?C# IDataObject.SetData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了IDataObject.SetData方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SetData1
private void SetData1()
{
// Creates a component to store in the data object.
Component myComponent = new Component();
// Creates a data object.
DataObject myDataObject = new DataObject();
// Adds the component to the data object.
myDataObject.SetData(myComponent);
// Checks whether data of the specified type is in the data object.
Type myType = myComponent.GetType();
string myMessageText;
if(myDataObject.GetDataPresent(myType))
myMessageText = "Data of type " + myType.Name +
" is present in the data object";
else
myMessageText = "Data of type " + myType.Name +
" is not present in the data object";
// Displays the result in a message box.
MessageBox.Show(myMessageText, "The Test Result");
}
示例2: SetData2
private void SetData2()
{
// Creates a data object.
DataObject myDataObject = new DataObject();
// Stores a string, specifying the UnicodeText format.
myDataObject.SetData(DataFormats.UnicodeText, "Hello World!");
// Retrieves the data by specifying the Text format.
string myMessageText = "The data type is " + myDataObject.GetData(DataFormats.Text).GetType().Name;
// Displays the result.
MessageBox.Show(myMessageText, "The Test Result");
}
示例3: SetData3
private void SetData3()
{
// Creates a component.
Component myComponent = new Component();
// Gets the type of the component.
Type myType = myComponent.GetType();
// Creates a data object.
DataObject myDataObject = new DataObject();
// Stores the component in the data object.
myDataObject.SetData(myType, myComponent);
// Checks whether data of the specified type is in the data object.
string myMessageText;
if(myDataObject.GetDataPresent(myType))
myMessageText = "Data of type " + myType.Name +
" is stored in the data object";
else
myMessageText = "No data of type " + myType.Name +
" is stored in the data object";
// Displays the result.
MessageBox.Show(myMessageText, "The Test Result");
}
示例4: SetData4
private void SetData4()
{
// Creates a new data object.
DataObject myDataObject = new DataObject();
// Adds UnicodeText string to the object, and set the autoConvert
// parameter to false.
myDataObject.SetData(DataFormats.UnicodeText, false, "My text string");
// Gets the data format(s) in the data object.
String[] arrayOfFormats = myDataObject.GetFormats();
// Stores the results in a string.
string theResult = "The format(s) associated with the data are:" + '\n';
for(int i=0; i<arrayOfFormats.Length; i++)
theResult += arrayOfFormats[i] + '\n';
// Show the results in a message box.
MessageBox.Show(theResult);
}