View previous topic :: View next topic |
Author |
Message |
JWood KiXforms Dabbler

Joined: 04 Sep 2008 Posts: 9 Location: Phoenix, AZ
|
Posted: Wed Sep 10, 2008 10:00 pm Post subject: Rich Text Box and Buttons and events, oh my..... |
|
|
I have a need to have a button visible but disabled until a user scrolls to the end of a rich text box. Reaching the end of the text box should enable the button on the form. the whole 'read to the end before you can click accept' process.
I don't see any events associated with the Rich Text Box that I could use to find the end of the filed and trigger the Button to be enabled.
I'm open to suggestions here...
Thank you in advance!
-James |
|
Back to top |
|
 |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Fri Sep 12, 2008 12:07 pm Post subject: |
|
|
Great question! Going to investigate some options today. Anyone else try scripting this yet ?
-Shawn |
|
Back to top |
|
 |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Fri Sep 12, 2008 2:01 pm Post subject: |
|
|
Here's a scriptlet for those that want to attempt a solution. Looks "challenging" to say the least ...
Code: |
Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form()
$Form.Size = 640, 480
$RichTextBox = $Form.RichTextBox()
$RichTextBox.Location = 10,10
$RichTextBox.Right = $Form.ClientWidth - 10
$RichTextBox.Bottom = $Form.ClientHeight - 50
$RichTextBox.Anchor = 15
$RichTextBox.Text = GetLegalText()
$AcceptButton = $Form.Button()
$AcceptButton.Center
$AcceptButton.Top = $RichTextBox.Bottom + 5
$AcceptButton.Text = "I Accept"
$AcceptButton.Enabled = 0
$Form.Center
$Form.Show
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function GetLegalText()
Dim $i
For $i = 1 to 100
$GetLegalText = $GetLegalText + "This is line " + $i + @CRLF
Next
EndFunction
|
|
|
Back to top |
|
 |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Fri Sep 12, 2008 11:13 pm Post subject: |
|
|
k, heres a first stab ...
Code: |
Break On
$System = CreateObject("Kixtart.System")
$Form = $System.Form()
$Form.Size = 640, 480
$Form.Text = "Attention! Legal stuff here!"
$Form.FontSize = 10
$Label = $Form.Label()
$Label.Location = 10,10
$Label.Width = $Form.ClientWidth - 10
$Label.Text = 'Read the following text. Press PAGEDOWN for more. Click "I Accept" when done.'
$RichTextBox = $Form.RichTextBox()
$RichTextBox.ScrollBars = 0
$RichTextBox.Top = $Label.Bottom + 5
$RichTextBox.Left = 10
$RichTextBox.Right = $Form.ClientWidth - 10
$RichTextBox.Bottom = $Form.ClientHeight - 50
$RichTextBox.Anchor = 15
$RichTextBox.Text = GetLegalText()
$RichTextBox.OnKeyDown = "RichTextBox_KeyDown()"
$TargetSelectionStart = CalculateTargetSelectionStart($RichTextBox)
$AcceptButton = $Form.Button()
$AcceptButton.Center
$AcceptButton.Top = $RichTextBox.Bottom + 5
$AcceptButton.Text = "I Accept"
$AcceptButton.Enabled = 0
$AcceptButton.OnClick = "AcceptButton_Click()"
$Form.Center
$Form.Show
$RichTextBox.Focus
While $Form.Visible
$= Execute($Form.DoEvents)
Loop
Exit 0
Function GetLegalText()
Dim $i
For $i = 1 to 100
$GetLegalText = $GetLegalText + "This is line " + $i + @CRLF
Next
EndFunction
Function RichTextBox_KeyDown()
If $TargetSelectionStart = $RichTextBox.SelectionStart
$AcceptButton.Enabled = 1
$AcceptButton.FontBold = 1
Endif
EndFunction
Function AcceptButton_Click()
$Form.Hide
EndFunction
Function CalculateTargetSelectionStart($TextBox)
$Len = Len($TextBox.Text)
$Rows = UBound(Split($TextBox.Text,CHR(10)))
$CalculateTargetSelectionStart = $Len - $Rows
EndFunction
|
|
|
Back to top |
|
 |
JWood KiXforms Dabbler

Joined: 04 Sep 2008 Posts: 9 Location: Phoenix, AZ
|
Posted: Mon Sep 15, 2008 4:03 pm Post subject: |
|
|
I see where you are going with this... Let me play with it some and see what happens...
Thanks for the effort! |
|
Back to top |
|
 |
Shawn KiXforms Developer


Joined: 22 Feb 2003 Posts: 1983 Location: Canada
|
Posted: Mon Sep 15, 2008 5:12 pm Post subject: |
|
|
Yeah, had to turn-off the scrollbar because (as you know) there aint no scroll event  |
|
Back to top |
|
 |
JWood KiXforms Dabbler

Joined: 04 Sep 2008 Posts: 9 Location: Phoenix, AZ
|
Posted: Mon Sep 15, 2008 5:24 pm Post subject: |
|
|
Yeah, that was the first event I looked for. I never thought about testing for the cursor location... I think this is going to work for me though! I'll post some samples when I get it working...
Thanks again! |
|
Back to top |
|
 |
JWood KiXforms Dabbler

Joined: 04 Sep 2008 Posts: 9 Location: Phoenix, AZ
|
Posted: Mon Sep 15, 2008 9:41 pm Post subject: A Twist... |
|
|
The issue now seems to be that the rich text box is getting it's content from a file...
Code: | $RichTextBox.LoadFile("FileName.rtf") |
Does this affect the .text property? It seems to not be working the same.
UPDATE:
I can return a non-zero number for the elngth of the .Text property after the .LoadFile method executes.
Why would this not work?
Code: | If Len($rtb.Text) = $rtb.SelectionStart
$ButtonAccept.Enabled = 1
EndIf
|
|
|
Back to top |
|
 |
Gargoyle KiXforms Aficionado


Joined: 30 Dec 2003 Posts: 366 Location: Arizona
|
Posted: Tue Sep 16, 2008 3:52 am Post subject: |
|
|
$button.enabled is a boolean value.
Therefore to be true set it to -1 _________________ Parents were invented to make children happy by giving them something to ignore. |
|
Back to top |
|
 |
JWood KiXforms Dabbler

Joined: 04 Sep 2008 Posts: 9 Location: Phoenix, AZ
|
Posted: Tue Sep 16, 2008 2:55 pm Post subject: |
|
|
It seems that .rtf files must have hidden characters in them because the length of the .Text property is 4812 while I can only get the cursor in the rtb to move to character 4784. Where is how I enabled the button...
Code: | Function fnAUAKeyDown()
$Loc = $rtbAua.SelectionStart
If $Loc > 4783
$btnAuaAccept.Enabled = 1
EndIf
EndFunction |
Works just like a champ every time...
Thanks for all the input!!! |
|
Back to top |
|
 |
|