Put text inside a circle in a Rich Text Box
Author |
Message |
George Collin #1 / 6
|
 Put text inside a circle in a Rich Text Box
Hi, Is there anyway to draw a circle in a Rich Text Box control and then allow text to be typed over the circled area? I'm doing a CD label maker program and want to use the drawn circle as a guide for placing the label text. tia, George
|
Thu, 08 Jul 2004 10:38:15 GMT |
|
 |
Mike William #2 / 6
|
 Put text inside a circle in a Rich Text Box
I think you would be better off forgetting all about the Rich Text Box and use a Picture Box instead. That way, you will be able to allow the user to have standard text, rotated text, text around a curve, images, all sorts of things, if you are prepared to spend enough time writing lots of scary code! Mike
Quote: > Hi, > Is there anyway to draw a circle in a Rich Text Box control and then allow > text to be typed over the circled area? I'm doing a CD label maker program > and want to use the drawn circle as a guide for placing the label text. > tia, > George
|
Thu, 08 Jul 2004 12:22:44 GMT |
|
 |
George Collin #3 / 6
|
 Put text inside a circle in a Rich Text Box
Mike, Thanks for the information on printing the picture box correctly. It's very much the same as I have done for Rich Text Box. The remaining problem with the Picture Box is that, while I can draw text in it, I don't have any "built-in" text editing funtionally like that of the Rich Text Box. It seems to me that developing even simple text editing in a picture box is a sizeable task. But my application really depends on being able to insert and delete text on a line and being able to select text and change fonts and sizes. If I could just put that circle in the Rich Text Box I have it! :) Any other thoughts or suggestions? Thanks, George
Quote: > I think you would be better off forgetting all about the Rich Text Box and > use a Picture Box instead. That way, you will be able to allow the user to > have standard text, rotated text, text around a curve, images, all sorts of > things, if you are prepared to spend enough time writing lots of scary code! > Mike
> > Hi, > > Is there anyway to draw a circle in a Rich Text Box control and then allow > > text to be typed over the circled area? I'm doing a CD label maker > program > > and want to use the drawn circle as a guide for placing the label text. > > tia, > > George
|
Sat, 10 Jul 2004 07:19:10 GMT |
|
 |
Mauree #4 / 6
|
 Put text inside a circle in a Rich Text Box
Quote: > Thanks for the information on printing the picture box correctly. It's very > much the same as I have done for Rich Text Box. The remaining problem with > the Picture Box is that, while I can draw text in it, I don't have any > "built-in" text editing funtionally like that of the Rich Text Box.
You can write code to give the user full text editing facilities in a Picture Box, although that, of course, would require quite a lot of code. But you don't have to do that. All you need to do is display the circular outline of the CD label in a Picture Box and then place a small RichText Box next to it. Then allow the user to enter and edit text in the RichTextBox and each time the user makes a change you simply "draw" the text from the RichTextBox into the Picture Box, using CurrentX, CurrentY and Picture1.Print stuff, setting the font and the colour and stuff like that exactly reflect the text in the RichText Box, so that the user gets a "real time" display in the Picture Box of the text that he enters into the Text Box. Putting your "circle" in a RichText Box (as you currently seem to favour) will not really help you, even if you discover how to do it, simply because it will seriously limit the functionality of your application, especially an application such as yours that is iontended to allow the user to create CD labels. For example, one of the first things that the user will want to do is to print text on the label in a "circular" fashion, so that the main title, for example, is printed near the top of the label and follows its curve. He may also want to position other text near the bottom of the circular label, also following the curve. He doesn't have to do this, of course, but it would be nice to give him the facility to do so. Using a Picture Box in conjunction with a RichText Box, in the way that I have suggested, would allow you to do this, and you would be able to print the "curved" text into the Picture Box so that the user could see exactly how it is going to appear on his label. You could, for example, have one RichText Box for the user to enter the "top" curved text and another to enable him to enter the "bottom" curved text. You could have as many other little RichText Boxes as you like, to allow the user to enter and position "normally aligned" text anywhere he wants. In fact, if you do not want to give the user the option of "mixing fonts or colours" in any single text entry (an unusual requirement, anyway) then you could use standard Text Boxes instead. The user could select or deselect any of these boxes at will. Another thing you could do is allow the user to select and size a background picture, which you could display in the Picture Box beneath the text. All of this would require a fair bit of coding, but you will find it worth the effort. Mike
|
Sun, 11 Jul 2004 21:26:24 GMT |
|
 |
George Collin #5 / 6
|
 Put text inside a circle in a Rich Text Box
