Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DHTML instead of RichTextBox 1

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I'm hoping to use Microsoft's DHTML editor box in VB instead of a RichTextBox as part of an application where users can compose HTML emails.

As a first step I'm trying to replicate the functionality of a RTF box in so far as a rudimentary toolbar goes. I can use:
Code:
N$ = Editor.ExecCommand(DECMD_GETFONTNAME)
to get the name of the font where the cursor is, and similarly the font size.

Is there a way to find out other font attributes such as Bold, Italic and Underline? I know that DECMD_BOLD sets the text to bold but how do I find out whether the text where the cursor is is bold or not (or part bold, part normal)?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Use the QueryStatus() method passing the cmdID (e.g. DECMD_BOLD). Results returned include:
Return value

An enum value of type DHTMLEDITCMDF indicates the return value for the query. Possible values for this enum are:

DECMDF_DISABLED (1) Command is not valid for the selection. For example, DECMD_GETFONTNAME will return this value if you attempt to get the font name of an ActiveX control. In general, this status indicates that if the command being tested is visible in the user interface, the interface element (button or command) should be disabled.

DECMDF_ENABLED (3) Command is available for use with the selection. For example, DECMD_INSERTROW will return this value when the selection is within a table. DECMD_BOLD will return this value when the selection contains non-bold text.

DECMDF_LATCHED (7) Command is available for use with the selection and the command should be displayed latched (for example, a toolbar button should be depressed or a menu item should be checked). DECMD_BOLD will return this value when the selection contains bold text.

DECMDF_NINCHED (11) Command is available for use with the selection, but the selection contains mixed data. For example, DECMD_BOLD will return this value when the selection contains both bold and non-bold text.
 
Example from the TriEdit SDK Docs:
Code:
Private Sub DHTMLEdit1_DisplayChanged()
   retVal = DHTMLEdit1.QueryStatus(DECMD_BOLD)
   Select Case retVal
      Case DECMDF_ENABLED, DECMD_LATCHED
         btnBold.Enabled = True
      Case DECMDF_DISABLED
         btnBold.Enabled = False
   End Select
End Sub
 
Thanks for that.

I don't know if you've actually used the DHTML editor or not, but if you have do you know if there's a better way of obtaining the font size than using DECMD_GETFONTSIZE? It seems to return a value from 1 to 7 corresponding to the 'default' font sizes on html pages, whereas if a Style is used to set the font size to 11pt how can I get that size?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
No, the DHTMLEdit control is really meant for editing HTML that it creates itself. Sort of like editing an HTML email body. You can't even have a <style> unless you manipulate the underlying HTML text manually.

DHTMLEdit only uses <font> tags for such things, though it will respect a lot of basic CSS embedded in the document or a related resource (lke a .css file) when it comes to displaying the rendered page.

It is more of a tool for editing and displaying rich-markup text, like the RichTextBox. It doesn't make the best general-purpose HTML editior.
 
Aargh there had to be a catch! I added a style for the <p> tags to use Arial 10pt, so like you say it does implement styles if you include them. I'm not sure how many people actually change the font size when they're composing emails - not many I suspect - so I might be able to get away with the default font sizes.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
You could also give them the ability to set "block formats" to "paragraphs" (anything ending with a hard return basically). For example the <p> is "Normal" and you also have "Heading 1" and "Heading 2" etc. as well as stuff like "Formatted" and "Address."

These can be set up in CSS to use non-default fonts, sizes, colors, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top