• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Visual Basic Help (1 Viewer)

aaaman

Banned
Joined
Jan 5, 2005
Messages
851
Location
The Shire
Gender
Male
HSC
2005
hey guys, im wonderin if anyone knows how to print colours from a text box thanks you :)
 

aaaman

Banned
Joined
Jan 5, 2005
Messages
851
Location
The Shire
Gender
Male
HSC
2005
Casmira said:
do you mean full on print it like on a printer?
yea

Private Sub cmdPrint_Click()
Dim msgprompt As String, msgtitle As String 'the check if the user wants to print
Dim msgButtons As Integer, msgresult As Integer

msgprompt = "Are you sure you want to print the text?"
msgButtons = vbYesNo + vbInformation + vbDefaultButton2
msgtitle = "Printing Text"
msgresult = MsgBox(msgprompt, msgButtons, msgtitle)

Select Case msgresult
Case vbYes ' if user wants to print
With Printer
.FontName = "MS Sans Serif" 'sets font
If num >= 8 Then
.FontSize = num 'sets font size
Else
.FontSize = 12 'default font size
End If
If chkBold.value = 1 Then 'checks the bold setting if its turned on
.FontBold = True
Else
.FontBold = False
End If

If chkItalic.value = 1 Then 'checks the italic setting if its turned on
.FontItalic = True
Else
.FontItalic = False
End If

If chkStr.value = 1 Then 'checks the Strikethu setting if its turned on
.FontStrikethru = True
Else
.FontStrikethru = False
End If

If chkUnder.value = 1 Then 'checks the underline setting if its turned on
.FontUnderline = True
Else
.FontUnderline = False
End If

If chkBlack.value = 1 Then 'prints out the font of user's choosing
txtInput.ForeColor = RGB(0, 0, 0)
End If

If chkRed.value = 1 Then 'prints out the font of user's choosing
txtInput.ForeColor = RGB(146, 12, 12)
End If

If chkBlue.value = 1 Then 'prints out the font of user's choosing
txtInput.ForeColor = RGB(21, 7, 151)
End If

If chkGreen.value = 1 Then 'prints out the font of user's choosing
txtInput.ForeColor = RGB(20, 124, 62)
End If


End With

Printer.Print txtInput.Text
Printer.EndDoc

Case vbNo
Exit Sub 'if user does not want to print then nothing will happen
End Select
End Sub

thats my source code, i tried doing like that (bold) but it only prints out black :p
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
hmm im sure there are other methods of choosing a colour, not just setting RGB, have you tried the hexadecimal visual basic has by default?
 

sunny

meh.
Joined
Jul 7, 2002
Messages
5,350
Gender
Male
HSC
2002
The textbox itself is only used for displaying. To print in various formats you have to play with the printer object. For example, you can change Printer.FontBold, etc.
 

aaaman

Banned
Joined
Jan 5, 2005
Messages
851
Location
The Shire
Gender
Male
HSC
2005
sunny said:
The textbox itself is only used for displaying. To print in various formats you have to play with the printer object. For example, you can change Printer.FontBold, etc.

i did all that but i can not find a function for it :(
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
In your code you have...

txtInput.ForeColor = RGB(0, 0, 0) and other variants for other colours.

This changes the color of the text in the textbox, I'd say this should be...

.Forecolor = RGB(...)

So it refers to the printer object referred to by your With Printer... End With block.

(I've never fiddled with font colors when printing, but I'd assume a .Forecolor property exists for the Printer object).

HTH
Sam
 
Joined
Nov 4, 2004
Messages
3,550
Location
Sydney
Gender
Male
HSC
2005
^ The man has spoken, if you want too add some funky little features in your program (havent looked at your code thoroughly so i dont know if you have this neat module) but it shows what printer you have, its per attached and ive had it as a .txt for a long time and lost the source however its probably from planetsource
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top