I have an app with a bunch of controls in it and I want to place a set of cross hairs on top of it. My first attack used a PictureBox
and ran into this problem. The solution that fellow proposes, seems a bit... verbose for what I need.
我有一个带有一堆控件的应用程序,我想在它上面放置一组十字准线。我的第一次攻击使用PictureBox并遇到了这个问题。老乡提出的解决方案似乎有点......我需要的东西很冗长。
Is there a simple way draw on top of my form? Note that I don't even need the drawing to be part of a control as it doesn't need to do anything but just be there.
有没有一种简单的方法在我的表格之上画画?请注意,我甚至不需要绘图作为控件的一部分,因为它不需要做任何事情,只是在那里。
2 个解决方案
#1
Does a PictureBox
with a transparent image have the same problem as a Panel
with BackColor
set to Transparent
? I'm thinking you could have a PictureBox
with the crosshair image in it and move that around, instead of drawing it yourself...
具有透明图像的PictureBox是否与将BackColor设置为Transparent的Panel具有相同的问题?我想你可以有一个带有十字线图像的PictureBox并移动它,而不是自己绘制它...
#2
This eventually worked. I had to play some games though because most of the controls I wanted to draw on were not where it expected them to be.
这最终奏效了。我不得不玩一些游戏,因为我想要绘制的大部分控件并不是它所期望的。
Also, it ran into issues when controls were moved; it failed to redraw and stuff moved with the underlying control. This was fixed by forcing invalidation from the move event for anything that might move.
此外,它在控件移动时遇到了问题;它无法重绘,并且底层控件移动了东西。这是通过强制移动事件的无效来解决的。
#1
Does a PictureBox
with a transparent image have the same problem as a Panel
with BackColor
set to Transparent
? I'm thinking you could have a PictureBox
with the crosshair image in it and move that around, instead of drawing it yourself...
具有透明图像的PictureBox是否与将BackColor设置为Transparent的Panel具有相同的问题?我想你可以有一个带有十字线图像的PictureBox并移动它,而不是自己绘制它...
#2
This eventually worked. I had to play some games though because most of the controls I wanted to draw on were not where it expected them to be.
这最终奏效了。我不得不玩一些游戏,因为我想要绘制的大部分控件并不是它所期望的。
Also, it ran into issues when controls were moved; it failed to redraw and stuff moved with the underlying control. This was fixed by forcing invalidation from the move event for anything that might move.
此外,它在控件移动时遇到了问题;它无法重绘,并且底层控件移动了东西。这是通过强制移动事件的无效来解决的。