Help with HTML panel

derez

Expert
Licensed User
Longtime User
I found the HTML panel library and it seems exact to upgrade my chat program, but...
I don't understand the HTML language and the help file just adds to my confusion.

Can someone tell me how to do the following:

write a string on the panel, each separate string in one of few predefined formats (e.g. - font size and text color).

The strings are created in real time so I cannot use preset HTML files for them.

As strings are written, the panel should scroll down to show the last string written.

Thanks.
 

derez

Expert
Licensed User
Longtime User
thank you for the elaborated explanation and example.
I'll study it.:)

Edit:
The code is what I took from the example, to demonstrate what I wanted.
It still lacks the automatic scroll down after each input - I can't do it.
the form has a textbox and a button.

B4X:
Sub Globals
   Dim myPageText
   k = 1
End Sub

Sub App_Start
   Form1.Show   
   HtmlPanel.New1("Form1", 0, 0,220,200)
   HtmlPanel.ButtonColor = cWhite
   HtmlPanel.ScrollBarWidth = 10
   HtmlPanel.RenderWidth = 210
End Sub


Sub Button1_Click
k = -1 * k
st =  tb.Text
If k = 1 Then
   myPageText = myPageText & "<font color='red'>" & st & "</font><br />"
Else
    myPageText = myPageText & "<font color='green'>" & st & "</font><br />"
End If
HtmlPanel.ShowHtml ("<html><body>" & myPageText & "</body></html>")
tb.Text = ""
End Sub
 
Last edited:

derez

Expert
Licensed User
Longtime User
Thanks Andrew, it works now.

The problem was the missing +1 at the end, see the help:

"VScrollValue : Int32 [I/O] : Gets or sets the position of the vertical scrollbar. The minimum to use is 0 and the maximum is VScrollMax - VScrollLargeChange otherwise the underlying Panel will become visible."
 

agraham

Expert
Licensed User
Longtime User
The problem was the missing +1 at the end
I'm surprised, the +1 is a nicety that avoids a final 1 pixel movement of the the panel if you press the scroll bar down button. The difference is hardly visible so it should have scrolled to the bottom without it :confused:
 

derez

Expert
Licensed User
Longtime User
If I remove the +1 I get this error.
 

Attachments

  • html.jpg
    html.jpg
    29 KB · Views: 173

derez

Expert
Licensed User
Longtime User
I used the panel in the Chat program, here are screen views of the way text is formatted according to the message source.
Also - I attach a sub to show how I change the color of the last line (I do it to signal the reception of the message by the other side)

both last and myPageText are globals.

B4X:
Sub write_line(st,source)
Select source 
    Case "R"   ' Remote message
       last = "<font color='blue' size='12'>" & st & "</font><br />"
      myPageText = myPageText & last
   Case "L"   ' Local message
       st = StrReplace(st,Chr(0),"")  'remove hebrew device control charachter 
       last = "<font color='black' size='10'> " & st & "</font><br />"
      myPageText = myPageText & last
   Case "M"    ' Machine message
       last = "<font color='red' size='12'>" & st & "</font><br />"
      myPageText = myPageText & last
End Select
HtmlPanel.ShowHtml ("<html><body>" & myPageText & "</body></html>")
HtmlPanel.VScrollValue = HtmlPanel.VScrollMax - HtmlPanel.VScrollLargeChange + 1
End Sub

Sub change_color
myPageText = StrReplace(myPageText,last,"")
last = StrReplace(last,"color='black'","color='green'")
myPageText = myPageText  & last
HtmlPanel.ShowHtml ("<html><body>" & myPageText & "</body></html>")
End Sub

Thanks to Badkarma and Agraham :)
 

derez

Expert
Licensed User
Longtime User
It comes as part of the Hebrew language package which is installed on my device.
 
Top