如何在UP和DOWN键进行编码(How to code at the UP and DOWN key)

   IT问题网   2020-06-26 00:00:00

问 题

当用户按"向上"和"向下"键时,我想上下移动图片框键

解决方案

你的问题出在你的时候如果可以从表单中获取焦点,那么就可以控制表单。

此外,在其他解决方案中,我没有看到事件处理程序添加到事件实例的位置。



所以,这是真正的解决方案:

  int  increment =  //   ...  
picturebox mypictirebox = // ...

myform.keypreview = ; // 这很重要!
myform.keydown + =(sender,eventargs)= gt; {
clientheight = myform.clientsize.height;
if (eventargs.keycode = keys.upamp;amp; mypictirebox.top gt; 0 // not keydata!
mypictirebox.top-=增量;
else if (eventargs.keycode = keys.downamp;amp; mypictirebox.top lt; height-mypictirebox.height) // not form的高度
mypictirebox.top + =增量;
} // myform.keydown




此处的修正:1)事件在预览中被提升,因此有焦点的孩子不会抓住它,2)纠正使用密钥代码,3)更正客户端高度。 />


对于c#v.2的用户,添加带有"+ ="的处理程序应该有点不同。而不是



 myform.keydown + =(sender,eventargs)= gt;  { / *   ... * / } 








 myform.keydown + =  delegate  object  sender,system.keyeventargs eventargs){ / *   ... * / } 




祝你好运,

-sa

你没有提到任何按钮,所以我把它写在form1_keydownevent



对不起,如果误解了你的问题



  private   void  form1_keydown( object  sender,keyeventargs e)
{
我f (e.keydata == keys.up)
{
if (picbox1.top gt; 0
picbox1.top = picbox1.top- 10 ;
}
if (e.keydata == keys.down)
{
if (picbox1.top lt; =( this .height-picbox1。高度))
picbox1.top = picbox1.top + 10 ;
}
}

 point p = mypicturebox.location; 
p.y = p.y ++; // p.y--;向下移动
location = p.x;
mypicturebox.location = p;

标签:何在以及进行编码



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何计算excel 2003中的时间平均值(how to calculate time averge in excel 2003)

problem hii to all. if any body knows how to calculateave ...

控制相关问题(Control related issue)

problem respected sir, i have a page in which i m gettin ...

在运行时动态绘制div(draw div dynamically at runtime)

problem hiii all, i have a page which i draw all its attr ...

转换数据库值(Convert a databse value)

problem i have a table one field is price and ...

如何使单元格的内容可见为false(How do i make the content of a cell visible false)

problem how do i make the content of a cell visible false ...

qtwebkit并连接cpp和javascript(qtwebkit and connect cpp and javascript)

problem hi to all i am using qwebkit i have a cpp object ...

response.flush&到Response.End(problem with response.flush & response.end)

problem hello everybody, i have used response.flush() wi ...

ShellExecute()不执行(ShellExecute() Not Executing)

problem i''m running a batch file from c++ code.when i ru ...

Radion Button使用Javascript隐藏/可见(Radion Button Hide/Visible Using Javascript)

problem i want hide/visible radio button using javascript ...

如何在此xml文件中插入/删除节点(how to insert/delete a node to this xml file)

problem hi all :) i search in webto find a code that ins ...

XML + DTD,不会出现在浏览器中(XML + DTD, won't show up in browser)

problem my code looks right, validates, but when i open i ...

什么是样品反射(What is Reflection with sample)

problem hi everybody, could u plz tell me reflection d ...

在封闭网络上获取设备的IP地址(optaining IP addresses of devices on a closed network)

problem i have a situation where i have multiple devices ...

如何限制用户在asp.net中通过javascript在TextBox中仅输入alphabates(How to Restrict user to enter only alphabates in TextBox by javascript in asp.net)

problem how to restrict user to enter onlyalphabates in t ...

如何在远程服务器上使用jquery调用webservice?(how to call webservice using jquery on remote server)

problem i have created one html page,in that using jquery ...

pchealth文件夹占用了大量空间(pchealth folder consuming a lot of space)

problem in my server there are plenty of cab ...

如何在vb.net网站中添加c#名称空间?(How can add c# namespace in a vb.net Website)

problem hello codian, i want to create two namespaces in ...

仅搜索已更改的目录(Search Only Changed Directory(s))

problem i''m running this batch that works pr ...

在VB2010服务中打开Word文档(Opening Word document in a VB2010 service)

problem hi there, i try to open a word docum ...

VB.Net窗口服务安装64位(VB.Net window service install 64 bit)

problem i''m writing a windows service in vs 2010 and usi ...