Add RichTextBox example.

This commit is contained in:
haru-s 2023-05-06 00:29:43 +09:00
parent 6f28659c9a
commit 1cc86dd86d
10 changed files with 291 additions and 0 deletions

View file

@ -19,6 +19,7 @@ DFL is a Win32 windowing library for the D language.
![screen shot](./examples/timer/image/screenshot.png "screen shot")
![screen shot](./examples/contextmenu/image/screenshot.png "screen shot")
![screen shot](./examples/toolbar/image/screenshot.png "screen shot")
![screen shot](./examples/richtextbox/image/screenshot.png "screen shot")
## Recent major features
- DUB is available for DFL.

16
examples/richtextbox/.gitignore vendored Normal file
View file

@ -0,0 +1,16 @@
.dub
docs.json
__dummy.html
docs/
/hello_dfl
hello_dfl.so
hello_dfl.dylib
hello_dfl.dll
hello_dfl.a
hello_dfl.lib
hello_dfl-test-*
*.exe
*.pdb
*.o
*.obj
*.lst

View file

@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (Windows) richtextbox",
"type": "cppvsdbg",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "./bin/richtextbox_sample.exe",
"console": "internalConsole"
}
]
}

23
examples/richtextbox/.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dub",
"run": false,
"cwd": ".",
"compiler": "$current",
"archType": "$current",
"buildType": "$current",
"configuration": "$current",
"problemMatcher": [
"$dmd"
],
"group": "build",
"label": "dub: Build richtextbox_sample",
"detail": "dub build --compiler=dmd.EXE -a=x86_64 -b=debug -c=application",
"presentation": {
"clear": true
}
}
]
}

View file

@ -0,0 +1,2 @@
# Screen Shot
![screen shot](./image/screenshot.png "screen shot")

View file

@ -0,0 +1,16 @@
{
"authors": ["haru-s"],
"copyright": "Copyright (C) 2023 haru-s",
"description": "DFL sample code.",
"name": "richtextbox_sample",
"targetType": "executable",
"targetPath": "bin",
"dependencies": {
"dfl": {
"path": "../../../dfl"
}
},
"lflags-windows-x86_omf-dmd": ["/exet:nt/su:windows:6.0"],
"lflags-windows-x86_mscoff-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"],
"lflags-windows-x86_64-dmd": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 206 KiB

View file

@ -0,0 +1,12 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"d.projectImportPaths": [
"..\\..\\..\\dfl\\source"
]
}
}

View file

@ -0,0 +1,3 @@
set dmd_path=c:\d\dmd2\windows
set dmc_path=c:\dmc\dm
cmd

View file

@ -0,0 +1,205 @@
import dfl;
import std.conv;
version(Have_dfl) // For DUB.
{
}
else
{
pragma(lib, "dfl.lib");
}
class MainForm : Form
{
private RichTextBox _textbox1;
private ToolBar _toolBar;
this()
{
// Form setting
this.text = "RichTextBox sample";
this.size = Size(800,400);
// ToolBar setting
_toolBar = new ToolBar;
_toolBar.parent = this;
_toolBar.dock = DockStyle.TOP;
ToolBarButton button1 = new ToolBarButton("Bold");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button1)
_textbox1.selectionBold = !_textbox1.selectionBold;
};
_toolBar.buttons.add(button1);
ToolBarButton button2 = new ToolBarButton("UnderLine");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button2)
_textbox1.selectionUnderline = !_textbox1.selectionUnderline;
};
_toolBar.buttons.add(button2);
ToolBarButton button3 = new ToolBarButton("Font");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button3)
{
auto fontDialog = new FontDialog;
DialogResult dr = fontDialog.showDialog();
if (dr == DialogResult.OK)
_textbox1.selectionFont = fontDialog.font;
}
};
_toolBar.buttons.add(button3);
ToolBarButton button4 = new ToolBarButton("BaseUp");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button4)
{
if (_textbox1.selectionCharOffset <= 0)
_textbox1.selectionCharOffset = 72;
else
_textbox1.selectionCharOffset = 0;
}
};
_toolBar.buttons.add(button4);
ToolBarButton button5 = new ToolBarButton("BaseDown");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button5)
{
if (_textbox1.selectionCharOffset >= 0)
_textbox1.selectionCharOffset = -72;
else
_textbox1.selectionCharOffset = 0;
}
};
_toolBar.buttons.add(button5);
ToolBarButton buton6 = new ToolBarButton("F.Color");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is buton6)
{
auto colorDialog = new ColorDialog;
DialogResult dr = colorDialog.showDialog();
if (dr == DialogResult.OK)
_textbox1.selectionColor = colorDialog.color;
}
};
_toolBar.buttons.add(buton6);
ToolBarButton button7 = new ToolBarButton("B.Color");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button7)
{
auto colorDialog = new ColorDialog;
DialogResult dr = colorDialog.showDialog();
if (dr == DialogResult.OK)
_textbox1.selectionBackColor = colorDialog.color;
}
};
_toolBar.buttons.add(button7);
ToolBarButton button8 = new ToolBarButton("^X");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button8)
{
_textbox1.selectionSuperscript = !_textbox1.selectionSuperscript;
}
};
_toolBar.buttons.add(button8);
ToolBarButton button9 = new ToolBarButton("_X");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button9)
{
_textbox1.selectionSubscript = !_textbox1.selectionSubscript;
}
};
_toolBar.buttons.add(button9);
ToolBarButton button10 = new ToolBarButton("GetText");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button10)
{
msgBox(_textbox1.selectedText);
}
};
_toolBar.buttons.add(button10);
ToolBarButton button11 = new ToolBarButton("InsText");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button11)
{
_textbox1.selectedText = "[Insert Text]";
}
};
_toolBar.buttons.add(button11);
ToolBarButton buton12 = new ToolBarButton("GetRtf");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is buton12)
{
static if (1)
{
string rtf = _textbox1.selectedRtf;
}
else
{
string rtf = _textbox1.rtf;
}
msgBox(rtf);
static if (0)
{
_textbox1.rtf = rtf;
}
}
};
_toolBar.buttons.add(buton12);
ToolBarButton button13 = new ToolBarButton("GetSelNum");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button13)
{
msgBox(to!string(_textbox1.selectionLength));
}
};
_toolBar.buttons.add(button13);
ToolBarButton button14 = new ToolBarButton("SetSel(5)");
_toolBar.buttonClick ~= (ToolBar tb, ToolBarButtonClickEventArgs e) {
if (e.button is button14)
{
_textbox1.selectionLength = 5;
}
};
_toolBar.buttons.add(button14);
// RichTextBox setting
_textbox1 = new RichTextBox();
_textbox1.dock = DockStyle.FILL;
_textbox1.font = new Font(_textbox1.font.name, 14f);
_textbox1.multiline = true;
_textbox1.scrollBars = RichTextBoxScrollBars.FORCED_VERTICAL;
// _textbox1.acceptsReturn = true; // true: Enables RETURN key.
_textbox1.acceptsTab = true; // false: Disables TAB key.
// true: Enables TAB key. But be changed focus only
// because one line textbox is not able to input TAB char.
_textbox1.wordWrap = false; // false: Do not send words that span the right edge to the next line.
_textbox1.text = "Hello.\nhttp://g/ <- click\nこんにちは。";
_textbox1.linkClicked ~= (RichTextBox sender, LinkClickedEventArgs e) {
msgBox(e.linkText);
};
_textbox1.parent = this;
}
}
static this()
{
// Application.enableVisualStyles();
}
void main()
{
Application.run(new MainForm());
}