Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Word Interop library has many mapped classes to the corresponding objects in MS Word such as Paragraph, Table, Chart, Selection.

But I don't find out the mapped class to TextBox, could you let me know its name and its location in Word Interop library?

The term 'class' above in fact is called 'interface' which is not like Interface in .NET, I don't know why it is but those interfaces work as if they are really classes in .NET (especially, we can create their instances?).

Thank you!
Posted
Updated 22-Dec-11 19:43pm
v2
Comments
Sergey Alexandrovich Kryukov 23-Dec-11 23:05pm    
What do you mean by "not like interface in .NET"? A type is either an interface or not? Can you be clear about it? Or you don't know what are they? This is too easy to find out...
--SA

1 solution

First, many types of the Microsoft.Office.Interop.Word are technically the interfaces but are named not according to the naming conventions of interfaces. I just referenced and opened, out of curiosity, Microsoft.Office.Interop.Word v.12.0.0.0 and can confirm it. However, you should not be confused. Interfaces are interfaces, no matter how someone named them. Probably this is due to the style of original Word API, something existing by historical reasons.

Let's sort it out. Do you understand that, when it comes to objects, interface types can serve only as the compile-time types of objects, as interfaces cannot be instantiated; and run-time types of these objects represented by the interface references could be only classes or structures? Every time you work with any really existing interface reference during run time, you really work with an object which run time type is a class or a structure implementing the interface. There is nothing mysterious or unclear about it; this is the universal principle of using interfaces, as well as abstract classes, a very basic OOP principle.

[EDIT]

The right pattern is this:

C#
interface IMyInterface {
    void MyMethod(/* ... */);
    //...
}

class MyClass : IMyInterface {
    void IMyInterface.MyMethod(/* ... */) {}
    //...
}

structure MyStructure : IMyInterface {
    void IMyInterface.MyMethod(/* ... */) {}
    //...
}

//...

IMyInterface objectOne = new MyClass(/* ... */); // don't commit a crime of having typecast here
IMyInterface objectTo = new MyStructure(/* ... */); // don't commit a crime of having typecast here
objectOne.MyMethod(/* ... */); //do you get it finally?

//don't commit another crime here:
MyClass instance = (MyClass)objectOne;
instance.//.... crime is actually here: if you want using interfaces, use all implementing types
// via interface references only; this is not a strict rule, but not following it is a bad style


[END EDIT]

As to the TextBox — no, there is no such type in the whole assembly, and it's hard to understand why would anyone would need such thing in Word interoperation.

However, there is the interface Microsoft.Office.Interop.Word.TextInput. Maybe, this is what you are looking for. Please see:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.textinput%28v=office.14%29.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.textinput%28v=Office.11%29.aspx[^].

—SA
 
Share this answer
 
v3
Comments
supernorb 24-Dec-11 15:22pm    
Thank you, I just think that we can't do something like someinterface = new someinterface()
in .NET, the way above is how an object of someclass is created. If in .NET, it should be someinterface = (someinterface) new someclass() in which someclass has to implement someinterface otherwise an exception will be thrown.
As you can see, that kind of 'interface' is too strange to me and I didn't care much about that and treated it as normal class in .NET.
About the TextInput, I'll check it soon, I don't think there is any object in MS Word that doesn't have a mapped class in Word Interop library. Thank you for your help.
Sergey Alexandrovich Kryukov 25-Dec-11 14:06pm    
OK, I think you didn't get using interfaces. Please see my update, after [EDIT].
--SA
Sergey Alexandrovich Kryukov 25-Dec-11 13:58pm    
You are welcome.

As to "new someinterface()", what are you talking about? This is only possible is new someinterface is a class or structure, never an interface class. Interfaces cannot be instantiated, only via implementing classes or structures. In next sentence, you show a type cast which is never should be used. You are missing something important...

--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900