473,473 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Setting the text area of a textbox

I am creating a subclassed text box. I want to have a button inside the
tetbox. That was the easy part. The part I can't figure out, is how you
set the area for the text? If you type a string it will go underneath
the button instead of stopping at the button and doing it's normal wrap
functionality where it pushes the text off the one side of the
textbox... How do you tell it to only use a certain area for text?

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
9 3652
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I am creating a subclassed text box. I want to have a button inside the
tetbox. That was the easy part. The part I can't figure out, is how you set
the area for the text? If you type a string it will go underneath the
button instead of stopping at the button and doing it's normal wrap
functionality where it pushes the text off the one side of the textbox...
How do you tell it to only use a certain area for text?


You can use p/invoke to set a horizontal indentation. A VB6 sample can be
found here:

SetMargin
<URL:http://dotnet.mvps.org/vb/samples/controls/SetMargin.zip>

If you don't want a border around the whole control, you can create a
usercontrol that contains a textbox and the button control.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I am creating a subclassed text box. I want to have a button inside
the tetbox. That was the easy part. The part I can't figure out, is
how you set the area for the text? If you type a string it will go
underneath the button instead of stopping at the button and doing it's
normal wrap functionality where it pushes the text off the one side of
the textbox... How do you tell it to only use a certain area for text?

You can use p/invoke to set a horizontal indentation. A VB6 sample can
be found here:

SetMargin
<URL:http://dotnet.mvps.org/vb/samples/controls/SetMargin.zip>

If you don't want a border around the whole control, you can create a
usercontrol that contains a textbox and the button control.


I'll have to see if I can get that to work in VB.Net ... I do want a
border around the whole thing. I actually want the button to be part of
the text box, not outside of it...

Here is what I have:

Public Class PromptTextBox
Inherits System.Windows.Forms.TextBox
Dim Prompt As New PromptButton

Public Class PromptButton
Inherits System.Windows.Forms.Button

Public Sub New()
Dim sz As System.Drawing.Size
Me.Text = "..."
Me.TextAlign = ContentAlignment.BottomCenter
sz.Height = 17
sz.Width = 18
Me.Size() = sz
Me.FlatStyle = FlatStyle.System
Me.BackColor =
System.Drawing.Color.FromKnownColor(KnownColor.Con trol)
Me.Cursor = System.Windows.Forms.Cursors.Arrow
End Sub
End Class

Public Sub New()
Me.Controls.Add(Prompt)
End Sub

Private Sub PromptTextBox_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
Dim pt As System.Drawing.Point
pt.X = Me.Width - (Prompt.Size.Width + 3)
pt.Y = 0
Prompt.Location = pt
End Sub

End Class

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #3
Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I am creating a subclassed text box. I want to have a button inside
the tetbox. That was the easy part. The part I can't figure out, is
how you set the area for the text? If you type a string it will go
underneath the button instead of stopping at the button and doing it's
normal wrap functionality where it pushes the text off the one side of
the textbox... How do you tell it to only use a certain area for text?

You can use p/invoke to set a horizontal indentation. A VB6 sample can
be found here:

SetMargin
<URL:http://dotnet.mvps.org/vb/samples/controls/SetMargin.zip>

If you don't want a border around the whole control, you can create a
usercontrol that contains a textbox and the button control.


I'll have to see if I can get that to work in VB.Net ... I do want a
border around the whole thing. I actually want the button to be part of
the text box, not outside of it...

Here is what I have:

Public Class PromptTextBox
Inherits System.Windows.Forms.TextBox
Dim Prompt As New PromptButton

Public Class PromptButton
Inherits System.Windows.Forms.Button

Public Sub New()
Dim sz As System.Drawing.Size
Me.Text = "..."
Me.TextAlign = ContentAlignment.BottomCenter
sz.Height = 17
sz.Width = 18
Me.Size() = sz
Me.FlatStyle = FlatStyle.System
Me.BackColor =
System.Drawing.Color.FromKnownColor(KnownColor.Con trol)
Me.Cursor = System.Windows.Forms.Cursors.Arrow
End Sub
End Class

Public Sub New()
Me.Controls.Add(Prompt)
End Sub

Private Sub PromptTextBox_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
Dim pt As System.Drawing.Point
pt.X = Me.Width - (Prompt.Size.Width + 3)
pt.Y = 0
Prompt.Location = pt
End Sub

End Class

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #4
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal wMsg
As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module

