1
양식에 채워진 텍스트 상자 만 인쇄하고 그 근처에 레이블을 인쇄 할 수있는 코드를 작성하려고합니다. 아래의 코드를 검색하여 최종 결과라고 생각했습니다. 나는 어쩌면 내가 너희들의 도움이 필요합니다, 지금까지 멀리 용액으로부터 갔다 왜 모르겠어요채워진 텍스트 상자와 그 주변의 레이블 만 어떻게 인쇄합니까?
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
'===============================================================================================
Dim name As String
Dim cc As Integer
Dim f As New Font("Times New Roman", 14, FontStyle.Underline)
Dim b As New SolidBrush(Color.Black)
Dim c As Integer = 60
'search for filled textboxes
For Each ctrl In Me.TabControl1.TabPages(0).Controls
If (TypeOf ctrl Is TextBox) Then
If CType(ctrl, TextBox).Text.Length > 0 Then
e.Graphics.DrawString(CType(ctrl, TextBox).Text, f, b, 30, c)
c = c + 30
If c > 60 Then
Exit For
End If
End If
End If
Next
'======================================================
'to know if previuos for loop actualy find any
If c > 60 Then
' to be print over textboxes if are there
e.Graphics.DrawString(Label6.Text, f, b, 16, 30)
End If
'======================================================
' this one to find out the name of the control wich found filled
For Each ctrl In Me.TabControl1.TabPages(0).Controls
If (TypeOf ctrl Is TextBox) Then
If CType(ctrl, TextBox).Text.Length > 0 Then
name = ctrl.Name
e.Graphics.DrawString(name, f, b, 0, c)
End If
End If
Exit For
Next
'and this step to print the label with its textbox
If name = "TextBox2" Then
e.Graphics.DrawString(Label1.Text, f, b, 0, c)
ElseIf name = "TextBox3" Then
e.Graphics.DrawString(Label2.Text, f, b, 0, c)
ElseIf name = "textbox4" Then
e.Graphics.DrawString(Label3.Text, f, b, 0, c)
ElseIf name = "textbox5" Then
e.Graphics.DrawString(Label4.Text, f, b, 0, c)
End If
End Sub
vb.net 2008을 사용하고있다?
입니다. 이는 단지 눈부신입니다. "레이블 = Controls.Find (labelName, True)"로 표시된 "dim labelControl"에서 "value of type 'System.Windows.Forms.Control의 1 차원 배열을'시스템으로 변환 할 수 없습니다. '라는 문제를 해결했습니다. Windows.Forms.Label ' "괜찮은 것 같아요. –
코드를 업데이트했습니다. Actully find는 배열을 반환합니다. 그래서 당신은 같은 원소로부터 단지 0 번째 원소만을 취해야합니다. 지금 시도해보십시오. –
ITS WORKS 고맙습니다. 고맙습니다. SACHIN은 (는) 깊은 문제에서 벗어나겠습니다. –