KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

RichText SelectedRTF?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Fri Aug 17, 2007 2:22 am    Post subject: RichText SelectedRTF? Reply with quote

Hi All,
I'm would like to make an app that allows people to save/print labels. It will read from a DB and make the labels based on templates. As part of this, I would like to create a template editor that allows people to set the font, size, bold, underline, and italic properties on selected RichText. I see that I obviously need to edit the RTF property, but I don't think it's currently possible to find the selected text that includes the RichText markup. Any suggestions on how I should approach this?
Thanks,
Richard
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Aug 17, 2007 12:49 pm    Post subject: Reply with quote

Quote:

I see that I obviously need to edit the RTF property,


Well yes and no. The RichTextBox control has properties that make this much easier for the developer. Here are the properties:

SelectionAlignment
SelectionBackColor
SelectionColor
SelectionFont

All your supposed to do is let the user make the selection (or you can make the selection in code) then set the appropriate property to whatever (color, font) then the RichTextBox will set the selection accordingly.

The problem is that Kixforms.Classic doesn't have these properties. Kixforms.Net has a few of them - if you can try Kixforms.Net - here is some sample code of what I think your trying to do ...

If your really set on using classic - I can have a look at adding a few of these properties - let me know.

Code:

Break On

$System = CreateObject("Kixforms.System")

$Form = $System.Form()

$MainMenu = $System.MainMenu()

$FileMenu = $MainMenu.MenuItems.Add($System.Menuitem("File"))

$ExitMenu = $FileMenu.MenuItems.Add($System.Menuitem("Exit"))
$ExitMenu.Click = "ExitMenu_Click($$System.Sender, $$System.EventArgs)"

$FormatMenu = $MainMenu.MenuItems.Add($System.Menuitem("Format"))

$FontMenu = $FormatMenu.MenuItems.Add($System.Menuitem("Font..."))
$FontMenu.Click = "FontMenu_Click($$System.Sender, $$System.EventArgs)"

$Form.Menu = $MainMenu

$RichTextBox = $Form.Controls.Add($System.RichTextBox())
$RichTextBox.Dock = 5
$RichTextBox.Text = "
Name: Shawn Tassie
Address: Toronto, Ontario, Canada
Phone: 123-456-7890"

$ColorDialog = $System.ColorDialog()
$FontDialog = $System.FontDialog()

$Form.Center
$Form.Show
While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function ExitMenu_Click($sender, $e)

 quit

EndFunction

Function FontMenu_Click($sender, $e)

 $FontDialog.Color = $RichTextBox.SelectionFont

 If $FontDialog.ShowDialog() <> $System.DialogResult_Ok
  Return
 Endif

 $RichTextBox.SelectionFont = $FontDialog.Font

EndFunction
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Sat Aug 18, 2007 9:11 pm    Post subject: Reply with quote

Shawn, you're my hero! Very Happy I'm afraid I do need to use KiXforms classic as this is going to be part of an app that is already over 6900 lines of code. The properties you have listed
Quote:
SelectionAlignment
SelectionBackColor
SelectionColor
SelectionFont
would be ideal not only for my app but would also make the RichTextBox control much more useful. Would the SelectionFont property in Classic be assigned a font object or a font name string? Naturally, if it is a font object, it would then be possible to set the font style (bold etc) on the selected text.

If it is not too much trouble and you would be so kind as to add those properties, I will post back code to the forum for a rich text editor when I am finished.

Much respect and thanks,

Richard
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sat Aug 18, 2007 9:41 pm    Post subject: Reply with quote

I would be glad to add them One thing though - would you be willing to give a brand new build of Kixforms.Classic a try ? Its a re-built version - using the latest and greatest compiler - just one thing though ...

Do you use "expando" properties in your script ? You know, where you create your own properties like this:

$Form.MyLabel = $Form.Controls.Label(...)
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Sun Aug 19, 2007 2:08 am    Post subject: Reply with quote

