I would like to ask on how to put a border in print preview and it will also put the label value inside the border please see attached print preview screenshot thank you. Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
print preview screenshot
here is my code:
Private Sub PrintDocument1_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.DrawString("CONOLOSCOPY", New Font("Arial", 20, FontStyle.Bold), Brushes.Red, New Point(300, 20))
e.Graphics.DrawString("ENDOSCOPY NO.: " + txt_ID.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 60))
e.Graphics.DrawString("_________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(180, 60))
e.Graphics.DrawString("REG NO.: " + txt_REGNO.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(300, 60))
e.Graphics.DrawString("_________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(390, 60))
e.Graphics.DrawString("HEIGHT: " + txt_HEIGHT.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(500, 60))
e.Graphics.DrawString("_________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(580, 60))
e.Graphics.DrawString("DATE: " + txt_DATE.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 80))
e.Graphics.DrawString("______________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(70, 80))
e.Graphics.DrawString("ROOM NO.: " + txt_ROOMNO.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(280, 80))
e.Graphics.DrawString("_________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(380, 80))
e.Graphics.DrawString("WEIGHT NO.: " + txt_WEIGHT.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(500, 80))
e.Graphics.DrawString("_________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(620, 80))
e.Graphics.DrawString("LAST NAME: " + txt_LNAME.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 130))
e.Graphics.DrawString("__________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(120, 130))
e.Graphics.DrawString("FIRST NAME: " + txt_FNAME.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(350, 130))
e.Graphics.DrawString("__________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(470, 130))
e.Graphics.DrawString("AGE: " + txt_AGE.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 160))
e.Graphics.DrawString("_____", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(55, 160))
e.Graphics.DrawString("SEX: " + txt_SEX.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(120, 160))
e.Graphics.DrawString("_____", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(170, 160))
e.Graphics.DrawString("CELL NO.: " + txt_CELLNO.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(250, 160))
e.Graphics.DrawString("_________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(340, 160))
e.Graphics.DrawString("ADDRESS: " + txt_ADDRESS.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 190))
e.Graphics.DrawString("__________________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(100, 190))
e.Graphics.DrawString("EMAIL: " + txt_EMAIL.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 240))
e.Graphics.DrawString("_______________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(60, 240))
e.Graphics.DrawString("REFERRING MD: " + txt_REFERMD.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 270))
e.Graphics.DrawString("________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(160, 270))
e.Graphics.DrawString("ATTENDING MD: " + txt_MD.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(350, 270))
e.Graphics.DrawString("___________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(495, 270))
e.Graphics.DrawString("ANESTHESIOLOGIST: " + txt_ANES.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 300))
e.Graphics.DrawString("_______________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(210, 300))
e.Graphics.DrawString("PROCEDURE: " + txt_PROC.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 330))
e.Graphics.DrawString("______________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(135, 330))
e.Graphics.DrawString("INDICATION: " + txt_INDICATION.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(350, 330))
e.Graphics.DrawString("_________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(460, 330))
e.Graphics.DrawString("PREMEDICATION: " + txt_PREMED.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 360))
e.Graphics.DrawString("_______________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(170, 360))
e.Graphics.DrawString("SCOPE USED: " + txt_SCOPE.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 390))
e.Graphics.DrawString("___________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(140, 390))
e.Graphics.DrawString("PROCTIME: " + txt_PROCTIME.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(400, 390))
e.Graphics.DrawString("___________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(510, 390))
e.Graphics.DrawString("BIOPSY: " + txt_BIOPSY.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(370, 420))
e.Graphics.DrawString("___________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(450, 420))
e.Graphics.DrawString("ESOPHAGUS: " + txt_ESOPHAGUS.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 450))
e.Graphics.DrawString("CARDIA: " + txt_CARDIA.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 480))
e.Graphics.DrawString("BODY: " + txt_BODY.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 510))
e.Graphics.DrawString("ANTRUM: " + txt_ANTRUM.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 540))
e.Graphics.DrawString("DUODENAL: " + txt_DUODENAL.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 580))
e.Graphics.DrawString("ENDOSCOPIC DESCRIPTION: " + txt_ENDODESC.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 610))
e.Graphics.DrawString("_________________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(270, 610))
e.Graphics.DrawString("THERAPEUTIC INTERVENTION " + txt_THERAPEUTIC.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 660))
e.Graphics.DrawString("______________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(290, 660))
e.Graphics.DrawString("DIAGNOSIS: " + txt_DIAGNOSIS.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 810))
e.Graphics.DrawString("___________________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(120, 810))
e.Graphics.DrawString("HISTOPATH: " + txt_HISTOPATH.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 960))
e.Graphics.DrawString("_______________________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(120, 960))
e.Graphics.DrawString("ENDOSCOPIST: " + txt_ENDOSPCOPIST.Text, New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(10, 1010))
e.Graphics.DrawString("_______________________________________________________", New Font("Arial", 13, FontStyle.Regular), Brushes.Black, New Point(150, 1010))
End Sub
How can i print multiple pages? In my form i have textboxes with their corresponding labels eg. (id, name, course, etc.) but the problem is 1 page is not enough to display all textboxes. i have to add another page to display the remaining textboxes with their labels. I tried to set e.hasmorepages to true but the textboxes appears in the second page are just the same with the first page it does not continue.
Here is my code :
Private Sub printSisDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printSisDoc.PrintPage
Dim labelFont As New Font("Arial", 11, FontStyle.Bold)
Dim textFont As New Font("Arial", 11, FontStyle.Regular)
Dim headerFont As New Font("Arial", 12, FontStyle.Bold)
e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660)
e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690)
e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692)
e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715)
e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740)
e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765)
e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790)
e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815)
e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840)
e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865)
e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890)
e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 1500)
mPageNumber += 1
e.HasMorePages = (mPageNumber <= 2)
End Sub
When you have more than one page, you need to ensure the single PrintPage() method is called once for every page you need to print. Each time the method is called, it needs to know which page is current and what should be written to that page.
The e.HasMorePages variable is how you make the PrintDocument object call the method again. Also remember the printSisDoc_PrintPage() method is part of a class. You can set data in the class instance the method can use to know what page is current and what to print.
Private Sub printSisDoc_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printSisDoc.PrintPage
Dim labelFont As New Font("Arial", 11, FontStyle.Bold)
Dim textFont As New Font("Arial", 11, FontStyle.Regular)
Dim headerFont As New Font("Arial", 12, FontStyle.Bold)
Select mPageNumber
Case 1
e.Graphics.DrawString(lblGrade.Text, headerFont, Brushes.Black, 650, 660)
e.Graphics.DrawString(grade11.Text, textFont, Brushes.Black, 660, 690)
e.Graphics.DrawString(underline.Text, labelFont, Brushes.Black, 643, 692)
e.Graphics.DrawString(grade12.Text, textFont, Brushes.Black, 660, 715)
e.Graphics.DrawString(grade13.Text, textFont, Brushes.Black, 660, 740)
e.Graphics.DrawString(grade14.Text, textFont, Brushes.Black, 660, 765)
e.Graphics.DrawString(grade15.Text, textFont, Brushes.Black, 660, 790)
e.Graphics.DrawString(grade16.Text, textFont, Brushes.Black, 660, 815)
e.Graphics.DrawString(grade17.Text, textFont, Brushes.Black, 660, 840)
e.Graphics.DrawString(grade18.Text, textFont, Brushes.Black, 660, 865)
e.Graphics.DrawString(grade19.Text, textFont, Brushes.Black, 660, 890)
e.HasMorePages = True
Case 2
e.Graphics.DrawString(grade20.Text, textFont, Brushes.Black, 0, 400)
e.HasMorePages = False
End Select
mPageNumber += 1
End Sub
I want to draw circles within circles and i have tried this but having difficulties
here is my code
Private Sub DrawCircle()
Dim g As Graphics
g = Panel1.CreateGraphics
Dim yellowPen As New Pen(Color.Yellow, 20)
Dim bluePen As New Pen(Color.Blue, 30)
Dim greenPen As New Pen(Color.Green, 20)
Dim skybluePen As New Pen(Color.AliceBlue, 20)
Dim voiletPen As New Pen(Color.Violet, 15)
Dim blackPen As New Pen(Color.Black, 2)
' Draw ellipses
g.DrawEllipse(yellowPen, 260, 180, 10, 10)
g.DrawEllipse(greenPen, 240, 160, 50, 50)
g.DrawEllipse(bluePen, 220, 140, 90, 90)
g.DrawEllipse(greenPen, 200, 120, 130, 130)
g.DrawEllipse(skybluePen, 180, 100, 170, 170)
g.DrawEllipse(blackPen, 180, 100, 170, 170)
g.DrawEllipse(voiletPen, 170, 90, 190, 190)
End Sub
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
DrawCircle()
End Sub
It is working well but if there is any other option because if you change a little in this code everything goes wrong please help me out
May be i did't get your point right and i think you are looking for an alternate solution
here is one
Private colorForAllCircles As Color
Private ReadOnly rand As New Random
Function RandomColor() As Color
Return Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256))
End Function
Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim centerX, centerY As Integer
Dim cornerX, cornerY As Integer
Dim radius As Integer
Dim greenPen As New Pen(Brushes.Blue)
centerX = 300
centerY = 200
Dim i As Integer
For i = 20To 200 Step 20
greenPen = New Pen(RandomColor, 20)
radius = i
cornerX = centerX - radius / 2
cornerY = centerY - radius / 2
e.Graphics.DrawEllipse(greenPen, cornerX, cornerY, radius, radius)
Next
End Sub