[英]How do i use 2 buttons to do the same thing
嘿,我对编码有点陌生,我想知道如何使用两个按钮执行同一件事,只有第一个按钮有效,第二个按钮不编码:
private void button1_Click(object sender, EventArgs e)
{
Send(richTextBox1.Text);
}
private void button2_Click(object sender, EventArgs e)
{
Send(textBox1.Text);
}
发送的东西:
void Send(string command)
{
try
{
callbytes = BitConverter.GetBytes(cbuf_address);
if(command == "")
{
MessageBox.Show("You must enter a command before pressing Send!", "Error", MessageBoxButtons.OK);
}
else
{
if(cbuf_addtext_alloc == IntPtr.Zero)
{
cbuf_addtext_alloc = VirtualAllocEx(hProcess, IntPtr.Zero, (IntPtr)cbuf_addtext_wrapper.Length, AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);
commandbytes = System.Text.Encoding.ASCII.GetBytes(command);
commandaddress = VirtualAllocEx(hProcess, IntPtr.Zero, (IntPtr)(commandbytes.Length), AllocationType.Commit | AllocationType.Reserve, MemoryProtection.ExecuteReadWrite);
int bytesWritten = 0;
int bytesWritten2 = commandbytes.Length;
WriteProcessMemory(hProcess, commandaddress, commandbytes, commandbytes.Length, out bytesWritten2);
Array.Copy(BitConverter.GetBytes(commandaddress.ToInt64()), 0, cbuf_addtext_wrapper, 9, 4);
Array.Copy(callbytes, 0, cbuf_addtext_wrapper, 16, 4);
WriteProcessMemory(hProcess, cbuf_addtext_alloc, cbuf_addtext_wrapper, cbuf_addtext_wrapper.Length, out bytesWritten);
IntPtr bytesOut;
CreateRemoteThread(hProcess, IntPtr.Zero, 0, cbuf_addtext_alloc, IntPtr.Zero, 0, out bytesOut);
if(cbuf_addtext_alloc != IntPtr.Zero && commandaddress != IntPtr.Zero)
{
VirtualFreeEx(hProcess, cbuf_addtext_alloc, cbuf_addtext_wrapper.Length, FreeType.Release);
VirtualFreeEx(hProcess, commandaddress, cbuf_addtext_wrapper.Length, FreeType.Release);
}
}
cbuf_addtext_alloc = IntPtr.Zero;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK);
}
}
即时消息真的很东西,所以如果有人可以帮助我解决这个问题,我可能会很感激,请尽快回复!
谢谢。
像这样
private void button1_Click(object sender, EventArgs e)
{
if(!String.IsNullOrEmpty(richTextBox1.Text))
{
Send(richTextBox1.Text);
}
else if(!String.IsNullOrEmpty(textBox1.Text))
{
Send(textBox1.Text);
}
else
{
return;
}
}
您必须确保连接Click
事件,才能触发代码。 当您双击该按钮时,将在设计器代码中为您自动设置(自动生成)。 但是,您也可以在查看事件列表时自动生成方法和订阅。
复制事件功能或手动对其进行编码将不会自动执行。 但是,有了代码,您现在应该可以在设计器中时,从Click事件下拉列表中选择代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.