Image of Navigational Panel mapped to Contents / Home / Search Creating Bitmaps from Graphics Methods
Tech Support Question

Image of Line Break

Q. My name is Brad Herman, I am fairly new to VB programming but I did a lot of Basic programming in my past. I am learning steadily and am getting the hang of it. I have a VB4 (Win95) problem.

It has kept me up for 2 days straight. I need to take text in text boxes and make them graphics. I have a Form with multiple text boxes, and want to be able to put the text from the boxes onto a .bmp (and a .pcx eventually) - so you can type in all the info and press the button, and it puts the text you just typed in at certain spots on an image, and in different fonts (bold/regular). I know there must be a way to do this, please help me.

Gratefully,

From: Brad Herman
Email: Technomage techno@voicenet.com

A. What you want to do is certainly achievable, the main problem is figuring out from the VB documentation how it can be done. Here is a method that works with both VB4 16 bit and VB3 (I have not tested it with VB4 32 bit, but I would be surprised if it did not work). I will take you through all the necessary steps, so you can see how it is done.

NB: I have used default control names for simplicity - I don't recommend it.

First thing to do is create a new project. On the blank form that is created, place a picture control. Now, here is the pivotal bit: change the picture control's AutoRedraw property to true. Then place two buttons and a textbox on the form. In the Click event of the first button place the following code (or similar):

  Picture1.Print Text1.Text

On the Click event of the second button place the following code:

  SavePicture Picture1.Image, "C:\TEST.BMP"

Now whenever you click the first button, the current text in the text box is written to the picture control. When you click the second button, the bitmap generated by drawing the text on the picture box is saved to a bitmap file on your hard disk.

The trick to achieving this is the AutoRedraw property. This has to be one of the most obscure and least understood properties in VB (don't get me wrong, I don't understand it either). Basically what it does is produces a persistent bitmap from any graphics methods applied to the picture box (or form). This means that the picture box (or form) has a bitmap image of how it should look. This means that when it receives a Paint message (because a window that was in front of it has moved out of the way) the picturebox was resized, or for whatever other reason it has a bitmap in memory of what it should look like, and will display that bitmap. It also means that that bitmap is exposed by the image property. When AutoRedraw is false, the picturebox (or form) relies on code in its paint event to provide whatever graphics methods are required to make it look however it should.

Let me try and explain that another way. When AutoRedraw is off, the picturebox can have things drawn on it in its paint event, but it does not remember what was drawn. When it needs to be redrawn it starts from scratch. When AutoRedraw is true, it remembers what it is supposed to look like and will display that when it needs to paint itself. When you want to start from scratch and AutoRedraw is on, you need to use the Cls method.

Now all you need to do is manipulate the Font properties (FontName, FontBold, and so on) of the picture control to get the right effects you want. You can also use the CurrentX and CurrentY properties to position the text however you want, by changing them to wherever you want the results from the next Text method to appear.

I hope this lets you do what you want, it should at least give you a good start. Have fun.


Image of Arrow to Previous Article Image of Arrow to Next Article

[TECH SUPPORT TOC]
Image of Line Break
[HOME] [TABLE OF CONTENTS] [SEARCH]