Textbox Properties

Making a textbox resizeable

Page 1 of 1

3 Replies - 14374 Views - Last Post: 11 February 2009 - 01:24 PM Rate Topic: -----

#1 PWLevy  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 11-February 09

Textbox Properties

Posted 11 February 2009 - 01:16 PM

I have set up a Textbox Resize event, but when I execute the form, it doesn't allow me to change the textbox size. I'm not sure what code to show; this is a VB.Net book exercise that I'm running in VB 2005.

Here is the property code for the textbox and the form
'TextBox1
   '
		Me.TextBox1.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
					Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
		Me.TextBox1.Location = New System.Drawing.Point(48, 43)
		Me.TextBox1.Name = "TextBox1"
		Me.TextBox1.Size = New System.Drawing.Size(65, 20)
		Me.TextBox1.TabIndex = 2
		'
		'fclsEventsDemo
		'
		Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
		Me.ClientSize = New System.Drawing.Size(302, 259)
		Me.Controls.Add(Me.TextBox1)
		Me.Controls.Add(Me.lblMessage)
		Me.Controls.Add(Me.txtEvents)
		Me.Name = "fclsEventsDemo"
		Me.Text = "Form1"
		Me.ResumeLayout(False)
		Me.PerformLayout()
  



Here is the event code
 Private Sub TextBox1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Resize

		TextBox1.Text = TextBox1.Width
	End Sub	



I have tried setting the Border to something beside 'Fixed'. All resize references I have found refer to Forms or tables. Is there a property that allows users to resize a textbox?
(

Is This A Good Question/Topic? 0
  • +

Replies To: Textbox Properties

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 773
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: Textbox Properties

Posted 11 February 2009 - 01:23 PM

Make sure first that the MultiLine property for the TextBox is set to True. This will allow the TextBox to be resized (else, it will remain the same size). Then, to change the width and height of the control you will use the following code:

TextBox1.Width = 100
TextBox1.Height = 100



Of course, the numbers presented here are just an exmple and you can replace them with the values you need.

This is the way to modify the control size at runtime if you trigger another event, like Button_Click.

This post has been edited by Core: 11 February 2009 - 01:26 PM

Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1633
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Textbox Properties

Posted 11 February 2009 - 01:23 PM

Have a look at this on allowing a user to resize a control at run-time
Was This Post Helpful? 1
  • +
  • -

#4 WinBase  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 93
  • Joined: 27-January 09

Re: Textbox Properties

Posted 11 February 2009 - 01:24 PM

i plagiarised a bit of code that i stumbled across that allows u to resize any control, it mite be what u want and i certainly found it useful


'---------------------------------------------------------------------
' ResizeableControl.vb
'
' A class to enable resizing of any control by the user.
' this is based on code found at the following link:
'
' http://www.codeproject.com/KB/dotnet/Resize_Control_at_Runtime.aspx
'
' and used with the navigation bar at:
' http://www.codeproject.com/KB/office/Outlook_Navigation_Pane.aspx
'
' Usage As Follows At Form Level:
'
'   Dim rc As ResizeableControl
'   rc = New ResizeableControl(Panel1)

'---------------------------------------------------------------------

Public Class ResizeableControl

Private WithEvents mControl As Control
Private mMouseDown As Boolean = False
Private mEdge As Edge = Edge.None
Private mWidth As Integer = 4
Private mOutlineDrawn As Boolean = False

Private Enum Edge
   None
   Right
   Left
   Top
   Bottom
   TopLeft
End Enum

Public Sub New(ByVal control As Control)
	mControl = control
End Sub

Private Sub mControl_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mControl.MouseDown
   If e.Button = Windows.Forms.MouseButtons.Left Then _
	  mMouseDown = True
End Sub

Private Sub mControl_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mControl.MouseUp
   mMouseDown = False
End Sub

Private Sub mControl_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles mControl.MouseMove
   Dim c As Control = CType(sender, Control)
   Dim g As Graphics = c.CreateGraphics

   Select Case mEdge
	  Case Edge.TopLeft
		 g.FillRectangle(Brushes.Fuchsia, 0, 0, mWidth * 4, mWidth * 4)
		 mOutlineDrawn = True

	  Case Edge.Left
		 g.FillRectangle(Brushes.Fuchsia, 0, 0, mWidth, c.Height)
		 mOutlineDrawn = True

	  Case Edge.Right
		 'g.FillRectangle(Brushes.Fuchsia, c.Width - mWidth, 0, c.Width, c.Height)
		 g.FillRectangle(Brushes.Transparent, c.Width - mWidth, 0, c.Width, c.Height)
		 mOutlineDrawn = True

	  Case Edge.Top
		 g.FillRectangle(Brushes.Fuchsia, 0, 0, c.Width, mWidth)
		 mOutlineDrawn = True

	  Case Edge.Bottom
		 g.FillRectangle(Brushes.Fuchsia, 0, c.Height - mWidth, c.Width, mWidth)
		 mOutlineDrawn = True

	  Case Edge.None
		 If mOutlineDrawn Then
			c.Refresh()
			mOutlineDrawn = False
		 End If
   End Select

'*****
'* this resizes the control when its being dragged
'*
   If mMouseDown And mEdge <> Edge.None Then
	  c.SuspendLayout()
	  Select Case mEdge
		 Case Edge.TopLeft
			c.SetBounds(c.Left + e.X, c.Top + e.Y, c.Width, c.Height)

		 Case Edge.Left
			c.SetBounds(c.Left + e.X, c.Top, c.Width - e.X, c.Height)

		 Case Edge.Right
			c.SetBounds(c.Left, c.Top, c.Width - (c.Width - e.X), c.Height)

		 Case Edge.Top
			c.SetBounds(c.Left, c.Top + e.Y, c.Width, c.Height - e.Y)

		 Case Edge.Bottom
			c.SetBounds(c.Left, c.Top, c.Width, c.Height - (c.Height - e.Y))

	  End Select
	  c.ResumeLayout()

	 Else

	  Select Case True
		 Case e.X <= (mWidth * 4) And e.Y <= (mWidth * 4) ' top left corner
			c.Cursor = Cursors.SizeAll
			mEdge = Edge.TopLeft

		 Case e.X <= mWidth							   ' left edge
			c.Cursor = Cursors.VSplit
			mEdge = Edge.Left

		 Case e.X > c.Width - (mWidth + 1)				' right edge
			c.Cursor = Cursors.VSplit
			mEdge = Edge.Right

		 Case e.Y <= mWidth							   ' top edge
			c.Cursor = Cursors.HSplit
			mEdge = Edge.Top

		 Case e.Y > c.Height - (mWidth + 1)			   ' bottom edge
			c.Cursor = Cursors.HSplit
			mEdge = Edge.Bottom

		Case Else										 ' no edge
			c.Cursor = Cursors.Default
			mEdge = Edge.None
		End Select
   End If
End Sub

Private Sub mControl_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles mControl.MouseLeave
   Dim c As Control = CType(sender, Control)
   mEdge = Edge.None
   c.Refresh()
   c.Cursor = Cursors.Default ' added
End Sub

End Class



GL

Bob
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1