Print Form problem
-
2011年10月31日 18:55I'm trying to utilize the print form tool. I have two, one thats print to printer and the other is print to print screen. When I use either one, my file in the menustrip is blocking out information, like it's showing the menustrip. Is there any way to get it to print just the form without the menustrip without having to put in menustrip1.visible = false?
If you found my post helpful, please give me a recognition point on the left hand side of my post.
全部回复
-
2011年10月28日 21:08I'm trying to utilize the print form tool. I have two, one thats print to printer and the other is print to print screen. When I use either one, my file in the menustrip is blocking out information, like it's showing the menustrip. Is there any way to get it to print just the form without the menustrip without having to put in menustrip1.visible = false?
If you found my post helpful, please give me a recognition point on the left hand side of my post.- 已合并 Mike FengMicrosoft Contingent Staff, Moderator 2011年11月1日 18:06 duplicate
-
2011年10月28日 22:15Try the Power Packs forum.
-
2011年10月31日 18:55Thanks :]
If you found my post helpful, please give me a recognition point on the left hand side of my post. -
2011年11月1日 18:11版主
Hi Ddday,
Welcome to the MSDN Forum.
Do you mean you just want to use one print form to preview and print ?
If so, please take a look at this code:
Imports System.Text Public Class PrintViewWithSetting Dim sb As New StringBuilder Private Sub PrintPreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click RichTextBox1.SelectAll() RichTextBox1.SelectionColor = Color.Black RichTextBox1.Font = New Font(RichTextBox1.Font.FontFamily.ToString, 15) If RichTextBox1.Text = "" Then MsgBox("Please enter text") Else Dim pdialog As New PrintDialog sb.Append(Me.RichTextBox1.Text) Me.PrintPreviewDialog1.Document = PrintDocument1 Me.PrintPreviewDialog1.ShowDialog() Me.PrintPreviewDialog1.TopLevelControl.Size = New System.Drawing.Size(1000, 850) End If End Sub Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim charactersOnPage As Integer = 0 Dim linesPerPage As Integer = 0 ' Sets the value of charactersOnPage to the number of characters ' of stringToPrint that will fit within the bounds of the page. e.Graphics.MeasureString(sb.ToString(), RichTextBox1.Font, e.MarginBounds.Size, StringFormat.GenericTypographic, charactersOnPage, linesPerPage) ' Draws the string within the bounds of the page e.Graphics.DrawString(sb.ToString(0, charactersOnPage), RichTextBox1.Font, Brushes.Red, e.MarginBounds, StringFormat.GenericTypographic) ' Remove the portion of the string that has been printed. sb.Remove(0, charactersOnPage) ' Check to see if more pages are to be printed. e.HasMorePages = sb.Length > 0 End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click Dim pdialog As New PrintDialog sb.Append(Me.RichTextBox1.Text) pdialog.ShowDialog() PrintDocument1.PrinterSettings.PrinterName = pdialog.PrinterSettings.PrinterName If PrintDocument1.PrinterSettings.CanDuplex Then PrintDocument1.PrinterSettings.Duplex = Printing.Duplex.Vertical End If PrintDocument1.Print() 'actually print data End Sub End Class
It only use one Printform to achieve this goal.If I have misunderstood anything, please feel free to let me know.
Best regards,
Mike Feng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- 已建议为答案 CrazyGhost_Von 2011年11月7日 5:59
- 已标记为答案 Mike FengMicrosoft Contingent Staff, Moderator 2011年11月13日 6:51
- 取消答案标记 Mike FengMicrosoft Contingent Staff, Moderator 2011年11月13日 6:52
-
2011年11月4日 15:47
Nah, I don't mind using 2 of them. The problem I'm having is when I print or print preview, it shows the menustrip and it's dropdownmenu.
If you found my post helpful, please give me a recognition point on the left hand side of my post. -
2011年11月7日 5:59
Hi Ddday,
Did you try Mike's code? Please try it and tell us the result.
Have a nice day.
Call me ghost for short, Thanks
To get the better anwser, it should be a better question. -
2011年11月11日 23:02Sorry crazyghost, but I didn't try Mike's code. I don't mind using 2 different printforms. In fact the issue isn't about 2 different printforms, it's when I print or printpreview the dropdown from my menu shows. I was wanting to know if there was a way to print OR printpreview without that dropdown showing.
If you found my post helpful, please give me a recognition point on the left hand side of my post. -
2011年11月11日 23:12
The easiest way to let a method complete and call another method is to start a timer in the first method and call the other method from the tick event of the timer. Use the Tag property to call the appropriate method. You are now calling the PrintForm from a button click event on a menu strip. Effectively, the PrintForm code is a part of the click event code. You want to let the click event complete so the drop down closes.
- 已编辑 JohnWeinMicrosoft Community Contributor 2011年11月11日 23:13
- 已标记为答案 Mike FengMicrosoft Contingent Staff, Moderator 2011年11月13日 6:52
- 取消答案标记 ddday1991 2011年12月15日 16:53

