wince/mobile下支持触屏点击的文本框实现
- using System;
-
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
-
- namespace ClickableTextboxSample
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- #region 子类化
-
- [DllImport("coredll.dll")]
- private static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
- [DllImport("coredll.dll")]
- private extern static int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, uint msg, uint wParam, int lParam);
- [DllImport("coredll.dll")]
- public static extern IntPtr SetWindowLong(IntPtr hwnd, int nIndex, IntPtr dwNewLong);
- public const int GWL_WNDPROC = (-4);
- public IntPtr OldProc = IntPtr.Zero;
- public delegate int WndProcHandler(IntPtr hwnd, uint msg, uint wParam, int lParam);
- WndProcHandler myproc = null;
-
- #endregion
-
- //窗体创建好后执行
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- myproc = new WndProcHandler(MyWndProc);
- OldProc = SetWindowLong(textBox1.Handle, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(myproc));
- }
-
- public const int WM_LBUTTONUP = 0x202;
- int MyWndProc(IntPtr hwnd, uint msg, uint wParam, int lParam)
- {
- if (msg == WM_LBUTTONUP)
- {
- CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
- KeyboardWindow key = new KeyboardWindow();
- key.Input = textBox1.Text;
- if (key.ShowDialog() == DialogResult.OK)
- {
- textBox1.Text = key.Input;
- }
- return 1;//1表示处理过了,不需要系统继续处理了。
- }
- return CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
- }
-
- //本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wuyazhe/archive/2010/07/05/5714741.aspx
- }
- }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。