我是靠谱客的博主 友好蚂蚁,最近开发中收集的这篇文章主要介绍winform模拟qq聊天界面的小功能textbox1输入自动跳到textbox2,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication28
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            const int WM_CHAR = 0x0102;
            const int WM_USER = 0x0400;
            const int WM_USER1 = WM_USER + 1;
            switch (m.Msg)
            {
                case WM_USER1:
                    textBox1.Focus();
                    IntPtr hwnd = textBox1.Handle;
                    WinAPI.SendMessage(hwnd, WM_CHAR, (int)m.WParam, 0);
                    break;
            }
            base.WndProc(ref m);
        }
    }

    class MyTextBox : TextBox
    {
        protected override void WndProc(ref Message m)
        {
            const int WM_CHAR = 0x0102;
            const int WM_PAINT = 0x000F;
            const int WM_USER = 0x0400;
            const int WM_KEYDOWN= 0x0100;
            const int WM_IME_CHAR = 0x0286;
            const int WM_IME_COMPOSITION = 0x010F;
            switch (m.Msg)
            {
                case WM_CHAR:
                    {
                        int key = (int)m.WParam;
                        IntPtr hwnd = WinAPI.FindWindow("WindowsForms10.Window.8.app.0.2bf8098_r13_ad1", null);
                        WinAPI.SendMessage(hwnd, WM_USER + 1, (int)m.WParam, 0);
                    }
                    return;
                //case WM_IME_CHAR:
                //    MessageBox.Show("a");
                //    break;
                //case WM_KEYDOWN:
                //    {
                //        IntPtr hwnd = WinAPI.FindWindow("WindowsForms10.Window.8.app.0.2bf8098_r13_ad1", null);
                //        int code = (int)m.WParam;
                //        WinAPI.SendMessage(hwnd, WM_USER + 1, code, 0);
                //    }
                //    return;
                case WM_IME_COMPOSITION:
                    {
                        IntPtr hwnd = WinAPI.FindWindow("WindowsForms10.Window.8.app.0.2bf8098_r13_ad1", null);
                        int code = (int)m.WParam;
                        WinAPI.SendMessage(hwnd, WM_USER + 1, code, 0);
                    }
                    return;
                //case WM_PAINT:
                //    //MessageBox.Show("aa");
                //    break;
            }
            base.WndProc(ref m);
        }
    }
}

 

记录下,备忘~

就是要把上面那个textbox的WndProc重写下,然后消息拦截下就ok了。。

最后

以上就是友好蚂蚁为你收集整理的winform模拟qq聊天界面的小功能textbox1输入自动跳到textbox2的全部内容,希望文章能够帮你解决winform模拟qq聊天界面的小功能textbox1输入自动跳到textbox2所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部