Ist es möglich das meine Rechtschreibung "Popup" im Vordergrund definiert wird?
Nach dem Kontrollieren landet er leider im Hintergrund und macht das anklicken
unmöglich =(.
Code:
private string CheckSpellingDialog(string text)
{
if (string.IsNullOrEmpty(text))
return "";
Type wordType = Type.GetTypeFromProgID("Word.Application");
Type documentType;
object wordApp = null;
object documents = null;
object document = null;
object optional = Missing.Value;
object visible = false;
if (wordType != null)
{
wordApp = Activator.CreateInstance(wordType);
documents = wordType.InvokeMember("Documents", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, wordApp, new object[0]);
document = documents.GetType().InvokeMember("Add", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, documents, new object[4] {
optional,
optional,
optional,
visible
});
documentType = document.GetType();
}
else
{
throw new ApplicationException("Microsoft Word ist nicht installiert! Die Rechtschreibprüfung benötigt Microsoft Word.");
}
wordType.InvokeMember("Visible", BindingFlags.SetProperty | BindingFlags.OptionalParamBinding, null, wordApp, new object[1] { false });
object words = documentType.InvokeMember("Words", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, document, new object[0]);
object first = words.GetType().InvokeMember("First", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, words, new object[0]);
first.GetType().InvokeMember("InsertBefore", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, first, new object[1] { text });
documentType.InvokeMember("CheckSpelling", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, document, new object[0]);
object characters = documentType.InvokeMember("Characters", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, document, new object[0]);
object count = characters.GetType().InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, characters, new object[0]);
object firstChar = 0;
object lastChar = (int)count - 1;
object range = documentType.InvokeMember("Range", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, document, new object[2] { firstChar, lastChar });
object correctedString = range.GetType().InvokeMember("Text", BindingFlags.GetProperty | BindingFlags.OptionalParamBinding, null, range, new object[0]);
wordType.InvokeMember("Quit", BindingFlags.InvokeMethod | BindingFlags.OptionalParamBinding, null, wordApp, new object[1] { false });
return correctedString as string;
}
Aufruf mit:
CheckSpellingDialog("Loliüppü")
Schau Dir das mal an... ev. hilfts
Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...
Wenn dein Tool sich nicht auf eine Form bezieht, worauf dann?
Also ein einfaches Form welches Deine Methode aufruft... alles Paletti.
Also muss es an Deinem Form liegen...
Ist Dein Form allenfalls TopMost=true ?
Gruss
Programmierhans
Früher war ich unentschlossen, heute bin ich mir da nicht mehr so sicher...
Wenn ich es richtig verstanden habe hast ein Hauptfenster bzw. PopupMenu das nach dem Aufruf der Methode den Fokus verliert, das PopupMenu verschwindet dabei wahrscheinlich.
Das passiert weil das neu erstellte Word Hauptfenster erstmal den Fokus bekommt.
Du machst es danach zwar wieder unsichtbar aber dann ist es natürlich auch schon zu spät.
Ich seh da erstmal keinen direkten Lösungsansatz, entweder du baust deine Oberfläche um oder du erzeugst die Word Instanz einfach früher so das dass Problem mit dem Fokus Wechsel dadurch umgangen wird.