network stream question

G

Guest

hi, im working on a project that involves sending rich text over a netowkr
stream to show all the formatting and colors etc on the other side of the
program. i tried reading the .rtf of a richtextbox and sending that but then
cant add mroe text to the richtext box, atleast using the method i do

Dim bytes() As Byte = CType(ar.AsyncState, Byte())
Dim recv As String = ASCII.GetString(bytes, 0, numbytes)

Me.rtbreceivedtext.Rtf += recv & vbNewLine

how can i get my program to send the name of the font, the style, the color,
and the back color of the richtextbox and send it, and behave pretty much
like an instant messeneger where it shows everything that was sent, not just
wat was sent last. like i want it to look like a conversation but the
richtextbox keeps showing the most recent thing sent, not everything. ive
been working and researching this for a couple weeks now so if anyone can
help, thatd b great...

thanks
 
C

Chris

Can't you just serialize your RichTextBox object and send the XML file
to the other side?
 
G

Guest

how would i do that? sorry, ive nvr dealt with XML files before...if u can
send me any websites to help or explain it thatd b great
 
C

Chris

iwdu15 said:
how would i do that? sorry, ive nvr dealt with XML files before...if u can
send me any websites to help or explain it thatd b great

Sorry about that... Here's a quick link I found on google. The
RichTextBox probably isn't serializable, but this is an example of how
to serialize a TreeView...

http://www.codeproject.com/vb/net/TreeViewDataAccess.asp

You can use the same concept, create a new serializable structure that
contains all the data you need to send to the other text box (font
property, size, color etc). Serialize the structure, and write the xml
to your port. On the other side, open a byte reader, and deserialize
the xml.

Now that I think about it, this may not be the solution you're looking
for. Let me take a look at the RichTextBox and see how to get the stuff
you need out of it.
 
C

Chris

iwdu15 said:
how would i do that? sorry, ive nvr dealt with XML files before...if u can
send me any websites to help or explain it thatd b great

Ok.. Yeah I definitely should have read your entire question (my bad)
about the persisting text. I thought the question was just about making
one rtf box look like the other (in which case you can use
serialization, but it's just overkill).

So, doing it the way you're doing it right now... the only way I can
figure to do this would be to send RichTextBox.Rtf.

On the other side, you would need to take your existing Rtf (which would
look something like this), and insert the NEW Rtf in the correct place.
You'll need to devise some way of parsing the rich text string. Find
the position before the final } in RTF1, and insert everything between
the second to last and last } in RTF2.

So:

RTF1
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}{\f1\fnil\fcharset0 Arial;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs17 test cf1\f1\fs24 test\cf0\f0\fs17 test \par
}

RTF2
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}{\f1\fnil\fcharset0 Arial;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs17 the blue cow \cf1\f1\fs24 jumped\cf0\f0\fs17
over the brown fox\par
}

RTF Combined
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}{\f1\fnil\fcharset0 Arial;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\f0\fs17 test cf1\f1\fs24 test\cf0\f0\fs17 test \par
\viewkind4\uc1\pard\f0\fs17 the blue cow \cf1\f1\fs24 jumped\cf0\f0\fs17
over the brown fox\par
}

Once you have your RTF combined, set RichTextBox2.Rtf to your combined
rtf string.

Why don't you consider using a browser window or something instead of an
RichTextBox??
 
G

Guest

thanks so much for ur help, and theres most def an easier way i just have no
idea how to do it. im a n00b programmer that likes to try difficult things
and work through them to find out how they work, its weird but i learn best
this way. how would i use a brower window to do that? like theres a browser
window tool in the toolbox? sorry for asking so much im just a curious
programmer, so if u could elaborate a lil bit more thatd b awsome, and if not
thanks for all ur help so far
 
C

Chris

iwdu15 said:
thanks so much for ur help, and theres most def an easier way i just have no
idea how to do it. im a n00b programmer that likes to try difficult things
and work through them to find out how they work, its weird but i learn best
this way. how would i use a brower window to do that? like theres a browser
window tool in the toolbox? sorry for asking so much im just a curious
programmer, so if u could elaborate a lil bit more thatd b awsome, and if not
thanks for all ur help so far

No prob... I'm the same way. Sometimes it's the best way to learn. But
trust me when I say I'm no expert either, I only got into .NET because
my job required it. I'm just trying to get involved in the forums to
get more experience under my belt while I'm studying for my MCSD.

Anyhow... here's a link on how to get the browser control into your toolbox:

http://www.vb-helper.com/howto_net_set_webbrowser_contents.html

Then you can use simple HTML tags to send your messages, and just insert
them on the other side:
<span style="font-size:12px;color:red;">Hello</span> <strong>World</strong>.

You'll probably want to read up on the System.Web.UI namespaces for
writing out your HTML.

If you want to learn how to use XML, this would be a good chance. Read
up on transforming XML into HTML for display using XSL. You'll need to
learn about XPath, XslTransform, XmlReader, XPathNavigator, etc... You
can google on any of these and find some good examples. (like so:
http://www.google.com/search?hl=en&lr=&q=vb.net+xml+to+html) Then you
can make a smartphone or pocket pc client for your chat server :) If
you're planning getting a job programming, better learn XML now. I have
to deal with it every day..

You may want to check out http://www.codeproject.com. You'll have to
sign up (free) to download source code, but it has many good examples,
and ideas that you may find useful for your app.

Sorry I can't help more but I have a product update I have to get out by
next week.

Hope that helps...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Continues TCP recieve 2
Email Sockets Question 1
NNTP Client 4
Stream from Image? 3
Network Stream behaving strangely. 3
Merging data received via TCP 4
variable Bytes question 5
network read question 2

Top