Quote:
Originally Posted by dantz Hi everyone,
I have a textbox which is multiline and wordwrap is true.
I did not set any scrollbar because I want to show it manually (using different buttons)
The textbox will sometimes have double byte strings (chinese characters)
Question:
1) How can I know if I need to show the scrollbar base on the text inside the textbox?
Options:
1) is there a way to manually predict the number of characters that my textbox can show within its size? Getting the length of the string just show the number of characters in the string, not the actual space it can occupy inside the textbox
TIA
dantz |
Hi dantz!
This might be a moot point - not sure I understood your situation correctly. But at least with non-chinese (or other multi-byte) characters this should work....
You can measure the amount of pixels it takes to draw a string by using the MeasureString-method from the System.Drawing.Graphics - object.
- SizeF size = g.MeasureString("string to measure here", this.Font);
You will want to use the Font from your Textbox object. Now you only need to get a hold of Graphics object. One way is to override the OnPaint method like t his:
- protected override void OnPaint(PaintEventArgs e)
-
{
-
// e.Graphics has reference to Graphics used
-
}
Or if that wont do, you can do it once in your form's OnLoad like this:
- System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(this.Handle);
That should get you started solving your problem.
You will have some troubles with "borders" of the text box. I mean that the size of the textbox object is likely to be different from the area where you can actually draw strings...
HTH,
salmenmikko