如何复制多个文本框文本并将该文本粘贴到其他文本框中?

时间:2015-05-23 14:11:39

标签: vb.net textbox copying pasting

我有一些文本框(9),我想从那些文本框中复制数据,所以当我按下我的访问数据库上的保存时,我可以按过去,让我以前的数据显示在新的网格线上。

这可能吗?

这是我到目前为止所拥有的

COPY BUTTON -

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    If SİPARİŞ_MUMARASITextBox.TextLength = 0 Then
        MsgBox("yok")
    Else
        Clipboard.SetText(İSİMTextBox.Text & TARİHTextBox.Text & SİPARİŞ_MUMARASITextBox.Text _
          & SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text & SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text _
          & SAYACIN_BULUNDUĞU_KAZANTextBox.Text & KUMAŞ_RENGİTextBox.Text)
    End If
End Sub

PASTE BUTTON -

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    If Clipboard.ContainsText = True Then
        İSİMTextBox.Text = Clipboard.GetText
        TARİHTextBox.Text = Clipboard.GetText
        SİPARİŞ_MUMARASITextBox.Text = Clipboard.GetText
        SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Text = Clipboard.GetText
        BOBİN_GRAMJI__gr_m2_TextBox.Text = Clipboard.GetText
        BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt_TextBox.Text = Clipboard.GetText
        BASKIDAKİ_TUR_SAYISITextBox.Text = Clipboard.GetText
        SAYACIN_BULUNDUĞU_KAZANTextBox.Text = Clipboard.GetText
        KUMAŞ_RENGİTextBox.Text = Clipboard.GetText
    Else
        İSİMTextBox.Clear()
        TARİHTextBox.Clear()
        SİPARİŞ_MUMARASITextBox.Clear()
        SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ_TextBox.Clear()
        BOBİN_GRAMJI__gr_m2_TextBox.Clear()
        BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt_TextBox.Clear()
        BASKIDAKİ_TUR_SAYISITextBox.Clear()
        BASKIDAKİ_TUR_SAYISITextBox.Clear()
        SAYACIN_BULUNDUĞU_KAZANTextBox.Clear()
        KUMAŞ_RENGİTextBox.Clear()
    End If
End Sub

1 个答案:

答案 0 :(得分:3)

使用剪贴板很可能是错误的方法。相反,您可以拥有一个类,其中包含您想要记住的每个项目的属性:

Option Infer On
' ...

Dim thingsToCopy As CopyBuffer

Public Class CopyBuffer
    Property İSİM As String = ""
    Property TARİH As String = ""
    Property SİPARİŞ_MUMARASI As String = ""
    Property SİPARİŞİN_ADI__BASKIDAKİ_BİLGİ As String = ""
    Property BOBİN_GRAMJI__gr_m2 As String = ""
    Property BOBİN_ÜZERİNDE_YAZAN_METRAJ__cmXmt As String = ""
    Property BASKIDAKİ_TUR_SAYISI As String = ""
    Property SAYACIN_BULUNDUĞU_KAZAN As String = ""
    Property KUMAŞ_RENGİ As String = ""
End Class

Private Sub bnCopy_Click(sender As Object, e As EventArgs) Handles bnCopy.Click
    If SİPARİŞ_MUMARASITextBox.TextLength = 0 Then
        MsgBox("yok")
    Else
        thingsToCopy = New CopyBuffer With
                       {.İSİM = İSİMTextBox.Text,
                        .TARİH = TARİHTextBox.Text,
                        .SİPARİŞ_MUMARASI = SİPARİŞ_MUMARASITextBox.Text,
                        .SAYACIN_BULUNDUĞU_KAZAN = SAYACIN_BULUNDUĞU_KAZANTextBox.Text,
                        .KUMAŞ_RENGİ = KUMAŞ_RENGİTextBox.Text}

    End If

End Sub

Private Sub bnPaste_Click(sender As Object, e As EventArgs) Handles bnPaste.Click
    If thingsToCopy Is Nothing Then
        ' create a new one, which will have empty text
        thingsToCopy = New CopyBuffer
    End If

    With thingsToCopy
        İSİMTextBox.Text = .İSİM
        TARİHTextBox.Text = .TARİH
        SİPARİŞ_MUMARASITextBox.Text = .SİPARİŞ_MUMARASI
        SAYACIN_BULUNDUĞU_KAZANTextBox.Text = .SAYACIN_BULUNDUĞU_KAZAN
        KUMAŞ_RENGİTextBox.Text = .KUMAŞ_RENGİ
    End With

End Sub

你似乎粘贴的东西比复制的多;你必须调整代码以适应所需的。