---
# System prepended metadata

title: wxRichTextCtrl - Read Only version by R-CO
tags: [wxWidgets]

---

# wxRichTextCtrl - Read Only version by R-CO

## wxRichTextReadOnlyCtrl.hpp
```cpp=
#include <wx/richtext/richtextctrl.h>

class wxRichTextReadOnlyCtrl : public wxRichTextCtrl
{
public:
	explicit wxRichTextReadOnlyCtrl(wxWindow* parent, wxWindowID id = -1, const wxString& value = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
		long style = wxRE_MULTILINE, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxTextCtrlNameStr);

	virtual void AppendTextWithoutMoveCaret(const wxString& value, int flags = 0);
	virtual bool NewLineWithoutMoveCaret();
protected:
private:
};
```

## wxRichTextReadOnlyCtrl.cpp
```cpp=
#include "wxRichTextReadOnlyCtrl.hpp"

#include "wx/textfile.h"

wxRichTextReadOnlyCtrl::wxRichTextReadOnlyCtrl(wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
	: wxRichTextCtrl(parent, id, value, pos, size, style | wxRE_READONLY, validator, name)
{
}

void wxRichTextReadOnlyCtrl::AppendTextWithoutMoveCaret(const wxString& value, int flags)
{
    wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix);

    
    GetFocusObject()->InsertTextWithUndo(&GetBuffer(), GetLastPosition(), valueUnix, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
    if (!IsFrozen())
    {
        wxRichTextDrawingContext context(&GetBuffer());
        GetBuffer().Defragment(context);
    }

    if (flags & SetValue_SendEvent)
        wxTextCtrl::SendTextUpdatedEvent(this);
}

bool wxRichTextReadOnlyCtrl::NewLineWithoutMoveCaret()
{
    return GetFocusObject()->InsertNewlineWithUndo(&GetBuffer(), GetLastPosition(), this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
}
```

## Examples
### Auto-Scroll after appending text without moving current caret position
```cpp=
// wxRichTextReadOnlyCtrl *rich_text_read_only_ctrl = new wxRichTextReadOnlyCtrl(parent);
const bool auto_scroll = (rich_text_read_only_ctrl->IsPositionVisible(-1));

rich_text_read_only_ctrl->AppendTextWithoutMoveCaret(wxS("Hello world!\n"));

if (auto_scroll) {
    rich_text_read_only_ctrl->ShowPosition(rich_text_read_only_ctrl->GetLastPosition());
}
```

### In wxFormBuilder
![](https://i.imgur.com/BzKrIpv.png)

###### tags: `wxWidgets`