全屏随飞机地点置显示图片的小程序,keyDown事件方向键不响应

By admin in 4858.com on 2019年4月9日

想方设法:将显示屏截图作为程序背景图,在上述弹出提醒窗口,选用分明后举行定时图片随飞机地点置显得。(帮忙ESC键退出)

设法:将荧屏截图作为程序背景图,在以上弹出提醒窗口,选取明确后举办定时图片随飞机地点置显得。(支持ESC键退出)

C#全屏随飞机地方置显得图片的小程序,

想尽:将显示屏截图作为程序背景图,在上述弹出提示窗口,选拔明确后开始展览定时图片随飞机地点置展现。(辅助ESC键退出)

  • 全屏随飞机地点置显示图片的小程序,keyDown事件方向键不响应。内需加上的控件:Timer

4858.com 1

1 Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty)); 2
3 public Form1() 4 { 5 this.FormBorderStyle =
System.Windows.Forms.FormBorderStyle.None; 6 this.BackgroundImage =
GetNoCursor(); 7 InitializeComponent(); 8 } 9 10 private void
Form1_Load(object sender, EventArgs e) 11 { 12 timer1.Interval = 500;
13 if (MessageBox.Show(“消息”, “标题”, MessageBoxButtons.YesNo) ==
DialogResult.Yes) 14 { 15 timer1.Enabled = true; 16 } 17 else 18 { 19
this.Close(); 20 } 21 } 22 23 private void Form1_KeyDown(object sender,
Key伊芙ntArgs e) 贰四 { 二5 if (e.KeyData == Keys.Escape) 二陆 { 二7timer一.Enabled = false; 2八 MessageBox.Show(“音信”, “标题”,
MessageBoxButtons.OK); 2九 this.Close(); 30 } 3一 } 3二 3三 private Bitmap
GetNoCursor() 3四 { 3伍 Bitmap Source = new Bitmap(bounds.Width,
bounds.Height); //遵照显示器尺寸创立Bitmap对象 36 Graphics g =
Graphics.FromImage(Source); 三柒 g.CopyFromScreen(0, 0, 0, 0,
Source.Size); //获取没有鼠标的显示屏截图 38 g.Dispose(); //释放能源 3九return Source; 40 } 四一 4二 private void timer一_Tick(object sender,
伊夫ntArgs e) 四三 { 4四 Image img =
Resource一.Image一;//获取用于呈现的财富文件 肆5 if (img != null) 四六 { 47Graphics g = this.CreateGraphics(); 4八 Random rd = new Random(); 4九 int
picXPoint = rd.Next(0, bounds.Right – img.Width); 50 int picYPoint =
rd.Next(0, bounds.Height – img.Height); 5一 Point ulCorner = new
Point(picXPoint, picYPoint); 5二 g.DrawImageUnscaled(img, ulCorner); 五3 }
5肆 else 5伍 { 5六 timer1.Enabled = false; 伍7MessageBox.Show(“未有图片,感激使用”); 58 this.Close(); 5九 } 60 }

 

想法:将荧屏截图作为程序背景图,在以上弹出提醒窗口,采用分明后进行定时图片随机地方展现。(…

在做3D漫游时,分别使用WASD和方向键,控制视角前后左右,KeyDown事件记录漫游开端标记,可是WASD能够Debug进入,方向键却始终不可能进去,很奇怪的是,进不了KeyDown,却能响应KeyUp事件

  • 需求加上的控件:Timer
  • 急需丰硕的控件:Timer

然而Ctrl+方向键和Alt+方向键却得以进来,经过一番寻觅。很多稿子中剖析恐怕是因为趋势键默许是用来拍卖控件核心移动,由控件本人处理,一时半刻尚未权威说法,但此难点是按下述套路化解的。

4858.com 2

4858.com 3

 

 

 

Control::ProcessDialogKey这些函数能够告知程序案件时由控件本人处理也许写的顺序来处理

  • 亟需修改的Form一属性为下图稻草黄区域:
  • 亟待修改的Form一属性为下图莲红区域:

This
method is called during message preprocessing to handle dialog
characters, such as TAB, RETURN, ESC, and arrow keys.This
method is called only if
the IsInputKey.aspx) method
indicates that the control is not processing the key.The ProcessDialogKey simply sends the character to the
parent’s ProcessDialogKey method, or
returns false if the control has no parent.The Form.aspx) class
overrides this method to perform actual processing of dialog keys.This
method is only called when the control is hosted in a Windows Forms
application or as an ActiveX
control.

 4858.com 4

 4858.com 5

 

4858.com 6

4858.com 7

大约意思正是TAB, RETU奥迪Q5N, ESC, and arrow
keys那多少个键是控件自个儿处理,不过重写以后能够自定义处理。(作者只是通晓她的意味,但做不到标准翻译,表明能力有限)。

4858.com 8

4858.com 9

 

 

 

不留余地方案正是,遭逢方向键,return
false,那么控件就不会活动处理,交给KeyDown响应了。

  • 能源文件的拉长:添加->新建项->资源文件
  • 财富文件的增进:添加->新建项->能源文件

4858.com ,C#代码

4858.com 10

4858.com 11

