分不是白拿的
呵呵我们再WinForm下用Combobox的时候
可能需要向EditControl里面Paste一些东西
可是当字符串里面含有回车的时候就被截掉了
所以我想截获他的WM_PASTE消息
把回车替换成其他字符
可是在WndProc里面根本得不到WM_PASTE消息哪位兄弟知道
可否告知此问题如何解决
祝大家周末愉快PS:在TextBox里面是可以截获的
呵呵我们再WinForm下用Combobox的时候
可能需要向EditControl里面Paste一些东西
可是当字符串里面含有回车的时候就被截掉了
所以我想截获他的WM_PASTE消息
把回车替换成其他字符
可是在WndProc里面根本得不到WM_PASTE消息哪位兄弟知道
可否告知此问题如何解决
祝大家周末愉快PS:在TextBox里面是可以截获的
解决方案 »
- ds.Dispose(); return ds;请问返回的是空的还是??
- C#中用指针操作字符串的问题
- 使用最少的代码,完成窗体关闭任务(注意,要有关闭提示)
- 我现在有一个List<Group>的对象集合,需要把这个集合递归绑定到treeview上,求各位大虾帮帮忙!急……
- 如何从窗口的HWND转换为Form
- 请问我要下载一个指定文件该代码该怎么写啊?
- 如何不去处理异常使程序继续运行?
- Net Framework\MDAC2.7\SetupTest.msi的自动安装问题
- 网上有免费的C#开发工具吗?帮忙介绍一个
- 为什末.NET BATE2资料中的例子都不好用呢?
- 电脑中毒了,怎么办?
- 请大家帮我看看这样写对吗?
手上没有查MsgID的书。
觉得既然Testbox可以实现,那Combox也行的。
Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If e.Control = True And e.KeyCode = Keys.V And b = False Then
b = True
SendKeys.Send("^(Z)")
Dim i As IDataObject = Clipboard.GetDataObject()
Dim str As String
str = CType(i.GetData("System.String"), String)
Clipboard.SetDataObject(str.Replace(vbCrLf, "@"))
SendKeys.SendWait("^(V)")
b = False
Clipboard.SetDataObject(str)
End If
End Sub
b=false;在combobox的keydown事件里:
if(e.Control = True && e.KeyCode = Keys.V && b = False)
{
b=true;
SendKeys.Send("^(Z)");//程序输入ctrl+z撤销刚才ctrl+v操作
//呵呵,bt的想法
IDataObject i= Clipboard.GetDataObject();
string str;
str=(string)i.GetData("System.String");//从剪贴板取string
Clipboard.SetDataObject(str.Replace(vbCrLf, "@"))//更改剪贴板内容
SendKeys.SendWait("^(V)");//程序输出ctrl +v,粘贴
//必须用sendwait,否则死循环
b=false;
Clipboard.SetDataObject(str);//恢复剪贴板内容
}
在SendWait哪里 循环半天 然后出错
不过我执行了一下 好象不行啊
在SendWait哪里 循环半天 然后出错
那个b是要放在事件处理函数外边的否则每次重新初始化b(无法判断是否为程序输入还是用户输入),就产生死循环了
那右键的菜单怎么办?
换成自己的?
如果是控制键盘操作直接用ProcessDialogKey就可以了
不用SendKey
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Windows.Forms;public class ExactComboBox : ComboBox
{
private IContainer components; public ExactComboBox()
{
this.components = new Container();
} protected override void Dispose(bool disposing)
{
if (disposing == true)
{
if (!(this.components == null))
{
this.components.Dispose();
}
}
base.Dispose(disposing);
} [DllImport("USER32.DLL")]
private static extern bool GetComboBoxInfo(IntPtr comboBoxHandle, ref ComboBoxInfo pComboBoxInfo);
[StructLayout(LayoutKind.Sequential)]
private struct ComboBoxInfo
{
public int Size;
public Rectangle RectItem;
public Rectangle RectButton;
public int ButtonState;
public IntPtr ComboBoxHandle;
public IntPtr EditBoxHandle;
public IntPtr ListBoxHandle;
}
private class EditBoxWindow : NativeWindow
{ public EditBoxWindow(ComboBox parentComboBox)
{
parentComboBox.HandleDestroyed += new EventHandler(this.OnHandleDestroyed);
} private void OnHandleDestroyed(object sender, EventArgs e)
{
this.ReleaseHandle();
} [PermissionSet(SecurityAction.Demand)]
protected override void WndProc(ref Message m)
{
const int WM_PASTE = 770;
if (m.Msg == WM_PASTE)
{
MessageBox.Show("WM_PASTE");//在这里处理
}
base.WndProc(ref m);
}
} protected override void OnHandleCreated(EventArgs e)
{
ComboBoxInfo tComboBoxInfo = new ComboBoxInfo();
tComboBoxInfo.Size = Marshal.SizeOf(tComboBoxInfo);
if (GetComboBoxInfo(this.Handle, ref tComboBoxInfo) == false)
{
return;
}
if (tComboBoxInfo.EditBoxHandle.Equals(IntPtr.Zero))
{
return;
}
EditBoxWindow hEditBoxWindow = new EditBoxWindow(this);
hEditBoxWindow.AssignHandle(tComboBoxInfo.EditBoxHandle);
}
}
http://www.atit.co.jp/bbs/phpBB/viewtopic.php?topic=28307&forum=7&4