本文介绍了如何为两个文本框分配一个文本框值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发支票打印软件,所以有些银行在第1行和第2行的收款人第2行都有收款人行。我试图将收款人文本放入两个文本框中,从下拉控件选择的收款人到我,e txtpayee1和txtpayee2。



[来自评论的EDIT OP代码]

下面是我正在尝试的方法,我的座右铭是组合框选择的文本显示为两个文本框我,e在第一个文本框中只打印10个字符,只显示在2个文本框中。

I am developing cheque printing software, so some banks have payee row in line1 and payee line2 in row2. I am trying to put payee text into both text boxes from dropdown control selected payee to I,e txtpayee1 and txtpayee2.


Below is the method that I am trying, what is my motto is combobox selected text display into two textboxes I,e in first textbox will print only 10 characters remaining display into 2textbox.

Public Sub Addpayee2()
    Try
       Dim payee2 As String = ""
       payee2 = cboAccounts.Text.ToString()

       Dim g As Graphics = cboAccounts.CreateGraphics
       Dim payee2word As String, oneLine As String
       Dim test As String = "", test1 As String = ""
       Dim p2words() As String

       If g.MeasureString(payee2, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
           oneLine = payee2
           p2words = oneLine.Split(" ")
           For Each word In p2words
               test = test & word
               If g.MeasureString(test, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
                   txtPayAgainst.Text = test1
                   GoTo l1
               Else
                   test = test & " "
                   test1 = test
               End If
           Next
l1:        txtPayAgainst.Text = test1
           txtpayee2.Text = payee2.Substring(test1.Length)
       Else
           txtPayAgainst.Text = payee2
           txtpayee2.Text = ""
       End If

    Catch ex As Exception
        MsgBox(ex.Message, , "Cheque Print")
    End Try

 End Sub

推荐答案

Dim payee2 As String = cboAccounts.Text



然后使用Length属性,它显示字符串中的字符数(不要使用MeasureString函数 - 它们用于获取具有给定字体的字符串的像素数等。)

如果它太长,请使用SubString函数:


Then use the Length property, it shows you the number of characters in the string (do not use the MeasureString functions - they are used to get the number of pixels for the string with a given font etc.).
If it's too long, make use of the SubString function:

txtPayAgainst.Text = payee2.Substring(0, 10)
txtpayee2.Text = payee2.Substring(10)


这篇关于如何为两个文本框分配一个文本框值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:47