TEXTBOX
Tenho 1 textbox e nele quero que apareça as escritas de cores diferentes.
Ex: cliente: azul
server: vermelho
Entao quero que quando eu click commandbutton1 saia no textbox as letras azuis e quando eu clicar no commandbutton2 as letras apareçam vermelhas, mas isso no mesmo textbox.
Ex: cliente: azul
server: vermelho
Entao quero que quando eu click commandbutton1 saia no textbox as letras azuis e quando eu clicar no commandbutton2 as letras apareçam vermelhas, mas isso no mesmo textbox.
Tente
'Coloca cor da letra
Sub commandbutton1 _Click
text.forecolor = qbcolor(4)
end sub
'Coloca cor da letra
Sub commandbutton2 _click
text.forecolor = qbcolor(2)
end sub
'Coloca cor da letra
Sub commandbutton1 _Click
text.forecolor = qbcolor(4)
end sub
'Coloca cor da letra
Sub commandbutton2 _click
text.forecolor = qbcolor(2)
end sub
Coloque o seguinte código nos botões:
*****************************************************
Private Sub Command1_Click()
Text1.ForeColor = &HFF0000 'Azul
End Sub
*******************************************************
Private Sub Command2_Click()
Text1.ForeColor = &HFF& 'Vermelho
End Sub
*******************************************************
Qualquer dúvida, estamos ai...
Valew...
*****************************************************
Private Sub Command1_Click()
Text1.ForeColor = &HFF0000 'Azul
End Sub
*******************************************************
Private Sub Command2_Click()
Text1.ForeColor = &HFF& 'Vermelho
End Sub
*******************************************************
Qualquer dúvida, estamos ai...
Valew...
Acho q nao expliquei legal...
Vou colocar o codigo aqui pra ver se vcs me entedem melhor...
Na verdade e 1 chat e quero que quando o server escreva seja uma cor e quando o cliente escreva o nick seja de outra cor,resumindo uma cor pro server outra pro cliente,basta o nick!oBrigado ah todos!
Option Explicit
Dim strFriend As String 'holds servers name
Dim strMyName As String 'holds your name
Dim strFileName As String 'holds the name of the file u are receiving
Dim blnSend As Boolean 'if false, it wont send; if true it will
Dim strSize As String 'holds the size of the file
Dim strSoFar As String 'a var for calculating the KBps
Dim strBlock As String 'holds the data you are going to send
Dim strLOF As String 'holds the lenght of the file
Private Sub cmdSendChat_Click()
If Trim(txtSend.Text) = "" Then Exit Sub 'prevents someone trying to send nothing
Winsock.SendData "Chat" & txtSend.Text 'sends the text to the chat
txtChat.SelStart = Len(txtChat) 'put focus on the chat at the end so it is entered in the right place
txtChat.SelText = strMyName & ":" & txtSend.Text & vbCrLf 'puts the text in the chat
txtSend.Text = "" 'clears the textbox u type in
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock.Close 'closes winsock so program can end
End 'closes program
End Sub
Private Sub Timer1_Timer()
Label2.Visible = Not Label2.Visible
End Sub
Private Sub tmrKBps_Timer()
On Error Resume Next 'prevents error
lblKBps.Caption = "" & Format(strSoFar / 1000, "###0.0") & " / KBps" 'calculates the KBps
strSoFar = 0 'resets it so it can be calculated again
End Sub
Private Sub Winsock_Connect()
frmConnect.tmrClient.Enabled = False 'tell client to stop trying to connect cause it is connected =D
Winsock.SendData "Nick" & frmConnect.txtName.Text 'sends ur name to server
DoEvents 'i dunno why but i need it cause of winsock
strMyName = frmConnect.txtName 'saves ur name into memory
Me.Show 'shows frmclient
Unload frmConnect 'obvious
End Sub
Private Sub cmdSelect_Click()
CD.Flags = cdlOFNFileMustExist 'wont let someone open a file not there!
CD.Filter = "All Files (*.*)|*.*" 'filters all files to be shown!!!!!!!
CD.ShowOpen 'shows the open dialog box
txtFile.Text = CD.FileName 'puts the path of the file into the txtfile
End Sub
Private Sub cmdSend_Click()
On Error Resume Next 'prevents error
If txtFile.Text = "" Then Exit Sub 'wont let someone send something not there
strFileName = "" 'resets the filename
blnSend = False 'sets it to false
strSize = "" 'resets the size
Open txtFile.Text For Binary As #1 'opens the file u want to send so it can be read
strLOF = LOF(1) 'saves length of file into memory
Winsock.SendData "Name" & CD.FileTitle & ":" & strLOF 'sends server the name of the file and its length
DoEvents 'needed =D
Do While blnSend = False 'keeps looping until the server accepts the request
DoEvents 'lets u do stuff while in loop
Loop 'goes back to Do WHile statement
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next 'prevents error
Dim strData As String 'holds data for select case
Dim strData2 As String 'holds data
Call Winsock.GetData(strData, vbString) 'gets the data sent by the server
strData2 = Mid(strData, 5) 'gets data
strData = Left(strData, 4) 'gets data for select case
Select Case strData 'goes to the right case depending on strData
Case "File" 'a file transfer is in progress
Put 1, , strData2 'puts data into file
PBar.Value = PBar.Value + bytesTotal 'shows how much is done so far
strSoFar = strSoFar + bytesTotal 'calculates KBps
Winsock.SendData "OKOK keep sending!" 'tells them ur done with the data and u want some more!
DoEvents ' =D
Case "Name" 'server has sent u the filename and is ready to begin transfer
Dim intX As Integer 'holds position if :
intX = InStr(1, strData2, ":", vbTextCompare) 'gets position of :
strSize = Mid(strData2, intX + 1) 'holds the filesize
PBar.Max = strSize 'sets up the progressbar
strData = Mid(strData2, 1, intX - 1) 'holds filename
strFileName = strData 'puts filename into memory
Dim strResponse As String 'holds either a vbYEs or vbNo
strResponse = MsgBox(strFriend & " Quantos pra enviar [" & strFileName & "]. Vc deseja receber esse arquivo?", vbYesNo, "Arquivo A ser enviado !") '<=- easy to understand
If strResponse = vbYes Then 'if they said yes
Dim strType As String 'holds the type of file
strType = Right(strFileName, 3) 'gets the type of file
CD.FileName = strFileName 'sets the filename into the commondialog box
CD.Filter = "File Type (*." & strType & ")|*." & strType 'sets the filter to the filetype
CD.Flags = cdlOFNOverwritePrompt 'asks u if u want to overwrite file
CD.ShowSave 'shows the save commondialog box
Open CD.FileName For Binary As #1 'opens a file with the name and path u want
Winsock.SendData "OKOK i want the file" 'tell server u want the damn file
DoEvents 'yes another doevents
Me.Enabled = False 'disables to form to PREVENT ERROR!!!!!!!!!!
ElseIf strResponse = vbNo Then 'if they say no
Winsock.SendData "Nope dont want it!" 'tell em u dont want their crap!
DoEvents 'hmmm
End If 'ok enough of that madness
Case "Stop" 'the file exchange has ended
Close #1 'closes the file
'resets the progressbar
PBar.Value = 0
PBar.Max = 1
'=====================
Me.Enabled = True 'reenables the form!
Case "Nick" 'server has sent u their name
strFriend = strData2 'saves their name into memory
Case "Nope" 'tells u that they declined ur request to give em a file
MsgBox strFriend & " Arquivo recusado.", vbInformation, "Arquivo Cancelado!" '<=- easy to get again
Close #1 'closes the file
'stops the loops that was waiting for the boolean value to be true
Do
DoEvents
Loop
'==========================
Case "OKOK" 'tells u they want more of the file
blnSend = True 'tells u to keep sending
Me.Enabled = False 'keeps form disabled
PBar.Max = strLOF 'sets progressbar max to filesize
If Not EOF(1) Then 'does this if not the end of the file
If strLOF - Loc(1) < 2040 Then 'if you are at the last chunk of data
strBlock = Space$(strLOF - Loc(1)) 'sets the block size to the size of the data (cause its less!)
Get 1, , strBlock 'gets data
Winsock.SendData "File" & strBlock 'sends data
DoEvents ' =/
PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
strSoFar = strSoFar + (strLOF - Loc(1)) 'sets KBps
Winsock.SendData "Stop the maddness!" 'tells server THE TRANSFER IS ENDED!
Close #1 'closes file
'resets the progressbar
PBar.Max = 1
PBar.Value = 0
'====================
Me.Enabled = True 'reenables the form
Else 'if not the last chunk
strBlock = Space$(2040) 'sets block up to receive only 2040 bytes of data
End If
strSoFar = strSoFar + 2040 'calculates KBps
Get 1, , strBlock 'gets data
Winsock.SendData "File" & strBlock 'sends data
DoEvents 'hmmmm once again
PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
End If
Case "Chat" 'if they are talking to ya
txtChat.SelStart = Len(txtChat) 'sets cursor position in chatroom
txtChat.SelText = strFriend & ":" & vbTab & strData2 & vbCrLf 'puts the chat into the room
End Select
End Sub
Vou colocar o codigo aqui pra ver se vcs me entedem melhor...
Na verdade e 1 chat e quero que quando o server escreva seja uma cor e quando o cliente escreva o nick seja de outra cor,resumindo uma cor pro server outra pro cliente,basta o nick!oBrigado ah todos!
Option Explicit
Dim strFriend As String 'holds servers name
Dim strMyName As String 'holds your name
Dim strFileName As String 'holds the name of the file u are receiving
Dim blnSend As Boolean 'if false, it wont send; if true it will
Dim strSize As String 'holds the size of the file
Dim strSoFar As String 'a var for calculating the KBps
Dim strBlock As String 'holds the data you are going to send
Dim strLOF As String 'holds the lenght of the file
Private Sub cmdSendChat_Click()
If Trim(txtSend.Text) = "" Then Exit Sub 'prevents someone trying to send nothing
Winsock.SendData "Chat" & txtSend.Text 'sends the text to the chat
txtChat.SelStart = Len(txtChat) 'put focus on the chat at the end so it is entered in the right place
txtChat.SelText = strMyName & ":" & txtSend.Text & vbCrLf 'puts the text in the chat
txtSend.Text = "" 'clears the textbox u type in
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock.Close 'closes winsock so program can end
End 'closes program
End Sub
Private Sub Timer1_Timer()
Label2.Visible = Not Label2.Visible
End Sub
Private Sub tmrKBps_Timer()
On Error Resume Next 'prevents error
lblKBps.Caption = "" & Format(strSoFar / 1000, "###0.0") & " / KBps" 'calculates the KBps
strSoFar = 0 'resets it so it can be calculated again
End Sub
Private Sub Winsock_Connect()
frmConnect.tmrClient.Enabled = False 'tell client to stop trying to connect cause it is connected =D
Winsock.SendData "Nick" & frmConnect.txtName.Text 'sends ur name to server
DoEvents 'i dunno why but i need it cause of winsock
strMyName = frmConnect.txtName 'saves ur name into memory
Me.Show 'shows frmclient
Unload frmConnect 'obvious
End Sub
Private Sub cmdSelect_Click()
CD.Flags = cdlOFNFileMustExist 'wont let someone open a file not there!
CD.Filter = "All Files (*.*)|*.*" 'filters all files to be shown!!!!!!!
CD.ShowOpen 'shows the open dialog box
txtFile.Text = CD.FileName 'puts the path of the file into the txtfile
End Sub
Private Sub cmdSend_Click()
On Error Resume Next 'prevents error
If txtFile.Text = "" Then Exit Sub 'wont let someone send something not there
strFileName = "" 'resets the filename
blnSend = False 'sets it to false
strSize = "" 'resets the size
Open txtFile.Text For Binary As #1 'opens the file u want to send so it can be read
strLOF = LOF(1) 'saves length of file into memory
Winsock.SendData "Name" & CD.FileTitle & ":" & strLOF 'sends server the name of the file and its length
DoEvents 'needed =D
Do While blnSend = False 'keeps looping until the server accepts the request
DoEvents 'lets u do stuff while in loop
Loop 'goes back to Do WHile statement
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next 'prevents error
Dim strData As String 'holds data for select case
Dim strData2 As String 'holds data
Call Winsock.GetData(strData, vbString) 'gets the data sent by the server
strData2 = Mid(strData, 5) 'gets data
strData = Left(strData, 4) 'gets data for select case
Select Case strData 'goes to the right case depending on strData
Case "File" 'a file transfer is in progress
Put 1, , strData2 'puts data into file
PBar.Value = PBar.Value + bytesTotal 'shows how much is done so far
strSoFar = strSoFar + bytesTotal 'calculates KBps
Winsock.SendData "OKOK keep sending!" 'tells them ur done with the data and u want some more!
DoEvents ' =D
Case "Name" 'server has sent u the filename and is ready to begin transfer
Dim intX As Integer 'holds position if :
intX = InStr(1, strData2, ":", vbTextCompare) 'gets position of :
strSize = Mid(strData2, intX + 1) 'holds the filesize
PBar.Max = strSize 'sets up the progressbar
strData = Mid(strData2, 1, intX - 1) 'holds filename
strFileName = strData 'puts filename into memory
Dim strResponse As String 'holds either a vbYEs or vbNo
strResponse = MsgBox(strFriend & " Quantos pra enviar [" & strFileName & "]. Vc deseja receber esse arquivo?", vbYesNo, "Arquivo A ser enviado !") '<=- easy to understand
If strResponse = vbYes Then 'if they said yes
Dim strType As String 'holds the type of file
strType = Right(strFileName, 3) 'gets the type of file
CD.FileName = strFileName 'sets the filename into the commondialog box
CD.Filter = "File Type (*." & strType & ")|*." & strType 'sets the filter to the filetype
CD.Flags = cdlOFNOverwritePrompt 'asks u if u want to overwrite file
CD.ShowSave 'shows the save commondialog box
Open CD.FileName For Binary As #1 'opens a file with the name and path u want
Winsock.SendData "OKOK i want the file" 'tell server u want the damn file
DoEvents 'yes another doevents
Me.Enabled = False 'disables to form to PREVENT ERROR!!!!!!!!!!
ElseIf strResponse = vbNo Then 'if they say no
Winsock.SendData "Nope dont want it!" 'tell em u dont want their crap!
DoEvents 'hmmm
End If 'ok enough of that madness
Case "Stop" 'the file exchange has ended
Close #1 'closes the file
'resets the progressbar
PBar.Value = 0
PBar.Max = 1
'=====================
Me.Enabled = True 'reenables the form!
Case "Nick" 'server has sent u their name
strFriend = strData2 'saves their name into memory
Case "Nope" 'tells u that they declined ur request to give em a file
MsgBox strFriend & " Arquivo recusado.", vbInformation, "Arquivo Cancelado!" '<=- easy to get again
Close #1 'closes the file
'stops the loops that was waiting for the boolean value to be true
Do
DoEvents
Loop
'==========================
Case "OKOK" 'tells u they want more of the file
blnSend = True 'tells u to keep sending
Me.Enabled = False 'keeps form disabled
PBar.Max = strLOF 'sets progressbar max to filesize
If Not EOF(1) Then 'does this if not the end of the file
If strLOF - Loc(1) < 2040 Then 'if you are at the last chunk of data
strBlock = Space$(strLOF - Loc(1)) 'sets the block size to the size of the data (cause its less!)
Get 1, , strBlock 'gets data
Winsock.SendData "File" & strBlock 'sends data
DoEvents ' =/
PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
strSoFar = strSoFar + (strLOF - Loc(1)) 'sets KBps
Winsock.SendData "Stop the maddness!" 'tells server THE TRANSFER IS ENDED!
Close #1 'closes file
'resets the progressbar
PBar.Max = 1
PBar.Value = 0
'====================
Me.Enabled = True 'reenables the form
Else 'if not the last chunk
strBlock = Space$(2040) 'sets block up to receive only 2040 bytes of data
End If
strSoFar = strSoFar + 2040 'calculates KBps
Get 1, , strBlock 'gets data
Winsock.SendData "File" & strBlock 'sends data
DoEvents 'hmmmm once again
PBar.Value = PBar.Value + Len(strBlock) 'sets progressbar
End If
Case "Chat" 'if they are talking to ya
txtChat.SelStart = Len(txtChat) 'sets cursor position in chatroom
txtChat.SelText = strFriend & ":" & vbTab & strData2 & vbCrLf 'puts the chat into the room
End Select
End Sub
Se você quiser algo assim
[txt-size=3]
Detalhe: Tudo em um ÃÅ¡NICO textbox (dentro), TANTO as mensagens dos CLIENTES e as mensagens do SERVIDOR..... com o MULT-LINE = TRUE
Não será POSSÃ ÂVEL!!!!!
Sugiro USAR um
RichTextBox (Project / Componentes)
Um forte Abraço...
[txt-size=3]
Nick(Cliente): [txt-color=#0000ff]Ola como vai?[/txt-color]
Nick(Server): [txt-color=#ff0000]Respeite as Regras do CHAT[/txt-color]
[/txt-size]Detalhe: Tudo em um ÃÅ¡NICO textbox (dentro), TANTO as mensagens dos CLIENTES e as mensagens do SERVIDOR..... com o MULT-LINE = TRUE
Não será POSSÃ ÂVEL!!!!!
Sugiro USAR um
RichTextBox (Project / Componentes)
Um forte Abraço...
Sim ate ai usar o RichTextBox,e facil,o problema e fazer ele fucionar,no caso o que fazer depois de usar ele?
So mais uma coisa: nao quero mudar a cor do texto "escrita" quero mudar a cor dos nicks,pra diferenciar 1 do outro...
Alguem hj ai pra da uma força?!
Obrigado!
Obrigado!
Vc já tentou usar MSFLEXGRID sem bordas?
é só vc configurar de acordo com o tipo de mensagem (client ou server) a propriedade:
.CellForeColor = vbRed ou vbBlue
irá funcionar perfeitamente....
pra ficar "bonitinho", tira a borda do grid (flat), sem linhas e colunas...
é só vc configurar de acordo com o tipo de mensagem (client ou server) a propriedade:
.CellForeColor = vbRed ou vbBlue
irá funcionar perfeitamente....
pra ficar "bonitinho", tira a borda do grid (flat), sem linhas e colunas...
Sim mas o qual o codigo q eu uso?
Tópico encerrado , respostas não são mais permitidas