Current filter:
                                You should refresh the page.
                                0
                                  • I have an attached sample project that I am testing on how to display basic html text in a cardview, I followed the example E3167. I added a new property LinesCount as in some cases in our full project we want to limit the number of lines displayed as some data is very long, if LineCount = 0 all the field data is shown, but if in the case the LineCount=3 (use spinedit at top of form) the editor has a height of 3 lines but 4 lines of data, is there a way to display a scrollbar for this control so that the user can read all the data?

                                Custom Text Box.zip
                                You must  log in  or  register  to leave comments

                                1 Solution

                                0

                                Hi Michael,

                                Thank you for your message. To implement a scrolling functionality to your custom editor is not a trivial task. So, an easier way to resolve this issue is to use our RichEditControl. It can also show HTML text and provide the scroll bars feature by default.

                                I would like to note that the text for a RichEditControl in this case must have HTML mark up format.

                                If you wish to limit the CardView in-place editor height, we suggest that you use the RepositoryItemRichTextEdit.MaxHeight property.

                                I hope this information will be helpful to you. Feel free to contact us if you have any further difficulty. We are happy to help you at any time.

                                Updated by Yulia 15.08.2012 18:30

                                To implement a scrollbar in your custom editor, add the VScrollBar control to the editor's Controls property. Handle the VScrollBar.ValueChanged event and override the custom BaseEditPainter.DrawContent method in the following manner:

                                	
                                [VB.NET]
                                Public Sub New() _scrollBar = New VScrollBar() _scrollBar.Dock = DockStyle.Right AddHandler _scrollBar.ValueChanged, AddressOf vScroller_ValueChanged Me.Controls.Add(_scrollBar) End Sub Private Sub vScroller_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Dim vScroller As VScrollBar = TryCast(sender, VScrollBar) TryCast(Me.Painter, HtmlLabelPainter).ScrollBarValue = vScroller.Value Me.Refresh() End Sub Protected Overrides Sub DrawContent(ByVal info As ControlGraphicsInfoArgs) Dim rect As New Rectangle(info.ViewInfo.ContentRect.X, info.ViewInfo.ContentRect.Y - _scrollBarValue, info.ViewInfo.ContentRect.Width, info.ViewInfo.ContentRect.Height) info.Graphics.FillRectangle(info.ViewInfo.PaintAppearance.GetBackBrush(info.Cache), info.ViewInfo.ContentRect) Dim viewInfo As HtmlLabelViewInfo = TryCast(info.ViewInfo, HtmlLabelViewInfo) Dim item As RepositoryItemHtmlLabel = TryCast(viewInfo.Item, RepositoryItemHtmlLabel) If item.AllowHtmlString Then rect.Height = 0 Dim _stringInfo As StringInfo = RepositoryItemHtmlLabel.CalculateStringInfo(info.Graphics, viewInfo.PaintAppearance, viewInfo.DisplayText, rect) StringPainter.Default.DrawString(info.Cache, _stringInfo) Else info.Cache.DrawString(viewInfo.DisplayText, viewInfo.PaintAppearance.Font, viewInfo.PaintAppearance.GetForeBrush(info.Cache), viewInfo.ContentRect, viewInfo.PaintAppearance.GetStringFormat()) End If End Sub

                                To specify the upper limit of values in the scrollable range, use the VScrollBar.Maximum property. We suggest that you override the OnEditValueChanged method to calculate the VScrollBar.Maximum property value. Here is a sample code snippet that illustrates this task:

                                	
                                [VB.NET]
                                Protected Overrides Sub OnEditValueChanged() MyBase.OnEditValueChanged() Dim rect As New Rectangle(0, 0, Width - _scrollBar.Width, 0) Try TryCast(Me.Painter, HtmlLabelPainter).ScrollBarValue = 0 Dim _stringInfo As StringInfo = RepositoryItemHtmlLabel.CalculateStringInfo(Me.ViewInfo.GInfo.AddGraphics(Nothing), Me.ViewInfo.PaintAppearance, Me.ViewInfo.DisplayText, rect) ' ContentRect) Dim result = _stringInfo.Bounds.Height - Me.ViewInfo.Bounds.Height _scrollBar.Maximum = result + _scrollBar.LargeChange - 1 Finally Me.ViewInfo.GInfo.ReleaseGraphics() End Try End Sub

                                In addition, I have created and attached a sample project illustrating this task.

                                Q422992.zip
                                Show all comments
                                • Michael 7 08.10.2012

                                  Hi,

                                  Thanks for the reply, I had looked at using the RepositoryItemRichTextEdit but from our end user point of view the data that is required to be displayed only requires basic tags associated with it not a full html document syntax and styles and in that respect the custom RepositoryItemHtmlLabel works exactly to their requirements, they don't want the added overhead of the added html. Also in addition to that we could also implement the custom RepositoryItemHtmlLabel in shorter text fields of 100 chars where the RepositoryItemRichTextEdit would not work as the added html formatting would cause the data to exceed the field size. Note the sample you included appears to have some functionality the is not available in v9.3.7 eg RichEditDocumentServer, correct me if I'm wrong.

                                  So returning to the original query you have indicated that "it is not a trivial task", does that imply that it is still possible and what course of action is required?

                                • Thank you for your reply. Yes, you are right. RichEditDocumentServer is not supported in version 9.3.7, but you can use RichEditControl instead.

                                  To implement a scrollbar in your custom editor, add the VScrollBar control to the editor's Controls property. In addition, handle the VScrollBar.Scroll event and override the custom BaseEditPainter.DrawContent method in the following manner:

                                  Private Sub vScroller_Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs)
                                          Dim vScroller As VScrollBar = TryCast(sender, VScrollBar)
                                          TryCast(Me.Painter, HtmlLabelPainter).ScrollBarValue = vScroller.Value
                                          Me.Refresh()
                                  
                                      End Sub
                                  
                                  
                                  Protected Overrides Sub DrawContent(ByVal info As ControlGraphicsInfoArgs)
                                          Dim rect As New Rectangle(info.ViewInfo.ContentRect.X, info.ViewInfo.ContentRect.Y - _scrollBarValue, info.ViewInfo.ContentRect.Width, info.ViewInfo.ContentRect.Height)
                                          info.Graphics.FillRectangle(info.ViewInfo.PaintAppearance.GetBackBrush(info.Cache), info.ViewInfo.ContentRect)
                                          Dim viewInfo As HtmlLabelViewInfo = TryCast(info.ViewInfo, HtmlLabelViewInfo)
                                          Dim item As RepositoryItemHtmlLabel = TryCast(viewInfo.Item, RepositoryItemHtmlLabel)
                                          If item.AllowHtmlString Then
                                              Dim stringInfo As StringInfo = RepositoryItemHtmlLabel.CalculateStringInfo(info.Graphics, viewInfo.PaintAppearance, viewInfo.DisplayText, rect)
                                              StringPainter.Default.DrawString(info.Cache, stringInfo)
                                          Else
                                              info.Cache.DrawString(viewInfo.DisplayText, viewInfo.PaintAppearance.Font, viewInfo.PaintAppearance.GetForeBrush(info.Cache), viewInfo.ContentRect, viewInfo.PaintAppearance.GetStringFormat())
                                          End If
                                  End Sub
                                  

                                  I have modified and attached your sample project for your reference. Let us know if the suggested approach helps and do not hesitate to contact us in the future. We are always happy to help you.

                                • Michael 7 08.14.2012

                                  Thank you for the updated project, I have added the VScrollBar as suggested and the scroll works but when I am only displaying for example 2 lines and scroll the visible 2 lines of text scrolls up and out of view as expected but the remaining 3 lines of text are not painted. Please refer to attached image.

                                • I have reproduced the issue. Please refer to my previous answer for the most recent updates on this task.

                                • Michael 7 08.15.2012

                                  Thank you Yulia, assistance much appreciated, the solution has fixed my issue

                                • I'm glad to hear that my assistance was helpful to you. Thank you for informing us. We greatly appreciate it!

                                You must  log in  or  register  to leave comments
                                You must  log in  or  register  to leave an answer

                                Is your intention to post an answer to your own question?

                                • If so, then proceed.
                                • If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
                                • If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.