我试图在屏幕上获得控件的绝对位置.我正在使用两台显示器,结果并不是那么好......
我正在做的是打开另一个表单来捕获图像,然后将此图像传递给主表单并关闭捕获表单.然后,我希望主窗体出现在捕获图片的相同位置.要获得我想要做的事情的要点,请在Windows上打开Snipping Tool并捕获一个剪辑.然后窗口将出现在拍摄图像的位置.
这是我用来执行此操作的当前代码:
Location = new Point(Cursor.Position.X - CaptureBox.Width - CapturePanel.Location.X - CaptureBox.Location.X - 8, Cursor.Position.Y - CaptureBox.Height - CapturePanel.Location.Y - CaptureBox.Location.Y - 30);
Run Code Online (Sandbox Code Playgroud)
CapturePanel包含存储图片的CaptureBox控件.我也从X位置获取8,从te Y位置获取30来补偿表单的边框和标题栏,但唯一的问题是某些计算机将使用不同的窗口样式,这些数字将会改变.
如果有一种方法可以用来获取窗口的边框和标题宽度/高度,那就太棒了.
编辑
解决方法是:
Location = new Point(
Cursor.Position.X -
CaptureBox.Width -
CapturePanel.Location.X -
CaptureBox.Location.X -
SystemInformation.HorizontalResizeBorderThickness,
Cursor.Position.Y -
CaptureBox.Height -
CapturePanel.Location.Y -
CaptureBox.Location.Y -
SystemInformation.CaptionHeight -
SystemInformation.VerticalResizeBorderThickness
);
Run Code Online (Sandbox Code Playgroud)
在King King的帮助下向我指出了SystemInformation.
在过去一个小时左右的时间里,我一直在尝试让我的 Maven 项目包含其依赖项中的源文件,但由于某种原因,事实并非如此。我已按照以下链接提供的步骤进行操作,但是当我编译并运行插件时,出现 ClassNotFoundException:
https://github.com/mkremins/fanciful
我已确保将上面链接中的依赖项和存储库包含到我的 pom.xml 文件中,但是当我编译时,它们不会添加到我的 .jar 文件中。
我对使用 Maven 还很陌生,到目前为止还很喜欢它,尽管解决这样的问题可能会很痛苦。
我正在通过执行以下操作来构建该项目:
右键单击项目 -> 运行方式 -> Maven 构建 -> 目标:全新安装
经过一番探索,我发现事情并不像我想象的那么容易。我将以下内容添加到我的 pom.xml 构建部分:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>mkremins:fanciful</include>
<include>org.json:json</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
唯一的问题是我还需要手动包含我想要使用的主库的依赖项 - mkremins:fanciful; 是否有标志或选项可以自动从我需要的一个文件复制依赖项,而不是还包括<include>org.json:json</include>?