RichTextBox.AllowDrop 속성
컨트롤에서 끌어서 놓기 작업을 수행할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Overrides Property AllowDrop As Boolean
‘사용 방법
Dim instance As RichTextBox
Dim value As Boolean
value = instance.AllowDrop
instance.AllowDrop = value
public override bool AllowDrop { get; set; }
public:
virtual property bool AllowDrop {
bool get () override;
void set (bool value) override;
}
/** @property */
public boolean get_AllowDrop ()
/** @property */
public void set_AllowDrop (boolean value)
public override function get AllowDrop () : boolean
public override function set AllowDrop (value : boolean)
속성 값
컨트롤에서 끌어서 놓기 작업을 수행할 수 있으면 true이고, 그렇지 않으면 false입니다.
예제
다음 코드 예제에서는 RichTextBox 컨트롤에 놓을 항목이 포함된 ListBox 컨트롤을 사용하여 끌어서 놓기 작업을 수행하는 방법을 보여 줍니다. RichTextBox에서 끌어서 놓기 작업을 수행할 수 있도록 폼의 생성자는 AllowDrop 속성을 true로 설정합니다. 다음 예제에서는 DoDragDrop 메서드를 호출하여 끌기 작업을 시작하도록 ListBox의 MouseDown 이벤트를 사용합니다. 다음 예제에서는 DragEnter 이벤트를 사용하여 RichTextBox로 끌어 오는 항목이 유효한 데이터 형식인지 여부를 확인합니다. DragDrop 이벤트는 RichTextBox 내의 현재 커서 위치에 RichTextBox 컨트롤로 끌어 온 항목을 실제로 놓습니다. 이 예제를 실행하려면 DragDrop 및 DragEnter 이벤트가 이 예제에 정의된 이벤트 처리기에 연결되어 있어야 합니다.
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
richTextBox1.AllowDrop = True
End Sub
Private Sub listBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles listBox1.MouseDown
' Determines which item was selected.
Dim lb As ListBox = CType(sender, ListBox)
Dim pt As New Point(e.X, e.Y)
'Retrieve the item at the specified location within the ListBox.
Dim index As Integer = lb.IndexFromPoint(pt)
' Starts a drag-and-drop operation.
If index >= 0 Then
' Retrieve the selected item text to drag into the RichTextBox.
lb.DoDragDrop(lb.Items(index).ToString(), DragDropEffects.Copy)
End If
End Sub 'listBox1_MouseDown
Private Sub richTextBox1_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragEnter
' If the data is text, copy the data to the RichTextBox control.
If e.Data.GetDataPresent("Text") Then
e.Effect = DragDropEffects.Copy
End If
End Sub 'richTextBox1_DragEnter
Private Sub richTextBox1_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles richTextBox1.DragDrop
' Paste the text into the RichTextBox where at selection location.
richTextBox1.SelectedText = e.Data.GetData("System.String", True).ToString()
End Sub 'richTextBox1_DragDrop
public Form1()
{
InitializeComponent();
// Sets the control to allow drops, and then adds the necessary event handlers.
this.richTextBox1.AllowDrop = true;
}
private void listBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determines which item was selected.
ListBox lb =( (ListBox)sender);
Point pt = new Point(e.X,e.Y);
//Retrieve the item at the specified location within the ListBox.
int index = lb.IndexFromPoint(pt);
// Starts a drag-and-drop operation.
if(index>=0)
{
// Retrieve the selected item text to drag into the RichTextBox.
lb.DoDragDrop(lb.Items[index].ToString(), DragDropEffects.Copy);
}
}
private void richTextBox1_DragEnter(object sender, DragEventArgs e)
{
// If the data is text, copy the data to the RichTextBox control.
if(e.Data.GetDataPresent("Text"))
e.Effect = DragDropEffects.Copy;
}
private void richTextBox1_DragDrop(object sender, DragEventArgs e)
{
// Paste the text into the RichTextBox where at selection location.
richTextBox1.SelectedText = e.Data.GetData("System.String", true).ToString();
}
public:
Form1()
{
InitializeComponent();
// Sets the control to allow drops, and then adds the necessary event handlers.
this->richTextBox1->AllowDrop = true;
}
private:
void listBox1_MouseDown( Object^ sender, System::Windows::Forms::MouseEventArgs^ e )
{
// Determines which item was selected.
ListBox^ lb = (dynamic_cast<ListBox^>(sender));
Point pt = Point(e->X,e->Y);
//Retrieve the item at the specified location within the ListBox.
int index = lb->IndexFromPoint( pt );
// Starts a drag-and-drop operation.
if ( index >= 0 )
{
// Retrieve the selected item text to drag into the RichTextBox.
lb->DoDragDrop( lb->Items[ index ]->ToString(), DragDropEffects::Copy );
}
}
void richTextBox1_DragEnter( Object^ /*sender*/, DragEventArgs^ e )
{
// If the data is text, copy the data to the RichTextBox control.
if ( e->Data->GetDataPresent( "Text" ) )
e->Effect = DragDropEffects::Copy;
}
void richTextBox1_DragDrop( Object^ /*sender*/, DragEventArgs^ e )
{
// Paste the text into the RichTextBox where at selection location.
richTextBox1->SelectedText = e->Data->GetData( "System.String", true )->ToString();
}
public Form1()
{
InitializeComponent();
//Sets the control to allow drops, and then adds the necessary
//event handlers.
this.richTextBox1.set_AllowDrop(true);
} //Form1
private void listBox1_MouseDown(Object sender, System.Windows.Forms.
MouseEventArgs e)
{
//Determines which item was selected.
ListBox lb =(ListBox)sender;
Point pt = new Point(e.get_X(), e.get_Y());
//Retrieve the item at the specified location within the ListBox.
int index = lb.IndexFromPoint(pt);
//Starts a drag-and-drop operation.
if (index >= 0) {
//Retrieve the selected item text to drag into the RichTextBox.
lb.DoDragDrop(lb.get_Items().get_Item(index).ToString(),
DragDropEffects.Copy);
}
} //listBox1_MouseDown
private void richTextBox1_DragEnter(Object sender, DragEventArgs e)
{
// If the data is text, copy the data to the RichTextBox control.
if (e.get_Data().GetDataPresent("Text")) {
e.set_Effect(DragDropEffects.Copy);
}
} //richTextBox1_DragEnter
private void richTextBox1_DragDrop(Object sender, DragEventArgs e)
{
// Paste the text into the RichTextBox where at selection location.
richTextBox1.set_SelectedText(e.get_Data().GetData("System.String", true).
ToString());
} //richTextBox1_DragDrop
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원