شمارش تعداد خطوط textBox
کد:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const uint EM_GETLINECOUNT = 0xBA;
IntPtr wp = IntPtr.Zero;
IntPtr lp = IntPtr.Zero;
private void button1_Click(object sender, EventArgs e)
{
IntPtr lines = SendMessage(textBox1.Handle, EM_GETLINECOUNT, wp, lp);
MessageBox.Show(lines.ToInt32().ToString());
}
}
}