protected override bool ProcessDialogKey(Keys keyData)
{

     if (keyData == Keys.Up || keyData == Keys.Down || keyData == Keys.Left || keyData == Keys.Right)
     {
          return false;
      }
      else
      {
           return base.ProcessDialogKey(keyData);
      }
}
  • ESC键退出程序:
  • ESC键退出程序:

C++/CLI代码

在Form1.Designer.cs中增加

在Form1.Designer.cs中增加

virtual  bool ProcessDialogKey( System::Windows::Forms::Keys keyData)override
{
    if (keyData == System::Windows::Forms::Keys::Up || keyData == System::Windows::Forms::Keys::Down || keyData == System::Windows::Forms::Keys::Left || keyData == System::Windows::Forms::Keys::Right)
    {
          return false;
    }
    else
    {
          return __super::ProcessDialogKey(keyData);
    }
}

this.KeyDown += Form1_KeyDown;

this.KeyDown += Form1_KeyDown;

 

  • 代码如下:

     1         Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
     2 
     3         public Form1()
     4         {
     5             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
     6             this.BackgroundImage = GetNoCursor();
     7             InitializeComponent();
     8         }
     9 
    10         private void Form1_Load(object sender, EventArgs e)
    11         {
    12             timer1.Interval = 500;
    13             if (MessageBox.Show("消息", "标题", MessageBoxButtons.YesNo) == DialogResult.Yes)
    14             {
    15                 timer1.Enabled = true;
    16             }
    17             else
    18             {
    19                 this.Close();
    20             }
    21         }
    22 
    23         private void Form1_KeyDown(object sender, KeyEventArgs e)
    24         {
    25             if (e.KeyData == Keys.Escape)
    26             {
    27                 timer1.Enabled = false;
    28                 MessageBox.Show("消息", "标题", MessageBoxButtons.OK);
    29                 this.Close();
    30             }
    31         }
    32 
    33         private Bitmap GetNoCursor()
    34         {
    35             Bitmap Source = new Bitmap(bounds.Width, bounds.Height);    //根据屏幕大小创建Bitmap对象
    36             Graphics g = Graphics.FromImage(Source);
    37             g.CopyFromScreen(0, 0, 0, 0, Source.Size);  //获取没有鼠标的屏幕截图
    38             g.Dispose();    //释放资源
    39             return Source;
    40         }
    41 
    42         private void timer1_Tick(object sender, EventArgs e)
    43         {
    44             Image img = Resource1.Image1;//获取用于显示的资源文件
    45             if (img != null)
    46             {
    47                 Graphics g = this.CreateGraphics();
    48                 Random rd = new Random();
    49                 int picXPoint = rd.Next(0, bounds.Right - img.Width);
    50                 int picYPoint = rd.Next(0, bounds.Height - img.Height);
    51                 Point ulCorner = new Point(picXPoint, picYPoint);
    52                 g.DrawImageUnscaled(img, ulCorner);
    53             }
    54             else
    55             {
    56                 timer1.Enabled = false;
    57                 MessageBox.Show("没有图片,感谢使用");
    58                 this.Close();
    59             }
    60         }
    

     

  • 代码如下:

     1         Rectangle bounds = Screen.GetBounds(Screen.GetBounds(Point.Empty));
     2 
     3         public Form1()
     4         {
     5             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
     6             this.BackgroundImage = GetNoCursor();
     7             InitializeComponent();
     8         }
     9 
    10         private void Form1_Load(object sender, EventArgs e)
    11         {
    12             timer1.Interval = 500;
    13             if (MessageBox.Show("消息", "标题", MessageBoxButtons.YesNo) == DialogResult.Yes)
    14             {
    15                 timer1.Enabled = true;
    16             }
    17             else
    18             {
    19                 this.Close();
    20             }
    21         }
    22 
    23         private void Form1_KeyDown(object sender, KeyEventArgs e)
    24         {
    25             if (e.KeyData == Keys.Escape)
    26             {
    27                 timer1.Enabled = false;
    28                 MessageBox.Show("消息", "标题", MessageBoxButtons.OK);
    29                 this.Close();
    30             }
    31         }
    32 
    33         private Bitmap GetNoCursor()
    34         {
    35             Bitmap Source = new Bitmap(bounds.Width, bounds.Height);    //根据屏幕大小创建Bitmap对象
    36             Graphics g = Graphics.FromImage(Source);
    37             g.CopyFromScreen(0, 0, 0, 0, Source.Size);  //获取没有鼠标的屏幕截图
    38             g.Dispose();    //释放资源
    39             return Source;
    40         }
    41 
    42         private void timer1_Tick(object sender, EventArgs e)
    43         {
    44             Image img = Resource1.Image1;//获取用于显示的资源文件
    45             if (img != null)
    46             {
    47                 Graphics g = this.CreateGraphics();
    48                 Random rd = new Random();
    49                 int picXPoint = rd.Next(0, bounds.Right - img.Width);
    50                 int picYPoint = rd.Next(0, bounds.Height - img.Height);
    51                 Point ulCorner = new Point(picXPoint, picYPoint);
    52                 g.DrawImageUnscaled(img, ulCorner);
    53             }
    54             else
    55             {
    56                 timer1.Enabled = false;
    57                 MessageBox.Show("没有图片,感谢使用");
    58                 this.Close();
    59             }
    60         }
    

     

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图
Copyright @ 2010-2019 美高梅手机版4858 版权所有