Hi Shawn,
I'm more than willing to give a new version a try! Very Happy It sounds exciting... I like to use the latest and greatest! I do use expando's but not extensively. I mainly use them to bind data to objects.
Code:
Function MachineDetails($Dataset,Optional $UpdateArray)

   If Not VarType($Dataset)
      $=$ErrBox.Show("No data to display")
      Exit
   EndIf
   Dim $ActiveForm,$frmMachineDetails,$tabMachineDetails,$pgMachineDetails,$aCurrent,$aData,$aRecord,$i,$j,$Shown
   $btnCancel.Visible = 1
   $ActiveForm = $System.ActiveForm
   $ActiveForm.BeginUpdate
   $Console.BeginUpdate
   $frmMachineDetails = $System.Form($ActiveForm)
   $frmMachineDetails.BackColor = $MediumBlue
   $frmMachineDetails.ForeColor = $DarkBlueText
   $frmMachineDetails.FontSize = $Console.FontSize
   $frmMachineDetails.FontName = "Tahoma"
   $frmMachineDetails.Size = 890, 710
   $frmMachineDetails.Icon = 56
   $frmMachineDetails.Name = "frmMachineDetails"
   $frmMachineDetails.Resizable = 0
   $frmMachineDetails.Dataset = $Dataset
   $frmMachineDetails.QueryCount = IIf($UpdateArray,$QueryCount,"")
   $frmMachineDetails.Text = "Retrieved Inventory Record"+IIf(VarType($Dataset.SelectedIndexes)& 8192,"","s")
   $aCurrent = $frmMachineDetails.DataSet.Data

As I allow users to create multiple versions of each child form, I need to be able to bind to and get specific data associated with the creation of the form. I can however replace such expando properties if you are wanting to no longer support them Smile

Thanks again,

Richard
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Aug 19, 2007 2:22 am    Post subject: Reply with quote

yeah, i like using expandos too. its not that I dont want to support them - i love them - its just that they're not working under the new compiler (vs2005) - so I temporarily disabled them for now ... let me have another lookie to see if I can get them going again. It would be a shame to have to re-write your stuff.
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Sun Aug 19, 2007 2:30 am    Post subject: Reply with quote

Thanks, anything you do I'm grateful for, I don't wish to put you through too much trouble.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Aug 19, 2007 5:15 pm    Post subject: Reply with quote

No trouble.

Firstly ... if you could give the new Kixforms.Classic development build a try - and advise whether things look good - than we can use that as our base for the changes ... heres the link:

http://www.kixforms.org/forum/viewtopic.php?p=10995#10995

Think I got that Expando issue licked.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Sun Aug 19, 2007 9:16 pm    Post subject: Reply with quote

Ok, check-out the latest dev. build. I added the RichTextBox.SelectionColor property - just want to make sure we're on the right track ... here's a sample script to go with it ...

Code:

Break On

$dotnet = 0

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Width = 640
$Form.Height = 480
$Form.DockPadding = 10

$MainMenu = $System.MainMenu()

$FileMenu = $MainMenu.MenuItems.Add("File")

$ExitMenu = $FileMenu.MenuItems.Add("Exit")
$ExitMenu.OnClick = "ExitMenu_Click($$System.Sender, $$System.EventArgs)"

$FormatMenu = $MainMenu.MenuItems.Add("Format")

$ColorMenu = $FormatMenu.MenuItems.Add("Color...")
$ColorMenu.OnClick = "ColorMenu_Click($$System.Sender, $$System.EventArgs)"

$Form.Menu = $MainMenu

$RichTextBox = $Form.Controls.Add("RichTextBox")
$RichTextBox.Dock = "Fill"
$RichTextBox.FontName = "Arial"
$RichTextBox.FontSize = 10

For $i = 1 To 10
 $RichTextBox.Text = $RichTextBox.Text + "The quick brown fox jumped over the lazy moon." + @CRLF
Next

$ColorDialog = $System.ColorDialog()

