VS 2005 and EM_GETLINECOUNT

P

Per W.

Hi, can someone help me with this? I use VB.NET and are trying to the
EM_GETLINECOUNT to count lines in a textbox. But all examples that i have
found has to problemes. as any cant be used in VS2005 and hwnd or handle,
but i cant get the textbox.hwnd og handle to work. I always get error that
hwnd or handle is not a member of system.web.ui.webcontrols.

I want a code that can read how many lines that are in use in a textbox that
are multiline and wrap enabled.

/Per W.
 
G

Gadget

Hi, can someone help me with this? I use VB.NET and are trying to the
EM_GETLINECOUNT to count lines in a textbox. But all examples that i have
found has to problemes. as any cant be used in VS2005 and hwnd or handle,
but i cant get the textbox.hwnd og handle to work. I always get error that
hwnd or handle is not a member of system.web.ui.webcontrols.

I want a code that can read how many lines that are in use in a textbox that
are multiline and wrap enabled.

/Per W.

Option Strict On

Public Class Form1

Private Const EM_GETLINECOUNT As Integer = &HBA
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"_
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,_
ByVal lParam As Integer) As Integer

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Ret As Integer
Ret = SendMessage(TextBox1.Handle.ToInt32, EM_GETLINECOUNT, 0, 0)
TextBox1.Height = (Ret + 1) * TextBox1.Font.Height
End Sub
End Class

Cheers,
Gadget
 
P

Per W.

Gadget said:
Option Strict On

Public Class Form1

Private Const EM_GETLINECOUNT As Integer = &HBA
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"_
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer,_
ByVal lParam As Integer) As Integer

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim Ret As Integer
Ret = SendMessage(TextBox1.Handle.ToInt32, EM_GETLINECOUNT, 0, 0)
TextBox1.Height = (Ret + 1) * TextBox1.Font.Height
End Sub
End Class

Thanx, buit i still get the Error 1 'Handle' is not a member of
'System.Web.UI.WebControls.TextBox'. D:\Dokumenter\Visual Studio
2005\WebSites\WebSite4\Default.aspx.vb 11 27 D:\...\WebSite4\

I have option strict on

/Per W.
 
G

Gadget

Thanx, buit i still get the Error 1 'Handle' is not a member of
'System.Web.UI.WebControls.TextBox'. D:\Dokumenter\Visual Studio
2005\WebSites\WebSite4\Default.aspx.vb 11 27 D:\...\WebSite4\

I have option strict on

/Per W.

Web.UI??? In your whole last thread you didn't mention once that you were
running this on an ASP.NET page...

OK, well in that case forget this whole solution. The idea of auto-height
is dependent on things like browser text sise settings, so you might be
able to cludge something with System.Drawing.Graphics.MeasureString() as
Kevin mentioned, but it will possibly never be quite what you were
expecting.
You might also be able to create a server-side WinForm textbox and query
its height as above, then use that to generate you HTML height, but it's
all a bit of a bodge.

Cheers,
Gadget
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top