Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi coders, I am printing some text with two textboxes I,e txtPayAgainst and txtpayee2 my moto is to print text according to the txtbox1 width and remaining text will be print into txtpayee2.

I tried with below method but its not working according to the scenario. Please help I will be really appreaciated.
C#
        Public Sub Addpayee2()

        'Dim names() As String = cboAccounts.Text.Split(" ")
        'If names.Count > 1 Then
        '    txtPayAgainst.Text = names(0)
        '    txtpayee2.Text = names(1) + names(2) + names(3) + names(4)
        'End If
      

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

            Dim g As Graphics = cboAccounts.CreateGraphics
            Dim pword As String, poneLine As String
            Dim ptest As String = "", ptest1 As String = ""
            Dim pwords() As String

            If g.MeasureString(payee2, cboAccounts.Font).Width >= cboAccounts.Width Then

                poneLine = payee2
                pwords = poneLine.Split(" ")
                For Each pword In pwords
                    ptest = ptest & pword
                    If g.MeasureString(ptest, cboAccounts.Font).Width >= cboAccounts.Width Then
                        txtPayAgainst.Text = ptest1
                        GoTo l1
                    Else
                        ptest = ptest & " "
                        ptest1 = ptest
                    End If
                Next


l1:             txtPayAgainst.Text = ptest1

                txtpayee2.Text = payee2.Substring(ptest1.Length)

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

            Else
                txtPayAgainst.Text = payee2
                txtpayee2.Text = ""
                'txtpayee2.Visible = True

            End If

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



    End Sub
Posted
Updated 15-Jun-15 21:23pm
v3
Comments
Ralf Meier 16-Jun-15 3:34am    
Why don't you have tested the solution I have posted in the last Thread from you with the same question ?
Meer Wajeed Ali 16-Jun-15 4:34am    
Hi Ralf already I checked with last thread but yet I didn't get solution that why I re posted.
Ralf Meier 16-Jun-15 5:16am    
So ... what is the Problem ?
My posted code (correct inserted) should solve your existing Problem.
The seen code is the same as in the beginning - you don't added the necessary changes in it.
If there are circumstances with the changes I made we could talk about (my opinion).

Greetings
Ralf
Maciej Los 16-Jun-15 16:10pm    
Split on what condition?
Ralf Meier 17-Jun-15 0:44am    
@Maciej:
He splits the input-string into it's containing words.
Now he checks with a Loop if the words are matching (length) inside the first TextBox. If this TextBox is filled he want to change to the 2nd one and write the missing Content to this TextBox.
For that I gave him a solution (by another Thread) which is still not implemented in his code ...

1 solution

 Public Sub Addpayee2()

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

            Dim g As Graphics = cboAccounts.CreateGraphics
            Dim pword As String, poneLine As String
            Dim ptest As String = "", ptest1 As String = ""
            Dim pwords() As String

            If g.MeasureString(payee2, cboAccounts.Font).Width >= cboAccounts.Width Then

                poneLine = payee2
                pwords = poneLine.Split(" ")
                For Each pword In pwords
                    ptest = ptest & pword
                    If g.MeasureString(ptest, cboAccounts.Font).Width >= cboAccounts.Width Then
                        txtPayAgainst.Text = ptest1
                        GoTo l1
                    Else
                        ptest = ptest & " "
                        ptest1 = ptest
                    End If
                Next


l1:             txtPayAgainst.Text = ptest1
                txtpayee2.Visible = True
                txtpayee2.Text = payee2.Substring(ptest1.Length)

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

            Else
                txtPayAgainst.Text = payee2
                txtpayee2.Text = ""
                txtpayee2.Visible = False

            End If

        Catch ex As Exception
            MsgBox(ex.Message, , "Cheque Print")
        End Try
    End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900