VB.Net by API/System.Windows.Forms/DataObject — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 12:52, 26 мая 2010

DataObject.SetDate

   
Imports System.Drawing.Drawing2D
Imports System
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Math
Imports System.Xml.Serialization
Imports System.IO
Public Class MainClass
   Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1)
   End Sub 
End Class
Public Class Form1
    Private Sub frmDragRichText_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        " Give the RichTextBox some text.
        Dim txt As String = "www.vbex.ru"
        rchSource.Text = txt
        rchSource.Select(0, 0)
    End Sub

    Private Sub lblDragSource_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblDragSource.MouseDown
        " Make a DataObject.
        Dim data_object As New DataObject
        data_object.SetData(DataFormats.Text, rchSource.Text)
        lblDragSource.DoDragDrop(data_object, DragDropEffects.Copy)
    End Sub
    " Allow drop of Rtf, Text, and HTML.
    Private Sub lblDropTarget_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragEnter
        If e.Data.GetDataPresent(DataFormats.Text) Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub
    " Display whatever data we can.
    Private Sub lblDropTarget_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblDropTarget.DragDrop
        If e.Data.GetDataPresent(DataFormats.Text) Then
            lblTarget.Text = e.Data.GetData(DataFormats.Text).ToString
        Else
            lblTarget.Text = ""
        End If
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.lblTarget = New System.Windows.Forms.Label
        Me.lblDropTarget = New System.Windows.Forms.Label
        Me.lblDragSource = New System.Windows.Forms.Label
        Me.rchSource = New System.Windows.Forms.RichTextBox
        Me.SuspendLayout()
        "
        "lblTarget
        "
        Me.lblTarget.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblTarget.Location = New System.Drawing.Point(0, 232)
        Me.lblTarget.Margin = New System.Windows.Forms.Padding(3, 1, 3, 2)
        Me.lblTarget.Name = "lblTarget"
        Me.lblTarget.Size = New System.Drawing.Size(296, 28)
        Me.lblTarget.TabIndex = 11
        "
        "lblDropTarget
        "
        Me.lblDropTarget.AllowDrop = True
        Me.lblDropTarget.Anchor = CType((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.lblDropTarget.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDropTarget.Location = New System.Drawing.Point(200, 32)
        Me.lblDropTarget.Name = "lblDropTarget"
        Me.lblDropTarget.Size = New System.Drawing.Size(96, 48)
        Me.lblDropTarget.TabIndex = 9
        Me.lblDropTarget.Text = "Drop Target"
        Me.lblDropTarget.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "lblDragSource
        "
        Me.lblDragSource.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDragSource.Location = New System.Drawing.Point(0, 32)
        Me.lblDragSource.Name = "lblDragSource"
        Me.lblDragSource.Size = New System.Drawing.Size(96, 48)
        Me.lblDragSource.TabIndex = 8
        Me.lblDragSource.Text = "Drag Source"
        Me.lblDragSource.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        "
        "rchSource
        "
        Me.rchSource.AllowDrop = True
        Me.rchSource.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.rchSource.Location = New System.Drawing.Point(0, 0)
        Me.rchSource.Name = "rchSource"
        Me.rchSource.Size = New System.Drawing.Size(296, 28)
        Me.rchSource.TabIndex = 7
        Me.rchSource.Text = ""
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(296, 345)
        Me.Controls.Add(Me.lblTarget)
        Me.Controls.Add(Me.lblDropTarget)
        Me.Controls.Add(Me.lblDragSource)
        Me.Controls.Add(Me.rchSource)
        Me.Name = "Form1"
        Me.Text = "DragRichText"
        Me.ResumeLayout(False)
    End Sub
    Friend WithEvents lblTarget As System.Windows.Forms.Label
    Friend WithEvents lblDropTarget As System.Windows.Forms.Label
    Friend WithEvents lblDragSource As System.Windows.Forms.Label
    Friend WithEvents rchSource As System.Windows.Forms.RichTextBox
End Class