Windows Develop Bookmark and Share   
 index > Windows Forms General > Changing number of characters per tab indent.
 

Changing number of characters per tab indent.

According to the description forTextFormatFlags.ExpandTabs, here, the 'default' number of characters per tab is eight. Since it explicitly states 'default', I'm led to presume that this value is changeable, which is something I need/want to do for my program.

I understand that StringFormat.ExpandTabs(or somesuch function name) may do what I need/want, but StringFormat seems to be used by Graphics.DrawString, whereas my code is using TextRenderer.DrawText to draw the text(the reason being is that MeasureText/DrawText is accurate given the TextFormatFlags arguments I've specified, whereas I have not been able to get such accuracy of text length using Graphic's MeasureString/DrawString). As such, StringFormat's function does not seem to suit my needs.

In short, if anyone can offer assistance to setting the number of characters in a tab when the text is being drawn by TextRenderer.DrawText, I would be greatly appreciative.

Thanks.

nerd_boy  Tuesday, November 04, 2008 4:28 PM
The native API function, DrawTextEx() supports it through the DRAWTEXTPARAMS.iTabLength member. But that capability is not exposed by TextRenderer. P/Invoking it is, technically, possible.
nobugz  Tuesday, November 04, 2008 9:59 PM

Unfortunately the TextRenderer does not supportcustom tab lengths. If you want to display the tabs you can use the TextFormatFlags.ExpandTabs when calling TextRenderer.DrawText. If you want to use a different length for tabs, you will need toformat the string (replacingtabs withappropriate spacing)before passing it to TextRender.DrawText.

John

John Kellar  Tuesday, November 04, 2008 7:37 PM
The native API function, DrawTextEx() supports it through the DRAWTEXTPARAMS.iTabLength member. But that capability is not exposed by TextRenderer. P/Invoking it is, technically, possible.
nobugz  Tuesday, November 04, 2008 9:59 PM
Hey! Sounds just like what I needed. Thanks!
nerd_boy  Tuesday, November 04, 2008 10:50 PM

You can use google to search for other answers

Custom Search

More Threads

• Tablet pc ink in DataGridView
• Loading Image (Visual C# 2005) and Export Image question
• TreeView & ImageList Speed Issue
• Writing Help for .Net windows forms application...
• Access Javascript fns from WebBrowser C#
• Functional keys are not woking in datagrid
• Drag Control problem
• Script on interval basis
• Advantages and disadvantages of using images for controls instead of GDI+ features
• Taskbar item flashing