This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChapterViewer.cpp
52 lines (47 loc) · 1.66 KB
/
ChapterViewer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "ChapterViewer.h"
ChapterView::ChapterView(Chapter^ chp)
{
chapterBuffer = gcnew VTable(Chapter::typeid);
chapterBuffer->Add(0, chp);
chapterBuffer->Add(1, chp);
chapterBuffer->Add(2, chp);
rtb = gcnew System::Windows::Forms::RichTextBox;
rtb->Font = gcnew System::Drawing::Font("Arial", 12);
rtb->Multiline = true;
//rtb->Dock = System::Windows::Forms::DockStyle::Fill;
rtb->WordWrap = true;
rtb->Text += "\n\n";
rtb->Text += safe_cast<Chapter^>(chapterBuffer(0))->Name + "\n\n";
rtb->Text += (safe_cast<Chapter^>(chapterBuffer(0))->Text->ToString()->Replace('\r', ' '));
rtb->AppendText(safe_cast<Chapter^>(chapterBuffer(1))->Text->ToString()->Replace('\r', ' '));
rtb->Height = 570;
rtb->Width = 800;
rtb->ReadOnly = true;
this->Controls->Add(rtb);
rtb->VScroll += gcnew System::EventHandler(this, &ChapterView::OnVScroll);
//this->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &ChapterView::OnScroll);
}
void ChapterView::ExecuteEvent(ChapterView^ sender, System::EventArgs^ e, unsigned int i)
{
switch (i) {
case 0:
OnOpen(sender, e);
break;
}
}
void ChapterView::OnScroll(System::Object^ sender, System::Windows::Forms::ScrollEventArgs^ e)
{
if (e->NewValue > rtb->Height - 5) {
rtb->AppendText(safe_cast<Chapter^>(chapterBuffer(2))->Text->ToString()->Replace('\r', ' '));
rtb->Height = rtb->TextLength;
}
}
void ChapterView::OnVScroll(System::Object^ sender, System::EventArgs^ e)
{
rtb->DeselectAll();
this->Select();
if ((rtb->GetPositionFromCharIndex(0).Y * -1) > rtb->TextLength / 4) {
ExecuteEvent(this, nullptr, 0);
rtb->AppendText(safe_cast<Chapter^>(chapterBuffer(2))->Text->ToString()->Replace('\r', ' '));
}
}