$Form.Center
$Form.Show
While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function ExitMenu_Click($sender, $e)

 $Form.Hide

EndFunction

Function ColorMenu_Click($sender, $e)

 If $ColorDialog.ShowDialog <> $System.DialogResult.Ok
  Return
 Endif

 $RichTextBox.SelectionColor = $ColorDialog.Color

EndFunction

Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon Aug 20, 2007 12:06 am    Post subject: Reply with quote

Perfect! That is exactly what the RichTextBox control (and I) needs. I've also verified that expandos are working as well. I've noticed the binary is significantly larger, I guess that is a combination of more features and perhaps compiler optimisation? I am curious however about the $dotnet = 0. Is that simply to show that this is a classic script?

Richard
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 20, 2007 12:30 am    Post subject: Reply with quote

Yeah I noticed the binary size too. Its a combination of a bigger ATL library (we went from version 6 to 8 ) and a bigger WTL library (went from version 7 to 8 I believe) ... and all the other crap the new compiler threw in. I cant remember off-hand how big the old one was - how big ?

The $dotnet = 0 is just a test I threw in this rtf test script. I had it running Classic and kf.net code in one script - that flag just turned on which library I was doing. Been a while since I coded some classic stuff. Forgot lots of stuff man. Got to admit, classic is nice to use.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 20, 2007 12:45 am    Post subject: Reply with quote

How you planning on setting the font ? You going to provide buttons or menu-items for each font property (name, size, bold...) or you going to let the user open the FontDialog and select it from there ?

Would be more straight-forward if I implemented the SelectionXXX version of the existing FontXXX properties, like this:

FontName = "name"
SelectionFontName = "name"

FontSize = 10
SelectionFontSize = 10

FontBold = 1
SelectionFontBold = 1

and so on ... more properties to deal with but if it makes sense lets go for it.
Back to top
View user's profile Send private message
It Took My Prozac
KiXforms Supporter
KiXforms Supporter


Joined: 15 Feb 2005
Posts: 65

PostPosted: Mon Aug 20, 2007 1:19 am    Post subject: Reply with quote

The size of the previous binary was 676 KB compared to 944 KB now. I not concerned by this at all; as far as I'm concerned bigger is generally better. I was intending on providing menu items for each font property with a combo box for font names as I think this is more intuitive for the users. I think your suggestion to separate out each font property as its own property is a good one. That said, I'm very happy either way you decide to do it Smile Maybe you could do both or would that complicate things too much?
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 20, 2007 1:25 am    Post subject: Reply with quote

Good idea. Going to do both.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 20, 2007 1:48 pm    Post subject: Reply with quote

Posted a new build. Kixforms now has all the functionality required for your project I think. The RichTextBox.SelectionFont property is not there yet though ... heres the latest test harness ...

Code:

Break On

$dotnet = 0

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.Width = 640
$Form.Height = 480
$Form.DockPadding = 10

$MainMenu = $System.MainMenu()

$FileMenu = $MainMenu.MenuItems.Add("File")

$ExitMenu = $FileMenu.MenuItems.Add("Exit")
$ExitMenu.OnClick = "ExitMenu_Click($$System.Sender, $$System.EventArgs)"

$FormatMenu = $MainMenu.MenuItems.Add("Format")

$ColorMenu = $FormatMenu.MenuItems.Add("Color...")
$ColorMenu.OnClick = "ColorMenu_Click($$System.Sender, $$System.EventArgs)"

$Form.Menu = $MainMenu

$ToolPanel = $Form.Controls.Add("Panel")
$ToolPanel.Height = 24
$ToolPanel.Dock = "Top"

$Fonts = "Arial", "Courier New", "Times New Roman", "Verdana"

$FontNameComboBox = $ToolPanel.Controls.Add("ComboBox")
$FontNameComboBox.Left = 5
For Each $Font In $Fonts
 $FontNameComboBox.AddItem($Font)
Next
$FontNameComboBox.Text = $Fonts[0]
$FontNameComboBox.OnSelectedIndexChanged = "FontNameComboBox_SelectedIndexChanged($$System.Sender, $$System.EventArgs)"

