I am a little simple when it comes to programming and I find examples help me no end. I have created a VS 2005 Visual Basic Net 2.0 demo that creates a basic word processor using Text Dynamic and have added a custom menu to duplicate most button actions using the wpaProcess commands like
Code
Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click Me.WpdllInt1.CurrMemo.wpaProcess("Copy", "") End Sub
I have also added an Examples menu with some basic code that I found useful, mostly from the manual, API and all over. Code example to add a formatted header below. Only about 4 examples at present but I plan to add more as I go. If anyone has some Visual Basic code they wish to share I would be very happy to add it. Download at http://www.accessgp.com/Downloads.html
GRS
Code
Private Sub BlockToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BlockToolStripMenuItem.Click
'Dim memo As IWPMemo = WpdllInt1.Memo
Dim header As IWPDataBlock = Me.WpdllInt1.CurrMemo.BlockAdd(DataBlockKind.wpIsHeader, DataBlockRange.wpraOnAllPages, "", 0)
header.Clear()
header.WorkOnText = True
'IWPTextCursor cursor = memo.TextCursor;
'Me.WpdllInt1.Memo.CurrAttr.IncludeStyles(WPWRT.ITALIC)
'create a text style called "myStyle", this is not used for the actual header, confusing isn't it
Me.WpdllInt1.Memo.SelectStyle("myStyle") 'Selects a certain style. The style can be then manipulated through interface CurrStyle.
Me.WpdllInt1.Memo.CurrStyleAttr.SetFontface("Times New Roman") 'This interface is used to change the character attributes defined by the current style. Also see CurrStyle
Me.WpdllInt1.Memo.CurrStyleAttr.SetFontSize("12")
Me.WpdllInt1.Memo.CurrStyleAttr.SetStyles(7)
' Declaration()
'procedure SetStyles(Value: WrtStyle);
' Description()
'This method sets all character styles ate once. Also see IncludeStyles and ExcludeStyles and ToogleStyle.
' Parameters()
'Styles 1 : Bold text. (C# wrapper defines enum element WPSTY.BOLD)
'2 : Italic text. (C# wrapper defines enum element WPSTY.ITALIC)
'4 : Underlined text. (C# wrapper defines enum element WPSTY.UNDERLINE)
'8 : Strikeout text. (C# wrapper defines enum element WPSTY.STRIKEOUT)
'16 : Text in super-script (C# wrapper defines enum element WPSTY.SUPERSCRIPT)
'32 : Text in sub-script (C# wrapper defines enum element WPSTY.SUBSCRIPT)
'64 : Hidden text, (C# wrapper: WPYST.HIDDEN)
'128 : Uppercase text. (C# wrapper: WPYST.UPPERCASE)
'256 : reserved.
'512 : Lowercase text. (C# wrapper: WPYST.LOWERCASE)
'1024 : Text which should be excluded from spellcheck (WPSTY.NOPROOF)
'2048 : Double strikeout (WPSTY.DBLSTRIKEOUT)
'4096 : reserved.
'8192: Protected text(WPSTY.PROTECTED)
Me.WpdllInt1.Memo.CurrPar.StyleName = "myStyle"
'clear the writing attributes otherwise the style is not used
Me.WpdllInt1.Memo.CurrAttr.Clear()
Me.WpdllInt1.TextCursor.InputText(" Page ")
Me.WpdllInt1.TextCursor.InputTabstop(False, Me.WpdllInt1.Memo.PageSize.PageWidth - Me.WpdllInt1.Memo.PageSize.LeftMargin - Me.WpdllInt1.Memo.PageSize.RightMargin, 1, 1)
' Declaration()
'procedure InputTabstop(ClearAllTabs: WordBool; Value: Integer; Kind: Integer; FillMode: Integer);
' Description()
'Creates a tabstop.
' Parameters()
'ClearAllTabs True to clear tab list for current paragraph.
'Value Value of this tabstop (in twips=1/1440 inch)
'Kind The tabstop kind:
'0: Left(TAB)
'1: Right(TAB)
'2: Center(TAB)
'3 : Decimal tab
'Fill The fill mode used for this tabstop
'0: No(Filling)
'1: Dots ......
'2: Dots in middle of line
'3: Hyphens ------
'4: Underline(______)
'5: Thick Hyphen ---------
'6: Equal Signs =======
'7: Arrow()
Me.WpdllInt1.TextCursor.InputObject(TextObjTypes.wpobjTextObject, "PAGE", "", 0)
Me.WpdllInt1.TextCursor.InputText(" of ")
Me.WpdllInt1.TextCursor.InputObject(TextObjTypes.wpobjTextObject, "NUMPAGES", "", 0)
' Declaration()
'function InputObject(ObjType: TxTextObjTypes; const Name: WideString; const Command: WideString; Mode: Integer): Integer;
' Description()
'Creates different object kinds at cursor position.
' Parameters()
'ObjType 0=text object, 1=merge field, 2=hyperlink, 3=bookmark, 7=text object, 8=page reference, 11=footnote, 12=image or text box and 13 for horizontal lines.
'Name The name of the new object.
'Command The command parameter of the new object.
'Mode If bit 1 is set an object pair will be created. The cursor will be placed within.
'Bit 2 activates the "editable" mode used for form fields.
' Returns()
'0 if not successful. Otherwise the interface CurrObj can be used to change object properties.
'Declaration()
'function InputFieldObject(const Name: WideString; const Command: WideString; const DefaultText: WideString): Integer;
' Description()
'Creates a text object. This are single objects which are updated by the the event OnTextObjectGetText. The following fieldnames are predefined:
'"PAGE" : The current page number
'"NEXTPAGE": Page number of the next page, empty strig if last page
'"PRIORPAGE": Previous pagenumber, empty string if first page
'"NUMPAGES": Count of pages
'"DATE": The curent date
'"TIME": The current time
'"SECTIONPAGES": Count of pages in this section
'When you need to create HTML text you can use a field with the name HTMLCODE and any custom code as "command" to insert custom HTML tags into the HTML text.
Me.WpdllInt1.Reformat()
End Sub
Alles anzeigen