I got a programming question I would like to ask.

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • I got a programming question I would like to ask.

      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.
      Files
      • Book.zip

        (126.28 kB, downloaded 676 times, last: )
      I WANT ULTIMA 7/8 CONSTRUCTION SET! I WANT ULTIMA 7/8 CONSTRUCTION SET!!
    • Did you ever get this fixed? Sorry, I don't know Visual Basic at all and I've never used its Graphics class.

      -Rez
    • I did get this fixed but I also learned that I will NOT get any help here at all. Therefore I am no longer going to post for assistance here...can you imagine if I relied on you guys to help me in this...I would have wasted a week now and still got no where. Thank God that is nice the case.
      I WANT ULTIMA 7/8 CONSTRUCTION SET! I WANT ULTIMA 7/8 CONSTRUCTION SET!!
    • Yes, that's probably for the best. Relying on others to do your work for you is typically not a solid plan for getting something done. Keep in mind that we all have full-time jobs and/or school, which tends to limit the help we can provide. I know I was crunching pretty hard last week trying to get this game to alpha, hence my delayed response.

      When seeking help in the future, whether here or on other forums, I would suggest that you use an industry standard language like C++ and an industry standard graphics API, like DirectX or OpenGL. The reason for this is that people are typically more willing to help when they can answer the question off the top of their head rather than having to dig through an API they don't know written in a language they're unfamiliar with. I could tell you how to do what you're trying to accomplish very easily in C++ using D3D. Furthermore, I would strongly suggest that you learn C++ and either DirectX or OpenGL if you don't know them already, simply because you really should be using the best tool for the job. Visual Basic .Net, which is a Microsoft-specific interpreted language, is not such a tool.

      Good luck in your endeavors, I wish you the best.

      -Rez
    • My target audience is Windows :). VB.NET is not an interpreter nowadays VB especially .NET is as equal as a compiler as C++ is. VB.NET is a master language for Application Development (no, KING of a language) since my editor comes into two worlds, one the application part that you use to develop your world and the engine that runs your design. With VB.NET I will get an equal result as I would with C++ for Application Development but WITH faster result. I don't want to spend 6 month to a year just to develop the Application side of my editor verses let us say 3 month for example with VB.NET. Now we may discuss C++ when it comes to the engine part, that is a good idea if I want faster frame rate for my game. But let us not talk about this yet.
      I WANT ULTIMA 7/8 CONSTRUCTION SET! I WANT ULTIMA 7/8 CONSTRUCTION SET!!
    • Yes, for the editor it'll be fine. You certainly don't want to use it for the engine. :) I prefer C# for application development, but only because I like the C-style syntax over the VB.NET syntax.

      -Rez
    • Doesn't the CLR concept of NET imply that it is interpreted ? At least there is an additional layer which you could cut out using C++

      As for the Master / KING language - that completely depends on the project / developer combination. Personal preference i guess

      Good Luck with your project :D
      -- hoschi

      [size=small]The answer is 42[/size]