Author | Message | Time |
---|---|---|
Eli_1 | How can I add [red]c[/red][green]olore[/green][red]d[/red] text to a RichTextBox control, while stopping it from scrolling? I've done it using SendMessage and .Text, but that was ghetto and had a few problems: 1) I couldn't add colored text. 2) 8:10 users of the program would have seizures due to the horrible flickering. Thanks in advance... | June 1, 2004, 11:21 PM |
Myndfyr | [quote author=Eli_1 link=board=31;threadid=7066;start=0#msg63139 date=1086132104] How can I add [red]c[/red][green]olore[/green][red]d[/red] text to a RichTextBox control, while stopping it from scrolling? I've done it using SendMessage and .Text, but that was ghetto and had a few problems: 1) I couldn't add colored text. 2) 8:10 users of the program would have seizures due to the horrible flickering. Thanks in advance... [/quote] What are you trying to do, exactly? How is your Add-Text function set up? | June 2, 2004, 12:53 AM |
Eli_1 | There is no addtext function set up currently. Here's a simple one I use sometimes: [code] Public sub AddText(atoutput as richtextbox, byval data as string, color as colorconstants) with atoutput .selstart = len(.text) .selcolor = color .seltext = data .selstart = len(.text) end with end sub [/code] My question wasn't very clear, I'm realizing. It's for a simple chat bot, where text is constantly being added to the textbox. But say someone says something funny like, "I like poopie", and I want to quote it. I have to scroll up and copy and paste it. But say he says something else while I'm trying to copy it, I'll be scrolled to the bottom again, because of .SelStart. This is what I'm trying to get around... | June 2, 2004, 2:30 AM |
hismajesty | [quote author=Eli_1 link=board=31;threadid=7066;start=0#msg63139 date=1086132104]2) 8:10 users of the program would have seizures due to the horrible flickering.[/quote] Use LockWindowUpdate to stop the flickering. [code]Public Declare Function LockWindowUpdate Lib "user32" (ByVal hwnd As Long) As Long[/code] | June 2, 2004, 2:43 AM |
Eli_1 | While that would work, the way I made it work would mean no colors -- a very boring chat bot. | June 2, 2004, 2:46 AM |
Stwong | Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;) | June 2, 2004, 4:02 AM |
Grok | [quote author=Stwong link=board=31;threadid=7066;start=0#msg63212 date=1086148968] Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;) [/quote] A good idea several of us have considered for years, but nobody has even started. We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots. | June 2, 2004, 4:11 AM |
CrAz3D | [quote author=Grok link=board=31;threadid=7066;start=0#msg63217 date=1086149484] [quote author=Stwong link=board=31;threadid=7066;start=0#msg63212 date=1086148968] Write the entire textbox yourself using the windows gdi and backbuffers so it wont flicker? :D This advice is probably thoroughly unhelpful, but there are gdi tutorials on google ;) [/quote] A good idea several of us have considered for years, but nobody has even started. We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots. [/quote] What would a StarCraft styled listbox be? | June 2, 2004, 5:59 AM |
Adron | [quote author=Grok link=board=31;threadid=7066;start=0#msg63217 date=1086149484] A good idea several of us have considered for years, but nobody has even started. We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots. [/quote] A Starcraft-styled ListBox is suboptimal because that ListBox doesn't support selecting and copying text. It might be better to just write the whole thing from scratch. | June 2, 2004, 9:31 AM |
iago | [me=iago]points to javax.swing.JTextPane[/me] oops! :-) | June 2, 2004, 6:03 PM |
Myndfyr | [quote author=Adron link=board=31;threadid=7066;start=0#msg63249 date=1086168679] [quote author=Grok link=board=31;threadid=7066;start=0#msg63217 date=1086149484] A good idea several of us have considered for years, but nobody has even started. We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots. [/quote] A Starcraft-styled ListBox is suboptimal because that ListBox doesn't support selecting and copying text. It might be better to just write the whole thing from scratch. [/quote] I'm using a managed wrapper of the MSHTML DHTML editor control. I haven't built in the logic for it to not scroll, and honestly, I've only thought about it a little. But look how easy it is: [code] void AddChatEvent(ChatEvent ce) { // this loop ensures that only 100 events are displayed at a time. // eventQueue is a Queue object (wow!) that stores the last 100 chat events (wow!) while (eventQueue.Count >= 100) { ChatEvent removing = eventQueue.Pop() as ChatEvent; // sbText is a StringBuilder object, for mutable, buffered strings // it holds the entire HTML that should be displayed // Instance method ChatEvent.ToString() converts the chat event into HTML text based on the event type // and data. sbText.Remove(removing.ToString()); // that takes the oldest chat event out. } // now we append the new event. sbText.Append(ce.ToString()); // find the element // he is the wrapped control, for HtmlEditor. HtmlEditor.Document is a wrapper for the IHTMLDocument, // IHTMLDocument2, IHTMLDocument3, IHTMLDocument4, IHTMLDocument5, and IHTMLDocument6 COM // interfaces. // To use these, you have to reference the interop assembly Microsoft.mshtml.dll IHTMLElement element = he.Document.getElementById("armabot_textinsert"); element.innerHTML = sbText.ToString(); // now if I want to scroll it, I find the element that I just inserted by its ID which is uniquely generated by the // ChatEvent class. IHTMLElement newElement = he.Document.getElementById(ce.Identifier); newElement.scrollIntoView(1 as object); } [/code] The HTML code that ChatEvent.ToString() emits is something like the following: [code] <span id="CE10352"><div class="time">[1.32.55 pm]</div> <div class="username">MyndFyre:</div> <div class="ChatText">Blah blah blah</div></span> [/code] The nice thing is that the HTML box also allows me to copy as plaintext or HTML: [quote] [1.25.23 pm] MyndFyre whispers: Instance ban is currently disabled. [1.29.47 pm] Slackware joined the channel with Warcraft II: Battle.net Edition. [1.29.49 pm] e1-: I have designated Slackware [1.38.49 pm] R.a.B.B.i.T[e1] has left the channel. [/quote] [code] <SPAN id=eid48><SPAN class=time>[1.25.23 pm]</SPAN> <SPAN class=whispername>MyndFyre whispers:</SPAN> <SPAN class=whisper>Instance ban is currently disabled.</SPAN></SPAN><BR><SPAN id=eid49><SPAN class=time>[1.29.47 pm]</SPAN> <SPAN class=userjoin>Slackware joined the channel with Warcraft II: Battle.net Edition.</SPAN></SPAN><BR><SPAN id=eid50><SPAN class=time>[1.29.49 pm]</SPAN> <SPAN class=moderatorname>e1-:</SPAN> <SPAN class=ChatText>I have designated Slackware</SPAN></SPAN><BR><SPAN id=eid51><SPAN class=time>[1.38.49 pm]</SPAN> <SPAN class=userleft>R.a.B.B.i.T[e1] has left the channel.</SPAN></SPAN> [/code] MSHTML HTML isn't exactly pretty, but it gets the job done :) Anyway, that's what I use. If you're up for a little bit of a learning curve, MSHTML IMHO is worth it. | June 2, 2004, 8:39 PM |
Adron | That looks nice. Adding text doesn't affect current cursor location, scroll position or similar? Can you type into it too, if you don't make it read-only? | June 2, 2004, 8:43 PM |
Myndfyr | [quote author=Adron link=board=31;threadid=7066;start=0#msg63312 date=1086208982] That looks nice. Adding text doesn't affect current cursor location, scroll position or similar? Can you type into it too, if you don't make it read-only? [/quote] If you don't use the scrollIntoView, then no, it won't affect scroll position. There's a way to make it editable as well, although I'm not familiar with all of the mechanics behind it (I'd have to look at the source, which I have available, but am not familiar with). Cursor location is probably the same way. | June 2, 2004, 8:47 PM |
Dyndrilliac | Eh, Why couldn't you just write a function that locks the chat temporarily, and during that time, filter all messages recieved into a queue type mechanism - then once chat is unlocked, have the queue attractively unload the messages it recieved onto the RTB and continue program flow normally? Edit: Here's Something I wrote quickly.[code]Public Type FQueue Username As String Flags As Long Message As String Ping As Long End Type Public MQueue() As FQueue Public QMax As Integer Public Sub InitializeFQueue() QMax = 100 ReDim MQueue(QMax) End Sub Public Function AddMQ(Username As String, Flags As Long, Message As String, Ping As Long) On Error GoTo ErrHandle Dim i As Integer Retry: i = 0 Do Until MQueue(i).Message = vbNullString i = i + 1 Loop MQueue(i).Username = Username MQueue(i).Flags = Flags MQueue(i).Message = Message MQueue(i).Ping = Ping Exit Function ErrHandle: ReDim Preserve MQueue(QMax) GoTo Retry End Function[/code] Then, when you have the OnTalk event and the chat is locked, do something like...:[code]Public Locked As Boolean Public LockTimer As Timer Public Sub LockTimer_Timer() Dim i As Integer For i = 0 To MQueue(QMax) If MQueue(i).Username = vbNullString Then Exit Sub End If AddC frmMain.Chat, vbGreen, "<" & Mqueue(i).Username &.......<you get the picture>... Next i InitializeFQueue End Sub Public Sub OnTalk(Username As String, Flags As Long, Message As String, Ping As Long) Dim QInterval As Integer If Locked = True Then AddMQ Username, Flags, Message, Ping LockTimer.Enabled = True LockTimer.Interval = QInterval End If End Sub[/code] Note: The above is untested, but for the most part it looks right. | June 2, 2004, 9:28 PM |
UserLoser. | [quote author=Grok link=board=31;threadid=7066;start=0#msg63217 date=1086149484] A good idea several of us have considered for years, but nobody has even started. We wanted to write a Starcraft-styled ListBox as a COM control in an ActiveX DLL, then distribute so VB programmers would have a better choice than a RichEdit control (RichTextBox) from which to start their bots. [/quote] Sounds like a good idea, maybe I can take a shot at this.. | June 3, 2004, 5:29 PM |
Eli_1 | [quote author=Dyndrilliac link=board=31;threadid=7066;start=0#msg63317 date=1086211724] Eh, Why couldn't you just write a function that locks the chat temporarily ...[/quote] That's the solution I decided to go with. But right now I just plan to call LockWindowUpdate (I think that's it) when the chat is locked, then unlock it. I might not be able to do this though[s], for one, I'm not sure if you're able to select text and copy it if the window is locked[/s] (silly me, yes you can). Also, I don't think I'll be able to add users to the channellist because drawing in the given window will be disabled... Thanks for all the suggestions. | June 3, 2004, 8:36 PM |
UserLoser. | [quote author=Eli_1 link=board=31;threadid=7066;start=15#msg63489 date=1086295014] [quote author=Dyndrilliac link=board=31;threadid=7066;start=0#msg63317 date=1086211724] Eh, Why couldn't you just write a function that locks the chat temporarily ...[/quote] That's the solution I decided to go with. But right now I just plan to call LockWindowUpdate (I think that's it) when the chat is locked, then unlock it. I might not be able to do this though[s], for one, I'm not sure if you're able to select text and copy it if the window is locked[/s] (silly me, yes you can). Also, I don't think I'll be able to add users to the channellist because drawing in the given window will be disabled... Thanks for all the suggestions. [/quote] Something like: [code] LockWindow(rtbChatOutput.hWnd) [/code] Might work, before were you using the dialog's hwnd? | June 3, 2004, 9:12 PM |
Eli_1 | [quote author=UserLoser. link=board=31;threadid=7066;start=15#msg63492 date=1086297132] Might work, before were you using the dialog's hwnd? [/quote] Yea, thanks Userloser. :) | June 4, 2004, 3:51 PM |
Skywing | I managed to hack up a passable solution for richedits to solve the position-changing-while-adding-text problem. It doesn't seem to work when you start using large font sizes (e.g. > 12 pt in most fonts) for some reason though. | June 6, 2004, 12:48 AM |
SPY-3 | if you made a good sc textbox control besure to add a color change for things like Á | August 27, 2004, 1:18 PM |