Mike, I'm actually working on the approach you suggest right now. It does seem to be a practical solution for my needs. Thanks very much for your input. I have just one more question: How do you print curved text to the picture box? I don't really need to for my use, but I'm interested in how it's done. Thanks again, George
Quote:
> > Thanks for the information on printing the picture box correctly. It's > very > > much the same as I have done for Rich Text Box. The remaining problem > with > > the Picture Box is that, while I can draw text in it, I don't have any > > "built-in" text editing funtionally like that of the Rich Text Box. > You can write code to give the user full text editing facilities in a > Picture Box, although that, of course, would require quite a lot of code. > But you don't have to do that. All you need to do is display the circular > outline of the CD label in a Picture Box and then place a small RichText Box > next to it. Then allow the user to enter and edit text in the RichTextBox > and each time the user makes a change you simply "draw" the text from the > RichTextBox into the Picture Box, using CurrentX, CurrentY and > Picture1.Print stuff, setting the font and the colour and stuff like that > exactly reflect the text in the RichText Box, so that the user gets a "real > time" display in the Picture Box of the text that he enters into the Text > Box. > Putting your "circle" in a RichText Box (as you currently seem to favour) > will not really help you, even if you discover how to do it, simply because > it will seriously limit the functionality of your application, especially an > application such as yours that is iontended to allow the user to create CD > labels. > For example, one of the first things that the user will want to do is to > print text on the label in a "circular" fashion, so that the main title, for > example, is printed near the top of the label and follows its curve. He may > also want to position other text near the bottom of the circular label, also > following the curve. He doesn't have to do this, of course, but it would be > nice to give him the facility to do so. Using a Picture Box in conjunction > with a RichText Box, in the way that I have suggested, would allow you to do > this, and you would be able to print the "curved" text into the Picture Box > so that the user could see exactly how it is going to appear on his label. > You could, for example, have one RichText Box for the user to enter the > "top" curved text and another to enable him to enter the "bottom" curved > text. You could have as many other little RichText Boxes as you like, to > allow the user to enter and position "normally aligned" text anywhere he > wants. In fact, if you do not want to give the user the option of "mixing > fonts or colours" in any single text entry (an unusual requirement, anyway) > then you could use standard Text Boxes instead. The user could select or > deselect any of these boxes at will. > Another thing you could do is allow the user to select and size a background > picture, which you could display in the Picture Box beneath the text. > All of this would require a fair bit of coding, but you will find it worth > the effort. > Mike
|
Mon, 12 Jul 2004 06:59:19 GMT |
|
 |
Mauree #6 / 6
|
 Put text inside a circle in a Rich Text Box
Quote: > Mike, > I'm actually working on the approach you suggest right now. It does seem to > be a practical solution for my needs. Thanks very much for your input. I > have just one more question: How do you print curved text to the picture > box? I don't really need to for my use, but I'm interested in how it's > done.
I have a sneaky suspicion that buried somewhere deep inside the API stuff related to text output there is a function that will draw your text on a curve for you, but I do not have access to my little Dan Appleman book at the moment, and so I can't be sure. You can, however, write code to draw each character separately, creating a "rotated font" for each individual character and positioning it using a bit of code to set the desired position of that character along the perimeter of a circle. That shpouldn't be too difficult to do, and it will certainly work. Just to get you started, here is some code to enable you to draw "rotated text". The example code is written to print rotated text to the printer (something which you will obviously have to do when you print your CD label) but you can easily change it to print to the Picture Box instead. I have deliberately posted "printer rotated text" rather than "picture box rotated text" because printing rotated text to the printer is not quite as simple as printing it to a picture box, and so you will need this code anyway. Mike Option Explicit Private Const LF_FACESIZE = 32 Private Type LOGFONT lfHeight As Long lfWidth As Long lfEscapement As Long lfOrientation As Long lfWeight As Long lfItalic As Byte lfUnderline As Byte lfStrikeOut As Byte lfCharSet As Byte lfOutPrecision As Byte lfClipPrecision As Byte lfQuality As Byte lfPitchAndFamily As Byte lfFaceName As String * LF_FACESIZE End Type Private Declare Function CreateFontIndirect Lib "gdi32" _ Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long Private Declare Function SelectObject Lib "gdi32" _ (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteObject Lib "gdi32" _ (ByVal hObject As Long) As Long Private Declare Function TextOut Lib "gdi32" Alias _ "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal _ y As Long, ByVal lpString As String, ByVal nCount _ As Long) As Long ' or Boolean Private Sub RotatedText(textstring As String, angle As Long) ' Prints rotated text at the current printer x and y ' coordinates at a specified angle (in tenths of a degree ' in an anti clockwise direction (zero is normal text) Dim printer_hdc As Long Dim oldmode As Long, xpix As Long, ypix As Long Dim log_font As LOGFONT Dim new_font As Long, old_font As Long With Printer xpix = .ScaleX(.CurrentX - .ScaleLeft, .ScaleMode, vbPixels) ypix = .ScaleY(.CurrentY - .ScaleTop, .ScaleMode, vbPixels) printer_hdc = .hdc End With With log_font .lfEscapement = angle .lfHeight = (Printer.FontSize * -20) / Printer.TwipsPerPixelY .lfFaceName = Printer.FontName & vbNullChar If Printer.FontBold = True Then .lfWeight = 700 Else .lfWeight = 400 End If .lfItalic = Printer.FontItalic .lfStrikeOut = Printer.FontStrikethru .lfUnderline = Printer.FontUnderline End With new_font = CreateFontIndirect(log_font) old_font = SelectObject(printer_hdc, new_font) TextOut printer_hdc, xpix, ypix, textstring, Len(textstring) SelectObject printer_hdc, old_font DeleteObject new_font End Sub Private Sub Command1_Click() Printer.FontTransparent = False Printer.Print Printer.FontTransparent = True Printer.ScaleMode = vbInches Printer.FontName = "Times New Roman" Printer.FontSize = 14 Printer.FontBold = False Printer.FontItalic = False Printer.FontUnderline = False Printer.FontStrikethru = False Printer.CurrentX = 4 Printer.CurrentY = 4.5 Dim angle As Long, s1 As String For angle = 0 To 3150 Step 450 ' angle is in tenths of a degree s1 = "Whisky and Coke is a wonderful drink " s1 = s1 + "(" + Format(angle \ 10) + Chr(186) + ")" RotatedText s1, angle Next angle Printer.EndDoc End Sub
|
Mon, 12 Jul 2004 07:52:09 GMT |
|
|
|