Is it something i am doing or am I just barking up the wrong tree with
this method? No matter what I do, it doesn't make a difference. I even
just tried a static value for a left margin just to get it to work, and
it's not... Tried it with Int32, Int64, Long and then the Handle.ToInt64
... Nothin...
Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I am creating a subclassed text box. I want to have a button inside
the tetbox. That was the easy part. The part I can't figure out, is
how you set the area for the text? If you type a string it will go
underneath the button instead of stopping at the button and doing it's
normal wrap functionality where it pushes the text off the one side of
the textbox... How do you tell it to only use a certain area for text?

You can use p/invoke to set a horizontal indentation. A VB6 sample can
be found here:

SetMargin
<URL:http://dotnet.mvps.org/vb/samples/controls/SetMargin.zip>

If you don't want a border around the whole control, you can create a
usercontrol that contains a textbox and the button control.

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #5
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal wMsg
As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module

Is it something i am doing or am I just barking up the wrong tree with
this method? No matter what I do, it doesn't make a difference. I even
just tried a static value for a left margin just to get it to work, and
it's not... Tried it with Int32, Int64, Long and then the Handle.ToInt64
... Nothin...
Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I am creating a subclassed text box. I want to have a button inside
the tetbox. That was the easy part. The part I can't figure out, is
how you set the area for the text? If you type a string it will go
underneath the button instead of stopping at the button and doing it's
normal wrap functionality where it pushes the text off the one side of
the textbox... How do you tell it to only use a certain area for text?

You can use p/invoke to set a horizontal indentation. A VB6 sample can
be found here:

SetMargin
<URL:http://dotnet.mvps.org/vb/samples/controls/SetMargin.zip>

If you don't want a border around the whole control, you can create a
usercontrol that contains a textbox and the button control.

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #6
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal wMsg As
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module


Replace the 'As Long' in the declarations with 'As Int32'. 'lRet' should be
32-bit too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal wMsg As
Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module


Replace the 'As Long' in the declarations with 'As Int32'. 'lRet' should be
32-bit too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8
Thank you! That was it.. Works good now.

Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module

Replace the 'As Long' in the declarations with 'As Int32'. 'lRet'
should be 32-bit too.

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #9
Thank you! That was it.. Works good now.

Herfried K. Wagner [MVP] wrote:
"Aaron Smith" <th**********@smithcentral.net> schrieb:
I can't seem to be able to get this to work with .Net...

Dim RightMargin As Long
RightMargin = Prompt.Size.Width + 3
Win32.SendMessage(Me.Handle, EM_SETMARGINS, EC_RIGHTMARGIN, RightMargin)

Public Module Win32
Private Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hwnd As System.IntPtr, ByVal wMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long

Public Function SendMessage(ByVal hwnd As System.IntPtr, ByVal
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lRet = SendMessageLong(hwnd, wMsg, wParam, lParam)
Return lRet
End Function
End Module

Replace the 'As Long' in the declarations with 'As Int32'. 'lRet'
should be 32-bit too.

--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Dannyboyo | last post by:
I have what I hope is a simple request. I can't really code in javascript, but I am pretty good at cusomizing it with slight modifications. I code in ASP and HTML. I am trying to capture customer...
5
by: dixie | last post by:
I want to be able to set the font size and font type for text in a text box on a report using VBA. I wan't to be able to control it from a setting in a table. The problem is that I don't know the...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
1
by: Dennis C. Drumm | last post by:
How can I determine if a string will fit in the display area of a text box? I don't want to use a char count because the width of each char can vary. I suspect I need to convert the string to a...
4
by: Gill Smith | last post by:
After setting the web control text box enable property to FALSE makes the control to loose the data between round trip. I am making sure that the property - EnableViewState = TRUE. Same code...
4
by: David Kyle | last post by:
Hello there, I'm having some problems setting the TextBox.Text Property in my code and having it returned to the client in the source when the TextBox.TextMode="Password". I know this is...
1
by: Aaron Smith | last post by:
I am creating a subclassed text box. I want to have a button inside the tetbox. That was the easy part. The part I can't figure out, is how you set the area for the text? If you type a string it...
0
by: karen987 | last post by:
Could someone please tell me what code to add here? I have a weblog, with daily news which readers can add comments to, which are stored in a database. The form to add the comments is on an ASP page,...
1
by: DeanB | last post by:
Please excuse my ignorance here as I have not used WPF for long, but what is the statement that tells what the "local:" identifier is that allows a window event to call a function in a .cs file? ...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.