如何将组合框文本分配到文本框中。 [英] How to Assign combo box text into textbox.
本文介绍了如何将组合框文本分配到文本框中。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试分配100个字符的组合框文本。我有两个文本框,所以在每个文本框中应尊重地显示50,50个字符。
以下是我的函数..我需要改变帮助...我是vb.net的新手
Hi, I am trying to assign combo box text which like 100 characters. and I am having two textboxes so in each textbox should display 50,50 characters respectfully.
below is my function..where I need to change kindly help...I am new for vb.net
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
Exit Sub
'txtpayee2.Text = payee2.Substring(test1.Length)
txtPayAgainst.Text = payee2.Substring(0, 10)
txtpayee2.Text = payee2.Substring(10)
Else
txtPayAgainst.Text = payee2
txtpayee2.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message, , "Cheque Print")
End Try
End Sub
推荐答案
我会像这样执行代码的内部部分:
I would do the inner part of your code like this :
Dim myItem As String = cboAccounts.SelectedItem.ToString()
Dim p2words As String() = myItem.Split(" ")
Dim testText As String = ""
Dim partText1 As String = ""
Dim partText2 As String = ""
For Each word As String In p2words
testText += " " + word
If g.MeasureString(testText.Trim, txtPayAgainst.Font).Width >= txtPayAgainst.Width Then
partText1 += " " + word
Else
partText2 += " " + word
End If
Next
txtPayAgainst.Text = partText1.Trim
txtpayee2.Text = partText2.Trim
请试一试......
Please try it ...
这篇关于如何将组合框文本分配到文本框中。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文