无法将窗口放置在显示器的确切位置 [英] Unable to place window at exact location of the monitor

查看:106
本文介绍了无法将窗口放置在显示器的确切位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好论坛,

我开发了一个应用程序,其中将多个文本框控件添加到拆分容器的panel2中.每个文本框的行为就像一个虚拟监视器.我还在运行时向panel2中添加了一个按钮控件,它代表了一个单独的应用程序,该应用程序在连接的多个实际监视器中的任何一个上运行. 我根据连接的显示器的分辨率调整每个文本框的大小.当我根据文本框的尺寸调整按钮的大小时,应用程序的大小在实际的监视器桌面上也会以相同的比例增加.
我的问题是,当我在文本框(虚拟监视器)上移动按钮控件时,应用程序在实际监视器上的位置总是错误的.始终存在一些偏移值,监视器上的应用程序位置与文本框(虚拟监视器)上的按钮位置之间存在偏移值.
如果有人可以指导解决此问题,我将非常感谢.

期待中的感谢
NamitaS

MouseMove_事件处理程序中的源代码发布如下:

Hi forum,

I have developed an application in which several text box controls are added to panel2 of a split container. Each Text box behaves as a virtual monitor. I also add a button control to panel2 in runtime, which represents a separate application running on any one of the several actual monitors connected.
I adjust the size of each textbox according to the resolution of the monitors connected. When I resize the button according to the dimensions of textbox, the size of the application also increase in the same proportion on the actual monitor desktop.
My problem is that Location of the application on actual monitor is always wrong, when I move the button control on the textbox(virtual monitor). There is always some offset value by which application location on the monitors differs from the button position on the textbox(virtual monitor).
I will be highly thankful, if anyone can guide to solve this matter.

Thanking in anticipation
NamitaS

Source code in MouseMove_ event handler is posted below:

protected virtual void MouseMoveEventHandler(object sender, MouseEventArgs e)
 {            
   if (
     !"Core.Windows.Forms.EditableControl"
     .Equals(sender.GetType().ToString()) &&
     _control_moving != null &&
      e.Button == MouseButtons.Left
       )
   {      
        _control_moving.Left = (_control_moving.Left + e.x) -      x_offset_on_client_control;
        _control_moving.Top = (_control_moving.Top + e.y)  - y_offset_on_client_control;

        // movement of the Media Player application
        // g_Obj is the handle to the corresponding Media Player App
        // cubeXres is the horizontal resolution of the actual monitor
        // cubeYres is the vertical resolution of the actual monitor
        // hSize is the width of the textbox(virtual monitor)
        // vSize is the height of the textbox(virtual monitor)
    
       Point mypoint = new Point((_control_moving.Left * (cubeXres / hSize)), (_control_moving.Top * (cubeYres / vSize)));
           
         g_Obj.Location = mypoint;                                     
   }

推荐答案

我绝对不能确定这是解决您问题的方法,但可能是您需要转换 mypoint 在将其分配给 g_Obj.Location 之前先显示其坐标.

请参见 PointToScreen [
I am by no means sure that this is the solution to your problem but it may be the case that you need to convert mypoint to screen coordinates before assigning it to g_Obj.Location.

See PointToScreen[^].


这篇关于无法将窗口放置在显示器的确切位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