$Sizes = 8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72

$FontSizeComboBox = $ToolPanel.Controls.Add("ComboBox")
$FontSizeComboBox.Left = $FontNameComboBox.Right + 5
$FontSizeComboBox.Width = 50
For Each $Size In $Sizes
 $FontSizeComboBox.AddItem($Size)
Next
$FontSizeComboBox.Text = $Sizes[0]
$FontSizeComboBox.OnSelectedIndexChanged = "FontSizeComboBox_SelectedIndexChanged($$System.Sender, $$System.EventArgs)"

$BoldButton = $ToolPanel.Controls.Add("Button")
$BoldButton.Left = $FontSizeComboBox.Right + 5
$BoldButton.Width = 75
$BoldButton.Height = $FontNameComboBox.Height
$BoldButton.FontBold = 1
$BoldButton.Text = "Bold"
$BoldButton.ToolTipText = "Make the selection bold"
$BoldButton.OnClick = "BoldButton_Click($$System.Sender, $$System.EventArgs)"

$ItalicButton = $ToolPanel.Controls.Add("Button")
$ItalicButton.Left = $BoldButton.Right + 5
$ItalicButton.Width = 75
$ItalicButton.Height = $BoldButton.Height
$ItalicButton.FontItalic = 1
$ItalicButton.Text = "Italic"
$ItalicButton.ToolTipText = "Make the selection Italic"
$ItalicButton.OnClick = "ItalicButton_Click($$System.Sender, $$System.EventArgs)"

$UnderlineButton = $ToolPanel.Controls.Add("Button")
$UnderlineButton.Left = $ItalicButton.Right + 5
$UnderlineButton.Width = 75
$UnderlineButton.Height = $ItalicButton.Height
$UnderlineButton.FontUnderline = 1
$UnderlineButton.Text = "Underline"
$UnderlineButton.ToolTipText = "Make the selection Underline"
$UnderlineButton.OnClick = "UnderlineButton_Click($$System.Sender, $$System.EventArgs)"

$RichTextBox = $Form.Controls.Add("RichTextBox")
$RichTextBox.Dock = "Fill"
$RichTextBox.FontName = "Arial"
$RichTextBox.FontSize = 10

For $i = 1 To 10
 $RichTextBox.Text = $RichTextBox.Text + "The quick brown fox jumped over the lazy moon." + @CRLF
Next

$ColorDialog = $System.ColorDialog()

$Form.Center
$Form.Show

$RichTextBox.Focus

While $Form.Visible
 $= Execute($Form.DoEvents)
Loop

Exit 0

Function ExitMenu_Click($sender, $e)

 $Form.Hide

EndFunction

Function ColorMenu_Click($sender, $e)

 If $ColorDialog.ShowDialog <> $System.DialogResult.Ok
  Return
 Endif

 $RichTextBox.SelectionColor = $ColorDialog.Color

EndFunction

Function FontNameComboBox_SelectedIndexChanged($sender, $e)

 $RichTextBox.SelectionFontName = $FontNameComboBox.Text
 $RichTextBox.Focus

EndFunction

Function FontSizeComboBox_SelectedIndexChanged($sender, $e)

 $RichTextBox.SelectionFontSize = $FontSizeComboBox.Text
 $RichTextBox.Focus

EndFunction

Function BoldButton_Click($sender, $e)

 $RichTextBox.SelectionFontBold = Not $RichTextBox.SelectionFontBold
 $RichTextBox.Focus

EndFunction

Function ItalicButton_Click($sender, $e)

 $RichTextBox.SelectionFontItalic = Not $RichTextBox.SelectionFontItalic
 $RichTextBox.Focus

EndFunction

Function UnderlineButton_Click($sender, $e)

 $RichTextBox.SelectionFontUnderline = Not $RichTextBox.SelectionFontUnderline
 $RichTextBox.Focus

EndFunction
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group