Click here to Skip to main content
16,020,714 members
Home / Discussions / Windows Forms
   

Windows Forms

 
AnswerRe: How to implement expandable and collapsable properties for usercontrol? Pin
Henry Minute3-Jul-09 0:01
Henry Minute3-Jul-09 0:01 
GeneralRe: How to implement expandable and collapsable properties for usercontrol? Pin
ice.cool 17293-Jul-09 2:01
ice.cool 17293-Jul-09 2:01 
GeneralRe: How to implement expandable and collapsable properties for usercontrol? Pin
Henry Minute3-Jul-09 2:29
Henry Minute3-Jul-09 2:29 
GeneralRe: How to implement expandable and collapsable properties for usercontrol? Pin
ice.cool 17293-Jul-09 2:38
ice.cool 17293-Jul-09 2:38 
GeneralRe: How to implement expandable and collapsable properties for usercontrol? Pin
Henry Minute3-Jul-09 2:53
Henry Minute3-Jul-09 2:53 
QuestionCalling Form from UserControl Layer Pin
Nath1-Jul-09 20:07
Nath1-Jul-09 20:07 
AnswerRe: Calling Form from UserControl Layer Pin
DaveyM691-Jul-09 22:51
professionalDaveyM691-Jul-09 22:51 
QuestionProblem with sizing an image to fit drawn text Pin
Alan Burkhart30-Jun-09 19:21
Alan Burkhart30-Jun-09 19:21 
Using VB.net...

I'm trying to size an in-memory bitmap to fit the text from a textbox. My steps are:
1. Get the height of the font (Font.Height) in the textbox.
2. Get the number of lines in the textbox.
3. Multiply the font height by the line count
4. Size the bitmap to textbox.width and font.height multiplied by the line count for the height
5. Create a rectangle sized to the bitmap
6. Draw the text in the bitmap within the rectangle
7. Set a picturebox's image property to the bitmap (picturebox sizemode set to autosize)

This works fine IF the textbox doesn't have a scrollbar. If it's a long text file, the image is only about half as tall as it needs to be.

Here's my code (RichTextBox named "rtf"):
  Private Sub tb_Draw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_Draw.Click

Dim fh As Integer 'font height
Dim cw As Integer 'rtf.width
Dim ch As Integer 'rtf.text height
Dim lineCount As Integer 'rtf.lines.length
Dim bmp As Bitmap
Dim g As Graphics

  fh = rtf.Font.Height
  cw = rtf.Width
  lineCount = rtf.Lines.Length
  ch = lineCount * fh
  rect = New Rectangle(0, 0, cw, ch)
  bmp = New Bitmap(cw, ch, Imaging.PixelFormat.Format32bppArgb)

  g = Graphics.FromImage(bmp)
  g.FillRectangle(Brushes.White, rect)
  g.DrawString(rtf.Text, rtf.Font, Brushes.Black, rect)

  picbox.Image = bmp

End Sub


The textbox only uses a single font.

What am I doing wrong?
QuestiongetModuleFileNameEx Pin
johnl012930-Jun-09 5:38
johnl012930-Jun-09 5:38 
AnswerRe: getModuleFileNameEx Pin
DaveyM6930-Jun-09 6:14
professionalDaveyM6930-Jun-09 6:14 
GeneralRe: getModuleFileNameEx Pin
johnl012930-Jun-09 8:11
johnl012930-Jun-09 8:11 
GeneralRe: getModuleFileNameEx Pin
Luc Pattyn30-Jun-09 8:28
sitebuilderLuc Pattyn30-Jun-09 8:28 
GeneralRe: getModuleFileNameEx Pin
johnl012930-Jun-09 8:40
johnl012930-Jun-09 8:40 
GeneralRe: getModuleFileNameEx Pin
DaveyM6930-Jun-09 10:22
professionalDaveyM6930-Jun-09 10:22 
GeneralRe: getModuleFileNameEx Pin
johnl012930-Jun-09 11:04
johnl012930-Jun-09 11:04 
GeneralRe: getModuleFileNameEx Pin
DaveyM6930-Jun-09 11:17
professionalDaveyM6930-Jun-09 11:17 
GeneralRe: getModuleFileNameEx Pin
DaveyM6930-Jun-09 10:29
professionalDaveyM6930-Jun-09 10:29 
Questionhow to create a new printer and add to the list Pin
genius_palli30-Jun-09 2:10
genius_palli30-Jun-09 2:10 
AnswerRe: how to create a new printer and add to the list Pin
Dave Kreskowiak30-Jun-09 3:40
mveDave Kreskowiak30-Jun-09 3:40 
AnswerRe: how to create a new printer and add to the list Pin
Sk9330-Jun-09 5:04
Sk9330-Jun-09 5:04 
AnswerRe: how to create a new printer and add to the list Pin
genius_palli30-Jun-09 19:21
genius_palli30-Jun-09 19:21 
AnswerRe: how to create a new printer and add to the list Pin
genius_palli30-Jun-09 21:34
genius_palli30-Jun-09 21:34 
GeneralRe: how to create a new printer and add to the list Pin
genius_palli10-Jul-09 2:54
genius_palli10-Jul-09 2:54 
GeneralRe: how to create a new printer and add to the list Pin
Sk9327-Jul-09 23:46
Sk9327-Jul-09 23:46 
Questionhow to use the expandable and collapsable property Pin
honey.rpk29-Jun-09 0:36
honey.rpk29-Jun-09 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.