clearz Posted July 22, 2003 Posted July 22, 2003 Hi TextBox t = new TextBox(); t.Text = "Hello"; Graphics g = t.CreateGraphics(); Ok this gets the graphics object of a textbox. What I would like to do is create an image object from that textbox am I on the right track using a Graphics object or is there some other way. Any help would be appricated. Thanks John Quote
ballisticnylon Posted July 22, 2003 Posted July 22, 2003 The code you posted allows you to draw on the textbox, not create an image from that textbox. Here's something more along the lines of what you want (I think): 'I'm assuming TextBox1 has been created design time Dim bmp as new Bitmap(Textbox1.Width, TextBox1.Height) Dim G as Graphics = Graphics.FromImage(bmp) Dim txtRect as New Rectangle(0, 0, TextBox1.Width, TextBox1.Height) G.FillRectangle(TextBox1.BackColor, txtRect) G.DrawRectangle(Pens.Black, txtrect) G.DrawString(TextBox1.Text, Brushes.Black, 2, 2) G.Dispose() This doesn't take a snapshot of the control, but it tries to emulate it. Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
clearz Posted July 22, 2003 Author Posted July 22, 2003 That is fine if you are using a single line textbox but the textboxs I am using are multiline. Quote
ballisticnylon Posted July 22, 2003 Posted July 22, 2003 This should work for a multi-line textbox. 'I'm assuming TextBox1 has been created design time Dim bmp As New Bitmap(Textbox1.Width, TextBox1.Height) Dim G As Graphics = Graphics.FromImage(bmp) Dim txtRectF As New RectangleF(0, 0, TextBox1.Width, TextBox1.Height) G.FillRectangle(TextBox1.BackColor, txtRect) G.DrawRectangle(Pens.Black, 0, 0, TextBox1.Width, TextBox1.Height) G.DrawString(TextBox1.Text, TextBox1.Font, Brushes.Black, txtRectF) G.Dispose() Quote "It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve." - Edgar Allan Poe, 1841 I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker. - Helen Keller
Leaders dynamic_sysop Posted July 22, 2003 Leaders Posted July 22, 2003 you could do something like this : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.BackColor = TextBox1.BackColor PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize Application.DoEvents() PictureBox1.CreateGraphics.DrawString(TextBox1.Text, TextBox1.Font, New SolidBrush(TextBox1.ForeColor), 0, 0) End Sub Quote
clearz Posted July 26, 2003 Author Posted July 26, 2003 Great Thanks ballisticnylon that is exactly what im looking for Quote
Hamburger1984 Posted July 27, 2003 Posted July 27, 2003 Hey clearz! If you also want to draw a single/3D Border, take a look at the System.Windows.Forms.ControlPaint-Class! It provides methods to draw Borders and many other things that look exactly as the windows-Controls... Andreas Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.