View previous topic :: View next topic |
Author |
Message |
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Thu Dec 23, 2004 6:00 pm Post subject: HowTo: Selection in textbox? |
|
|
I'm unclear on how to cause visible selection of a char[] within a multiline viewerTextBox.
I've tried various combinations of the following calls. I'm expecting that the selected text will be either highlighted or reverse video, but the viewerTextBox's appearance doesn't change.
int len = curSearchVerse.length;
int index = find(viewerTextBox.text, curSearchVerse);
viewerTextBox.hideSelection = false;
viewerTextBox.selectionStart = index;
viewerTextBox.selectionLength = len;
viewerTextBox.select(index, len);
Actually, I'm fuzzy on how to cause selection highlighting (reverse video) of a non-multiline TextBox. Nothing happens with the following code:
searchWordsTextBox.text = "1234567890";
searchWordsTextBox.hideSelection = false;
searchWordsTextBox.select(3, 5);
searchWordsTextBox.selectionStart(3);
searchWordsTextBox.selectionLength(5); |
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Fri Dec 24, 2004 12:05 am Post subject: Re: HowTo: Selection in textbox? |
|
|
Lynn wrote: | I'm unclear on how to cause visible selection of a char[] within a multiline viewerTextBox. |
The handle has to be created. Call it's createControl() function or wait until onHandleCreated(). |
|
Back to top |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Fri Dec 24, 2004 8:34 am Post subject: |
|
|
I see.. when I was making an example I found that setting the selection in some events doesn't work as expected.
For the record,
Code: | selectionStart = pos;
selectionLength = len; |
is the same as
and they use EM_SETSEL, so I guess it's a Windows thing. But here's my example that works. I found that setting the selection in a multiline textbox won't scroll to the caret, so I forced it to:
Code: | class MainForm: Form
{
TextBox single, multi;
this()
{
Button sbtn;
with(sbtn = new Button)
{
text = "&s btn";
parent = this;
click ~= &sbtn_click;
}
with(single = new TextBox)
{
left = sbtn.right + 4;
text = "Open Source Development for D Open Source Development for D Open Source Development for D"
" dsource.org";
hideSelection = false;
parent = this;
}
Button mbtn;
with(mbtn = new Button)
{
top = 40;
text = "&m btn";
parent = this;
click ~= &mbtn_click;
}
with(multi = new TextBox)
{
text = "Open Source Development for D\r\nOpen Source Development for D\r\nOpen Source Development for D"
"\r\nOpen Source Development for D\r\nOpen Source Development for D\r\nOpen Source Development for D"
" dsource.org";
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 epos;
epos = std.string.rfind(single.text, 'e');
if(epos != -1)
{
single.select(epos, 1);
}
}
private void mbtn_click(Object sender, EventArgs ea)
{
int epos;
epos = std.string.rfind(multi.text, 'e');
if(epos != -1)
{
multi.select(epos, 1);
multi.scrollToCaret();
}
}
} |
|
|
Back to top |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Mon Dec 27, 2004 7:26 pm Post subject: |
|
|
Thanks MUCHO for the example.
I tweaked it a bit into a complete program suitable to be a tutorial. Also, the revised code does more than look for the single character 'e' and makes sure that caret scrolling to take place.
Submitted to dfl.tutorial as:
http://dsource.org/tutorials/index.php?show_example=138 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|