PDA

View Full Version : سوال: مشکل در Loop در vb2010



SaidJan
سه شنبه 02 اردیبهشت 1393, 19:27 عصر
درود
یه مشکل دارم توی ویژوال بیسیک 2010
میخوام وقتی کاربر یه اسم رو توی textbox1 وارد میکنه از اون اسم و چند مورد دیگه پرینت بگیره.

کد زیر رو نوشتم, وقتی دکمه ‍‍‍‍‍پرینت رو میزنم بار اول درست کارمیکنه ولی واسه دفعه دوم این ارور رو میده:

"make sure you have not released a resource before attempting to use it"




Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim PrintFont As New Font("Arial", 18)
Dim LineHeightSingle As Single = PrintFont.GetHeight + 2
Dim HorPrintLocationSingle As Single = e.MarginBounds.Left
Dim VerPrintLocationSingle As Single = e.MarginBounds.Top
Dim S1, S2, S3 As String
Dim us As Integer
Dim es2 As String

e.Graphics.DrawString("Title", New Font("Arial", 24), Brushes.Red, 300, 50)

Try
S2 = RadioButton1.Text
S3 = ""
If RadioButton1.Checked Then
S2 = RadioButton1.Text
ElseIf RadioButton2.Checked Then
S2 = RadioButton2.Text
ElseIf RadioButton3.Checked Then
S2 = RadioButton3.Text
ElseIf RadioButton4.Checked Then
S2 = RadioButton4.Text
End If

us = Integer.Parse(TextBox2.Text)


S1 = "Name: " & TextBox1.Text & Environment.NewLine & "Units Completed: " & us.ToString("n0") & Environment.NewLine & ListBox1.Text & Environment.NewLine & ComboBox1.Text & Environment.NewLine & S2 & Environment.NewLine & S3
e.Graphics.DrawString(S1, PrintFont, Brushes.Black, HorPrintLocationSingle, VerPrintLocationSingle)
VerPrintLocationSingle += LineHeightSingle
Catch
es2 = "Enter a number as unit."
MessageBox.Show(es2, "Error in units", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try


توی دکمه پرینت هم اینو نوشتم:

PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.Show()

خودم حدس میزنم باید یه چیزی رو توی loop بزارم که هر دفعه که دکمه پرینت زده میشه و PrintDialog میاد اسم و مشخصات رو نشون بده.

majidnazari65
سه شنبه 02 اردیبهشت 1393, 20:40 عصر
سلام.
فکر میکنم برای حل مشکل باید خط آخر رو به صورت زیر بنویسی:
PrintPreviewDialog1.ShowDialog()

دلیلش رو نمیدونم چرا وقتی از PrintPreviewDialog1.Show() استفاده میشه بعد از اینکه پنجره بسته شد dispose میشه و دیگه قابل استفاده نیست. ولی با PrintPreviewDialog1.ShowDialog این اتفاق نمی افته
از دوستان کسی میدونه دلیلش چیه؟