DFL TextBox with Selection reverse video
Part of DflCategory
Description
Demonstrates how to find and select text in single-line and multi-line TextBoxes such that the found characters are highlighted in reverse video. For the multi-line TextBox, the selected chars aren't visible, so scrollToCaret is used to bring it into view.
Example
import std.stdio, std.string; import dfl.form, dfl.textbox, dfl.button, dfl.event, dfl.application, dfl.drawing; class MainForm: Form { TextBox single, multi; this() { Button sbtn; with(sbtn = new Button) { text = "&Find 'ment for'"; parent = this; click ~= &sbtn_click; } with(single = new TextBox) { left = sbtn.right + 4; text = "Open Source Development for D Open Source Development for D"; hideSelection = false; parent = this; } Button mbtn; with(mbtn = new Button) { top = 40; text = "&Find 'for D 6'"; parent = this; click ~= &mbtn_click; } with(multi = new TextBox) { text = "Line 1 Open Source Development for D 111\r\n" "Line 2 Open Source Development for D 222\r\n" "Line 3 Open Source Development for D 333\r\n" "Line 4 Open Source Development for D 444\r\n" "Line 5 Open Source Development for D 555\r\n" "Line 6 Open Source Development for D 666\r\n" "Line 7 Open Source Development for D 777\r\n" "Line 8 Open Source Development for D 888\r\n" "Line 9 Open Source Development for D 999"; hideSelection = false; bounds = Rect(mbtn.right + 4, mbtn.top, 200, 60); multiline = true; acceptsReturn = true; parent = this; } } private void sbtn_click(Object sender, EventArgs ea) { int foundOffset = std.string.rfind(single.text, "ment for"); if(foundOffset != -1) { single.select(foundOffset, 8); // 8 is len of 'ment for' } } private void mbtn_click(Object sender, EventArgs ea) { int foundOffset = std.string.rfind(multi.text, "for D 6"); if(foundOffset != -1) { multi.select(foundOffset, 7); // 7 is len of 'for D 6' multi.scrollToCaret(); } } } void main() { Application.run(new MainForm); }
Source
Link | http://www.dsource.org/tutorials/index.php?show_example=138 |
Posted by | Lynn |
Date/Time | Mon Dec 27, 2004 7:23 pm |