|
Thank you for your answer. I agree that user should never see an exception, but I think it is even better to write correct code and avoid the exception, rather than displaying the error message. Exception would be nice if for instance the .dot file doesn't exist, but here it seems to be different.
About the empty : the Find.Execute function takes 15 parameters. The VBA help of Word gives me the feeling that none are supposed to be empty, but false. I have tried to use empty with some of these parameters, that are supposed to be facultative, but it changed nothing.
So I'm in need of more specific solution.
About the naming convention: I usually don't use hungarian notation, except in two cases. First, to differentiate between some parameters (like if I have a member Param, and a parameter Param), or when I'm porting an old C++ code, which is the case here, and I forget to rename a few classes or function.
|
|
|
|
|
Stephane David wrote:
but I think it is even better to write correct code and avoid the exception, rather than displaying the error message.
I don't agree, exceptions are meant to happen and be handled, it doesn't necessarily mean they are bad. Since you need to properly handle them and using a MessageBox to the user is typically a good option, when it is pertinent. Some exceptions can be handled internally, however when they are of value to the user, they should be informed.
- Nick Parker My Blog
|
|
|
|
|
That's what I meant. In that case, the only information I can provide the user with is "this function doesn''t work, and I don't know how to make it work". If the error happens 100% of the time, then is it not an exception, it really is a programming error. It doesn't prevent me from handling the exception, but it is not a solution to my problem.
|
|
|
|
|
Stephane David wrote:
I agree that user should never see an exception, but I think it is even better to write correct code and avoid the exception, rather than displaying the error message.
This is a bad assumption! Did you write Microsoft Word? I'm betting you didn't, so why trust the work of other people whom you probably don't know, and code in another application where a whole different set of problems exist? Never do. Never trust user input, and never trust another application. Always account for problems that might occur. Do you think that Word blindly accepts input from calling functions?
And just because a parameter takes a value of true doesn't mean that the converse is false . Look again at the type: Variant . When a variant isn't specified, it is an empty or missing variant, hence using Missing.Value (or sometimes you see
Type.Missing).<br />
<br />
I found this example on MSDN: <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtosearchfortextinworddocuments.asp">How to: search for text in Word documents</a>[<a target=_blank title='New Window' href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtosearchfortextinworddocuments.asp">^</a>]. They use <code>Type.Missing to find text. You have the right values for the ReplaceWith and Replace parameters. Also, you can search over the whole document (since in the example they set the range to the first two paragraphs) by using Document.Content instead of Application.Selection.Range , which - if I remember correctly - is an empty range anyway. I don't know about that, though - it's been a while since I programmed with the Office libraries. In any case, Document.Content is a Range over the whole document, which seems to be what you wanted anyway. Good luck!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Ok... I've tried to use an ActiveDocument.Content. I've tried with Selection. I've tried using Missing.Value with several parameters. Nothing works. I always get the same error... The execption starts to be not very... exceptional...
And to close the topic of exception, I never said I don't want to handle an exception. I said I don't know how to correct this one. Right now, my function always raise an exception, so it is useless....
|
|
|
|
|
Like I mentioned in the message you replied to, try Type.Missing instead of Missing.Value . This is what was given in the article I linked for you.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Arggh!!!!
I'm using this simple exemple directly from the article you linked for me. And it still doesn't work!!!
Would there be something else? Like not a simple parameter error, but perhaps a difference if I'm using Office XP or Windows XP?
// C#
internal void SelectionFind()
{
string strFind = "find me";
Word.Find fnd = ThisApplication.Selection.Find;
fnd.ClearFormatting();
fnd.Text = strFind;
object missingValue = Type.Missing;
if (fnd.Execute(ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue, ref missingValue, ref missingValue,
ref missingValue))
{
MessageBox.Show("Text found.");
}
else
{
MessageBox.Show("The text could not be located.");
}
}
|
|
|
|
|
Maybe you just typed your code fragment in wrong, but you didn't actually specify anything to find...or replace, for that matter. You're using ref missingValue in all of Find.Execute 's parameters.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
That was on purpose. As the replace doesn't work, I've tried the very basic, with the simpliest exemple I could find in the library, just find a text. And I still get the exception.
In this exemple, they do not use a parameter, but Word.Find.Text instead
|
|
|
|
|
After many testing, I've discovered that it didn't work because of my Office XP. I have installed Office 2000 instead, and now it works.
Except for one thing. I'd like to replace text which is a TextBox, and not in the body of the document. But Word.Content doesn't include shapes apparently. Anyone with an idea?
|
|
|
|
|
Hi,
I have a toolbar that displays 32 bit icons. When I set a toolbar button to disabled the image appears solid grey. Any tips for getting the icons to display in greyscale?
Thanks,
richjm
|
|
|
|
|
You could always make a second set of icons to add to your image list that are offset by the length of the original images (so you can simply shift the image index by the number of colored images). You'll have to extend the ToolBar class, however, in order to draw the buttons using those images, most likely having to override WndProc since the ToolBar control is just a wrapper to the Windows Common Control's Toolbar class. Messages are sent/posted and notification messages are handled. You'll have to do the same.
To see what's happening behind the scenes with the class, you should get yourself a good decompiler like .NET Reflector[^]. Understanding the Windows Messaging system and the Win32 APIs is necessary.
There are also ways to convert a colored image to gray scale, but you'll still have to extend ToolBar to do so. There's a good one in a great series by Christian Graus here on CP, Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^]. There is a b/w conversion algorithm mentioned in there and in his source code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
with my respect, I would like to ask you about the start menu lokated at the bottom of the Windows operating system desktop?
.........how can I build like it in my program using C#????
answer me on:
sfayoumy@yahoo.com
or
sfayoumy@hotmail.com
and
............................thank you all for this verey good site....
this helps me in my primary project in the university
|
|
|
|
|
Make a form borderless, and get the screen's bounds from the Screen class and apply to your form. Now you have the whole screen to play with.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Isn't it about time Chris makes a "help me do my homework / project / whatever" forum ?
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
Why would you want such a thing? That's going to confuse the hell out of your users.
// Steve McLenithan
Cluelessnes: There are no stupid questions, but there are a lot of inquisitive idiots.
|
|
|
|
|
This over-used application UI went out of style last century (really). There are much better ways to organize your program. The Start menu should not be triffled with and not duplicated, as it might confuse many of your users. It's purpose is to allow quick access to programs and settings, just like Mac's Apple menu, and KDE and GNOME's similar menus. Applications have menus for this purpose, like File, Edit, View, Windows, Help, etc. You should stick with these and read the Official Guidelines for User Interface Developers and Designers[^] for Microsoft Windows. Designing a consistent UI is important for users.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
Is it at all possible to add additional buttons next to the ControlBox on a windows form (kind of like what's in WindowsBlinds)?? Also, I'm trying to completely skin an app, so was wondering if anyone knows of any other ways I can "tweak" a form's border. Also, does anyone know of any prewritten skinning components for windows apps that have been created? Thank you so much.
Agent 86
|
|
|
|
|
With the .NET BCL, no. But there are article detailing this process by P/Invoking code (or that are written in C/C++ and you can P/Invoke and declare everything you need yourself).
For a skinned UI toolkit, check out http://www.fluiduitoolkit.com/[^], which is pretty much run by a group of CodeProject members. For others, just google.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks, I'll check into it!
Agent 86
|
|
|
|
|
Heath Stewart wrote:
For a skinned UI toolkit, check out http://www.fluiduitoolkit.com/[^],
Thanks Heath! It's comin' along, but not done yet.
|
|
|
|
|
Is there a projected release date for the Fluid UI??
Agent 86
|
|
|
|
|
For the first controls, they should be done in the next few months. More advanced controls will take a little while after that - mid-summer or beyond. (Just as I figured, the holidays offset the release date.)
|
|
|
|
|
Hi,
OK, I'm trying to create a background image on an MDI parent form. Here are my problems:
1) If I use a PictureBox, whenever I open a child form, the PictureBox stays in front of the child instead of behind it.
2) I have tried using the Graphics.DrawImage with no avail (e.g. the image doesn't appear).
I would like to have an image that appears on an MDI parent form and stays behind any children forms that are opened. What am I doing wrong?? Thanks in advance.
Agent 86
|
|
|
|
|
Agent 86 wrote:
2) I have tried using the Graphics.DrawImage with no avail (e.g. the image doesn't appear).
Where and how do you do it? You must do it in paint event of parent form in a way like this:
e.Graphics.DrawImage(...);
Mazy
No sig. available now.
|
|
|
|