简体   繁体   English

拖放标签文字Vb.net

[英]Drag & Drop label text Vb.net

Hello all: iam using WPF to create some controls, right now iam just testing with a simple control that consist in a Rectangle and a Stack Panel with Two labels in it. 大家好:iam使用WPF创建了一些控件,现在iam只是使用一个简单的控件进行测试,该控件包含一个Rectangle和一个带有两个标签的Stack Panel。 I followed the Drag and Drop Operation sample http://msdn.microsoft.com/en-us/library/hh144799.aspx which allows to drag the control to obtain its information (Color) and drop it to another one. 我遵循了拖放操作示例http://msdn.microsoft.com/zh-cn/library/hh144799.aspx ,该示例允许拖动控件以获取其信息(颜色)并将其拖放到另一个控件上。 I want to do the same, but in this time instead of droping the color i want to drop the text of the label. 我想做同样的事情,但是这次我不想删除颜色,而是要删除标签的文本。 For example in the first control i have two labels: is "Channel" and "Type", so i want that with the D&D replace the labels from second control to change its info to " Channel x" or "type x" 例如,在第一个控件中,我有两个标签:是“ Channel”和“ Type”,所以我希望用D&D替换第二个控件中的标签,以将其信息更改为“ Channel x”或“ type x”

First Control: 第一控制:

<UserControl x:Class="BxCtrl"
             .......
             .....
             AllowDrop="True">
    <Grid Width="150" Height="150">

<Rectangle x:Name="Box" Fill="gray" MouseMove="Box_MouseMove" RadiusX="8" RadiusY="8" Grid.Row="0" />
        <StackPanel>
            <Label Content="Channel" Width="auto" Height="28.093" Margin="25,15,67.133,15" Name="label"/>
            <Label Content="Type" Width="42.933" Height="28.093" Margin="25,20,0,20" HorizontalAlignment="Left" Name="label1"/>
        </StackPanel>

and a second one exactly the same 和第二个完全一样

<UserControl
...
...
x:Class BxCtrl1
AllowDrop="True"
<Grid Width="150" Height="150">
        <Rectangle x:Name="Box1" Fill="#FFCABFD5" RadiusX="8" RadiusY="8" MouseMove="Box1_MouseMove" Tag="hoola" />
        <StackPanel HorizontalAlignment="Left" Width="150" Name="StackPanel1">
            <Label Content="1" Width="auto" Height="28.093" Margin="25,15,67.133,15" Name="labelBox1"/>
            <Label Content="1" Width="42.933" Height="28.093" Margin="25,20,0,20" HorizontalAlignment="Left" Name="label1Box1"/>
        </StackPanel>                       
    </Grid>

according to the document for the drag and drop operation i have to create the objects i want to send with a dataObject so i suppose that i have to create a dataObject for the label? 根据用于拖放操作的文档,我必须创建要与dataObject发送的对象,所以我想必须为标签创建dataObject?

Private Sub Box_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs)
    'TODO: Add event handler implementation here.
    MyBase.OnMouseMove(e)
    If e.LeftButton = MouseButtonState.Pressed Then
        Dim data As New DataObject
        data.SetData(DataFormats.StringFormat, Box.Fill.ToString())
        data.SetData("Double", Box.Height)
        data.SetData("Object", Me)
        data.GetText()

        DragDrop.DoDragDrop(Me, data, DragDropEffects.Move)
    End If
End Sub

i use the GetText(), but i dont know how to send it, anyone has idea of how to drop a label text into another one?. 我使用GetText(),但是我不知道如何发送它,任何人都知道如何将标签文本放入另一个文本中。

What you have done is stuff your information in the DataObject so it can be reteived later when you handle the drop even in the other control. 您所做的就是将您的信息填充到DataObject中,以便以后在其他控件中处理放置操作时也可以检索它。 Read on in the tutorial and you will see they implement a "OnDrop" event and the key here is that the data you suffed in there comes out in 在教程中继续阅读,您将看到它们实现了“ OnDrop”事件,这里的关键是您在那里输入的数据来自

byval e As System.Windows.DragEventArgs
...
Dim dataString As String = e.Data.GetData(DataFormats.StringFormat)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 (VB.NET + WPF)在Scrollviewer中拖放堆栈面板元素(以允许用户排序​​)? - (VB.NET + WPF) Drag + Drop (to allow user sorting) of stackpanel elements within a Scrollviewer? 拖放从C#到VB.NET的Datagrid WPF代码转换行 - Drag and Drop rows of Datagrid WPF Code convertion from C# to VB.NET WPF (vb.net) 从 web 页面到标签/文本块的文本 - WPF (vb.net) Text from web page to label/text block 如何在WPF,VB.NET中更改文本框中的文本和标签以与滑块中的滑块值相对应 - How to change text in textbox and label acording to slider value in slider in WPF, VB.NET 拖放文本重复 - Drag and Drop Text Duplication 如果wpf和vb.net中的label属性之一更改,则该属性可以应用于所有标签 - property can be apply to all label if one of the label property change in wpf and vb.net 谁在vb.net wpf格式的文本框中写乌尔都语 - who to write Urdu in text box in vb.net wpf form 如何在WPF vb.net应用程序中将自动换行文本设置为TextBlock - How to Set Wrap Text To TextBlock in WPF vb.net application 如何在Data.net中添加DataGrid列并在VB.net WPF中显示TextBox,label或Grid footer中的结果? - How to SUM DataGrid column and show result in TextBox, label or a Grid footer in VB.net WPF? 将DataGrid Column标题拖放到标签上? - Drag DataGrid Column header and drop onto a label?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM