Alright, this turned out to be a task that is not for the faint of heart. I am sure there is a better way, but this is the best I could do.
In a nutshell, I created my own form that extends the Keyoti.RapidSpell.RapidSpellGUI class. I added a text box called txtOrig and set the size (and more importantly minimum size, because the Check() method seems to size the form down uless you have a minimum set) to 500,305. I didn't do anything with the text box in design view so I can show you in code where its' positioned. I didn't mess around with any of the pre-existing components, but you can if you want.
The form also needs to accept a string (containing text to check), a reference to a form(to send the fixed text back to), and the name of the form to send the fixed text back to. I must have tried a million ways, but this is the only one that worked for me (well others worked, but this was more flexible - more on that in a minute). Here is the code for my form:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Keyoti.RapidSpell;
namespace SpellCheckTest
{
public partial class ChkForm : Keyoti.RapidSpell.RapidSpellGUI
{
public Form fTemp;
public string sName;
public ChkForm()
{
InitializeComponent();
//size the text box
txtFix.Location = new Point(306, 11);
txtFix.Multiline = true;
txtFix.Size = new Size(174, 250);
txtFix.Visible = true;
txtFix.ScrollBars = ScrollBars.Vertical;
}
public ChkForm(string txt, Form fIn, string controlName)
{
//need the text, a reference to the form, and the control on the form's name
//in order to pass the text back once it is checked
InitializeComponent();
//size the text box
txtFix.Location = new Point(306,11);
txtFix.Multiline = true;
txtFix.Size = new Size(174,250);
txtFix.Visible = true;
txtFix.ScrollBars = ScrollBars.Vertical;
txtFix.Text = txt;
fTemp = fIn;
sName = controlName;
}
public void myCheck()
{
this.SetTextComponentToCheck(txtFix);
this.Check();
}
public void myCheck(string txt)
{
this.txtFix.Text = txt;
this.SetTextComponentToCheck(txtFix);
this.Check();
}
public void setText(string txt)
{
txtFix.Text = txt;
}
public void setControlName(string controlName)
{
sName = controlName;
}
}
}
At this point, we are still not done. The check() method that we need to use seems to be calling dispose(), because everyt time I tried retrieving the text from the form's text box using a property or method (outside dispose()), it was already gone. So, I hacked the dispose() method to try and send back text. Here is the method (in the form designer) - make sure that you have referenced System.Reflection namespace on your form:
Code:
protected override void Dispose(bool disposing)
{
try
{
fTemp.Controls[sName].Text = txtFix.Text;
}
catch (System.NullReferenceException ex)
{
//do nothing
}
finally
{
fTemp = null;
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
}
Before putting this in production I would make sure the error handling is VERY strong!
Finally, here is how I called it from my main form:
Code:
private void button3_Click(object sender, EventArgs e)
{
ChkForm myCHK = new ChkForm(txtOrig.Text, this, "txtOrig");
myCHK.myCheck();
}
Like I said I'm sure there is a better way, but this works alright. There is a lot avaialable in there that you can use to customize your form further too. The hardest part seems to be making it return the text to your original form.
I hope this helps,
Alex
[small]----signature below----[/small]
I don't do any programming whatsoever
Ignorance of certain subjects is a great part of wisdom