PDA

View Full Version : سوال: مشکل با چاپ متن در TextBox



MTK2010
دوشنبه 14 تیر 1389, 16:15 عصر
سلام دوستان من با VisualBasic 2008 کار میکنم

موقه‌ پرینت گرفتن از Textbox باید محتوای نوشتاری Textbox سمت راست Output بشه‌ که‌ نمیشه‌ ( محتوای نوشتاری TextBox سمت چپ Output میشه‌ ).



My TextBox1.Text Properties


Right to Left : Yes
Text Align : Right

لطفا پروژه‌ رو گذاشتم یکی زحمت تصحیحش رو بگردن بگیره‌ ، ممنون میشم اگه‌ برادری زحتمش رو متقبل بشه‌.

http://www.4shared.com/file/sxdiBicc/PrintTextBox.html









Imports System.Drawing.Printing
-----------------------------------------------
Public Class DataForm



Private Sub printText(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
ev.Graphics.DrawString(TextBox1.Text, New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 120, 120)
ev.HasMorePages = False
End Sub
.
.
.
.
.


Private Sub BTNPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNPrint.Click
Try
Dim prindoc As New PrintDocument
AddHandler prindoc.PrintPage, AddressOf Me.printText
prindoc.Print()
Catch ex As Exception
MessageBox.Show("Error", ex.ToString())
End Try
End Sub

MTK2010
سه شنبه 15 تیر 1389, 12:15 عصر
لطفایکی جواب بده‌ ناسلامتی اینجا انجمن برنامه‌ نویسها است. :عصبانی++:

nasim bahari
سه شنبه 15 تیر 1389, 15:43 عصر
زبان win رو فارسی کن..................

راستی چرا از microsoft reporter یا cristal reporter استفاده نمی کنی.......

a1b2uu
سه شنبه 22 تیر 1389, 11:21 صبح
دوست عزیز من از کد استفاده کردم شاید به دردت بخوره

Private myReader As StringReader
Protected Sub ThePrintDocument_PrintPage(ByVal sender As Object, ByVal ev As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim linesPerPage As Single = 0
Dim yPosition As Single = 0
Dim count As Integer = 0
Dim leftMargin As Single = ev.MarginBounds.Left
Dim topMargin As Single = ev.MarginBounds.Top
Dim line As String = Nothing
Dim printFont As Font = Me.Txtpres.Font
Dim myBrush As New SolidBrush(Color.Black)
' Work out the number of lines per page, using the MarginBounds.
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics)
' Iterate over the string using the StringReader, printing each line.
line = myReader.ReadLine()
While count < linesPerPage And (Nothing <> line)
' calculate the next line position based on
' the height of the font according to the printing device
yPosition = (topMargin + (count * printFont.GetHeight(ev.Graphics)))
' draw the next line in the rich edit control
ev.Graphics.DrawString(line, printFont, myBrush, leftMargin, yPosition, New StringFormat())
count += 1
line = myReader.ReadLine()
End While
' If there are more lines, print another page.
If Not (line Is Nothing) Then
ev.HasMorePages = True
Else
ev.HasMorePages = False
End If
myBrush.Dispose()
End Sub 'ThePrintDocument_PrintPage
Private Sub Btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnprint.Click
PrintDialog1.Document = PrintDocument1
Dim strText As String = Me.Textbox1.Text
myReader = New StringReader(strText)
If PrintDialog1.ShowDialog() = DialogResult.OK Then
Me.PrintDocument1.Print()
End If
End Sub