In my Windows form I have a picturebox, the picturebox will hold an open book graphics and in the textbox field the person enters what he wants to appear in the book. My question is this, how do I make the text appear on top of the graphics itself and fit on the page of the book and if the text fills in the first page, it warps to the second page. If the second page is filled it opens two new pages and so on?
Right now I have done this in the code:
Public Sub DrawStringOnPictureBox(ByRef p As DrawText)
'we start with a new bitmap (width, height, pixelformat)
Dim i As New Bitmap(p.PictureBox.Width, p.PictureBox.Height, p.PixelFormat)
'we get a Graphics object from that image
Dim g As Graphics = Graphics.FromImage(i)
'this is how you set the background color of the image
g.Clear(p.bgColor)
'Set the drawing font
Dim f As Font = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
'Measure the text (text, font, layoutsize, stringformat)
Dim fSize As SizeF = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop until the text width is less than the picturebox width (plus the border)
'Do While fSize.Width > (p.PictureBox.Width - p.BorderSize)
' 'if it is wider then we decriminate the text size by one and try again
' p.MaxSize -= 1
' f = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
' fSize = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop
If fSize.Width > (p.PictureBox.Width - p.BorderSize) Then
' You have reached the maximum border delete some before writing
Exit Sub
End If
''Loop until the text height is less than the picturebox height (plus the border)
'Do While fSize.Height > (p.PictureBox.Height - p.BorderSize)
' 'if it is heigher then we decriminate the text size again my one
' p.MaxSize -= 1
' f = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
' fSize = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop
'This is the DrawString method that draws the text onto the image
'DrawString(text, font, fontsize, fontsyle, graphicsunit, Brush, XPos, YPos, StringFormat)
g.DrawString(p.Text, f, New SolidBrush(p.foreColor), p.X, p.Y, p.StringFormat)
'set the Image of our Picturebox to the bitmap
p.PictureBox.Image = i
'cleanup
g.Dispose()
End Sub
What part of the problem is solved in the sentence that what ever I type in the textbox appears in the picturebox as if I am typing directly on the picturebox. But here comes the problem, first the text is at the center of the textbox, second of all whatever picture in the picturebox was (in the case an open empty two page book) it disappears to be replaced with the new text I enter. I don't want this at all. The reason this happens are the following two I believe:
Dim i As New Bitmap(p.PictureBox.Width, p.PictureBox.Height, p.PixelFormat)
and this one
'set the Image of our Picturebox to the bitmap
p.PictureBox.Image = i
Any suggestions is recommended, thanks in advance.
Right now I have done this in the code:
Public Sub DrawStringOnPictureBox(ByRef p As DrawText)
'we start with a new bitmap (width, height, pixelformat)
Dim i As New Bitmap(p.PictureBox.Width, p.PictureBox.Height, p.PixelFormat)
'we get a Graphics object from that image
Dim g As Graphics = Graphics.FromImage(i)
'this is how you set the background color of the image
g.Clear(p.bgColor)
'Set the drawing font
Dim f As Font = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
'Measure the text (text, font, layoutsize, stringformat)
Dim fSize As SizeF = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop until the text width is less than the picturebox width (plus the border)
'Do While fSize.Width > (p.PictureBox.Width - p.BorderSize)
' 'if it is wider then we decriminate the text size by one and try again
' p.MaxSize -= 1
' f = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
' fSize = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop
If fSize.Width > (p.PictureBox.Width - p.BorderSize) Then
' You have reached the maximum border delete some before writing
Exit Sub
End If
''Loop until the text height is less than the picturebox height (plus the border)
'Do While fSize.Height > (p.PictureBox.Height - p.BorderSize)
' 'if it is heigher then we decriminate the text size again my one
' p.MaxSize -= 1
' f = New Font(p.Font, p.MaxSize, FontStyle.Regular, GraphicsUnit.World)
' fSize = g.MeasureString(p.Text, f, p.LayoutSizeF, p.StringFormat)
'Loop
'This is the DrawString method that draws the text onto the image
'DrawString(text, font, fontsize, fontsyle, graphicsunit, Brush, XPos, YPos, StringFormat)
g.DrawString(p.Text, f, New SolidBrush(p.foreColor), p.X, p.Y, p.StringFormat)
'set the Image of our Picturebox to the bitmap
p.PictureBox.Image = i
'cleanup
g.Dispose()
End Sub
What part of the problem is solved in the sentence that what ever I type in the textbox appears in the picturebox as if I am typing directly on the picturebox. But here comes the problem, first the text is at the center of the textbox, second of all whatever picture in the picturebox was (in the case an open empty two page book) it disappears to be replaced with the new text I enter. I don't want this at all. The reason this happens are the following two I believe:
Dim i As New Bitmap(p.PictureBox.Width, p.PictureBox.Height, p.PixelFormat)
and this one
'set the Image of our Picturebox to the bitmap
p.PictureBox.Image = i
Any suggestions is recommended, thanks in advance.
I WANT ULTIMA 7/8 CONSTRUCTION SET! I WANT ULTIMA 7/8 CONSTRUCTION SET!!