|
Came across the following code here in response to another question.
The idea was to spell check some text. I want to do the same thing, but with only instantiating the objects once. The reason for this is I'm going to be checking a ton of strings one at a time, and don't want to keep creating new objects. (good reasons for doing so, but probably not relevant)
The main question is how do I ensure only the current string is being checked? The .dll was not document friendly.
doc.Words.First.InsertBefore(tBox.Text);
Thanks to anyone who takes the time to answer this,
<br />
<br />
public void fSpellCheck(TextBox tBox, Label lLbl) <br />
<br />
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();<br />
<br />
<br />
object template = Missing.Value;<br />
object newTemplate = Missing.Value;<br />
object documentType = Missing.Value;<br />
object visible = true;<br />
object optional = Missing.Value;<br />
<br />
_Document doc = app.Documents.Add<br />
(ref template,<br />
ref newTemplate,<br />
ref documentType,<br />
ref visible);<br />
<br />
doc.Words.First.InsertBefore(tBox.Text);<br />
Microsoft.Office.Interop.Word.ProofreadingErrors we = doc.SpellingErrors;<br />
iErrorCount = we.Count;<br />
doc.CheckSpelling(ref optional, ref optional, ref optional,<br />
ref optional, ref optional, ref optional, ref optional,<br />
ref optional, ref optional, ref optional,<br />
ref optional, ref optional);<br />
if (iErrorCount == 0)<br />
lLbl.Text = "Spelling OK. No errors corrected ";<br />
else if (iErrorCount == 1)<br />
lLbl.Text = "Spelling OK. 1 error corrected ";<br />
else<br />
lLbl.Text = "Spelling OK. " + iErrorCount +<br />
" errors corrected ";<br />
object first = 0;<br />
object last = doc.Characters.Count - 1;<br />
<br />
|
|
|
|
|
For no reason whatsoever I made a Console project with the following code:
<br />
namespace ConsoleApplication1<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
try<br />
{<br />
<br />
bool[] damn_big_array = new bool[2147483647];<br />
}<br />
catch (OutOfMemoryException oome)<br />
{<br />
Console.WriteLine(oome.Message);<br />
}<br />
Console.Read();<br />
}<br />
}<br />
}<br />
Now 2147483647 is the max value that can be held in 31 bits(Int32 or int). I run this with TaskManager open. Despite having over 600 MB of RAM free (I have a total of 1.25 GB) I get the OutOfMemoryException. Is there some limit it how much space .Net programs can use?
|
|
|
|
|
Are you kidding?
See here [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
What are you getting at? I know int and Int32 uses 4 bytes: 1 Bit for sign and 31 for the number. So:
2^31 - 1 = 2147483647 = 01111111111111111111111111111111
Whereas uint:
2^32 - 1 = 4294967295 = 11111111111111111111111111111111
|
|
|
|
|
sizeof bool is 1 byte , hence you're asking for 2 Gb of memory.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Oh whoops my bad. lol
Thanks.
|
|
|
|
|
On a 32 bit system, each application can only address 2 GB of memory.
You are trying to allocate a 2 GB array, which is more than your computer has. Also, as the application already uses some memory (stack, heap, code) there isn't 2 GB left in the virtual address space for the application.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hello.
I have a simple picturebox where there is a image loaded in
Im drawing a rectangle on the picturebox and when I press a button I want to invalidate it (remove the rectangle), but it doesnt seem to work
The rectangle is drawn fine and the image loads up to, but when I press my button nothing happens
Here is the code im using:
private void drawOnPic()<br />
{<br />
Graphics g = Graphics.FromImage(pictureBox1.Image);<br />
<br />
Pen PenStyle = new Pen(Color.Red, 1);<br />
<br />
g.DrawRectangle(PenStyle, 20, 20, 50, 50);<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
pictureBox1.Invalidate();<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
drawOnPic();<br />
}
|
|
|
|
|
Hi,
Graphics.FromImage(pictureBox1.Image); gives you access to the internals of
the image the PB is showing. g.DrawRectangle(...); modifies this image;
such modification is irreversible, invalidating the PB only tells it to repaint itself,
hence showing the modified image again.
If you want to be able to undo graphic stuff,
either paint on top of the PB (using its OnPaint handler)
or keep a copy of the original image, so you can restore it (PB.Image=oldImage;).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
In these days, in our project ,I must develop a logon page use c# language, it's a windows form project,for example:
1 The userName textbox coule only accept letter and numer digits ,and it exclude "@#$%&*(^_|" ,etc.
2 the roomid textbox could only accept the numeric digit ,but when the user input is 1.02,32.0,33.8 ,etc, which is not i expect.
Hao can i do ,any help is appreciated!
thank you very much .
|
|
|
|
|
either use a MaskedTextbox or use a regular TextBox and let the KeyPress handler reject
all characters you don't want (you probably should allow all char.IsControl so BACKSPACE
and CTRL/C and CTRL/V remain operational).
All the details (as well as the above) can be found in the documentation; and Google is a
nice way of locating it.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
hey guys
i have a URL saved in a string like http://codeproject.com/something.htm
i'd only like to select the domain name part of it (codeproject.com)
how can i do it?
page link can also be http://www.code... or www.code...
thank you
|
|
|
|
|
Create a Uri object with your stored string. Then access the Host property.
Example:
Uri url = new Uri("http://www.codeproject.com");<br />
string domainName = url.Host;
Ryan Bost
|
|
|
|
|
wow! i was never knew about Uri!
thank you so much!
|
|
|
|
|
Is it possible to make the soapformatter ignore missing fields?
Eg if the file have been saved in a previous format and I later try to deserialize it into a new format where not all fields match 100%
Im aware of [OptionalField], but that is the opposite of what I want.
Optional lets me introduce new fields into my format.
I want to simply ignore old fields that are not used any more.
And I also know that I can implement ISerializable, but I do not want that, I just want to use the default mechanism but ignoring missing fields.
(last resort would be to roll my own formatter, but im trying to avoid that)
|
|
|
|
|
Hello all,
Does anybody knows how to change the default caption text in the ColorDialog component of .Net 2.0? Default it is set to "Color", while I want to be able to change this into: "Select foreground color".
With regards,
EiSl
|
|
|
|
|
How do I publish an XNA project? I want to be able to send it in an eMail.
- I love D-flat!
- Need. More. Code.
modified on Saturday, April 5, 2008 6:29 PM
|
|
|
|
|
Repost your question here
|
|
|
|
|
I did.
- I love D-flat!
- Need. More. Code.
|
|
|
|
|
Hi. I need to take a screen shot of a control - the control is plotterForm.expressionPlotter. I am using the following code:
<br />
private Bitmap GetBitmap()<br />
{<br />
Bitmap bmp = new Bitmap(plotterForm.expressionPlotter.Width, plotterForm.expressionPlotter.Height);<br />
Graphics g = Graphics.FromImage(bmp);<br />
Screen screen = Screen.FromControl(plotterForm.expressionPlotter);<br />
g.CopyFromScreen(new Point(screen.Bounds.Location.X, screen.Bounds.Location.Y), Point.Empty, plotterForm.expressionPlotter.Size);<br />
return bmp;<br />
}
The problem is that the location of which the screen shot is always the upper left corner of the desktop, not the upper left corner of the control.
In other words the screen.Bounds.Location is a point which is always (0;0). When i added MessageBox.Show(screen.ToString()); i received the following message:
Screen[Bounds={X=0,Y=0,Width=1024,Height=768} WorkingArea={X=0,Y=0,Width=1024,Height=739} Primary=True DeviceName=\\.\DISPLAY1
As if the screen hasn't captured the control. How can i fix this???
Still learning...
|
|
|
|
|
I realized that the Screen.FromControl is something entirely different from the thing i expected! But here comes another question - how can i find the location of a control in relation to the desktop?
Still learning...
|
|
|
|
|
Use...
PointToScreen(control.Location);
Matthew Butler
|
|
|
|
|
Can you not just use DrawToBitmap as in:
int height = plotterForm.expressionPlotter.Height;
int width = plotterForm.expressionPlotter.Width;
Bitmap bmp = new Bitmap(width, height);
plotterForm.expressionPlotter.DrawToBitmap(bmp, new Rectangle(0,0,width,height));
Because if you could i imagine it will be much easier.
My current favourite word is: Nipple!
-SK Genius
|
|
|
|
|
I changed the code of the project a little bit and the control which i want to capture is a panel. The panel has a written text using the DrawString method of the Graphics class.The screen shot is stored in the clipboard. When i take a screen shot using DrawToBitmap , when i paste the image in paint it appears, but the text isn't there.
The taken screen shot[^]
The image as it should be[^]
Why doesn't the DrawToBitmap method capture the text???
Still learning...
|
|
|
|
|
i don't know, i had trouble with a textbox not drawing the text when i used DrawToBitmap. Then all of a sudden it just started working. and i'm not sure why/
My current favourite word is: Nipple!
-SK Genius
|
|
|
|