private void button1_Click(object sender, EventArgs e)
{
IntPtr ip = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Rectangle)));
SendMessage(richTextBox1.Handle, 0xb2, 0, ip);//EM_GETRECT=0xb2
Console.WriteLine(Marshal.PtrToStructure(ip, typeof(Rectangle)));
Marshal.FreeHGlobal(ip);
} private void button2_Click(object sender, EventArgs e)
{
Rectangle rec=new Rectangle();
GCHandle gch = GCHandle.Alloc(rec);
SendMessage(richTextBox1.Handle, 0xb2, 0, (IntPtr)gch);//EM_GETRECT=0xb2
Console.WriteLine(Marshal.PtrToStructure((IntPtr)gch, typeof(Rectangle)));
gch.Free();
}
用button1的方法没有问题,但是button2的方法执行后,程序就停止响应了
而且还有一个奇怪的现象:如果先单击button1,再单击button2,又正常了
{
IntPtr ip = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Rectangle)));
SendMessage(richTextBox1.Handle, 0xb2, 0, ip);//EM_GETRECT=0xb2
Console.WriteLine(Marshal.PtrToStructure(ip, typeof(Rectangle)));
Marshal.FreeHGlobal(ip);
} private void button2_Click(object sender, EventArgs e)
{
Rectangle rec=new Rectangle();
GCHandle gch = GCHandle.Alloc(rec);
SendMessage(richTextBox1.Handle, 0xb2, 0, (IntPtr)gch);//EM_GETRECT=0xb2
Console.WriteLine(Marshal.PtrToStructure((IntPtr)gch, typeof(Rectangle)));
gch.Free();
}
用button1的方法没有问题,但是button2的方法执行后,程序就停止响应了
而且还有一个奇怪的现象:如果先单击button1,再单击button2,又正常了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货