如何在父母的子控件上显示绘图? [英] How to show drawing on a child control of a parent?

查看:78
本文介绍了如何在父母的子控件上显示绘图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#上开发一个绘图锁控件,如Android绘图锁。这是我的控件 http://imgim.com/image/screenshotimage2.png

9个橙色方块是灰色标签的子项。我在正方形鼠标移动的中心点之间绘制线条。它绘制在灰色标签上,因为它比在正方形上绘图更容易。问题是线条没有出现在控件的顶部。这就像 http://imgim.com/image/screenshotimage3.png
如何使用父控件的图形在所有子控件上绘制线条?

I want to develop a drawing lock control on C# like Android drawing lock. Here is my Control http://imgim.com/image/screenshotimage2.png
The 9 orange squares is child of the gray label. I am drawing lines between center point of the squares mouse move on. It is drawing on gray label because it is easier than drawing on squares. The problem is lines doesnt appear on top of the controls. It is something like that http://imgim.com/image/screenshotimage3.png
How can I draw lines on top of all child controls using Graphics of parent control?

推荐答案

你不能。如果您使用某些控件的 Graphics ,则绘图将在此控件上呈现,而不是其他任何位置。从你的问题的其余部分的表述,这不是你想要的。你只想在一些对象之上绘制一些东西。



首先,引入几个不同的控件一起工作是一个常见的设计错误。对于没有经验的工程师来说,这只是一种不合理的复杂功能,这看起来就像是简化了。不要这样做;不要组合任何控件。只需要一个控件在一个公共表面上表示所有图形元素。当然,如果你遇到相反的问题,掩盖某些图形元素的问题,你可以随时这样做。



我甚至不知道还有什么讨论;一切看起来都很清楚。



如果你想要更难的方式,你还可以考虑以下可能性:拥有一个透明背景的自定义控件,将它放在你的另一个上面控制并在其表面绘制。但不要告诉我,我推荐它;这只是另一种可能性,几乎不是最好的。你决定。



请看相关主题的过去答案:

mdi子窗体之间的绘制线 [ ^ ](在查询者的某种类似尝试中),

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ],

在面板上捕获绘图 [ ^ ],

如何加速我的vb.net应用程序? [ ^ ],

用C#.net鼠标滚轮缩放图像 [ ^ ],

如何避免DatagridView C#中的红十字[ [ ^ ]。



-SA
You cannot. If you draw on Graphics of some control, the drawing will be rendered on this control and nowhere else. From the formulation of the rest of your problem, this is not what you want. You just want to draw something on top of some objects.

First of all, it's a common design mistake to introduce several different controls working together. This is nothing which an unreasonable complication which only looks like simplification to inexperienced engineers. Don't do it; don't combine any controls. Just have one control representing all your graphics elements on one common surface. Of course, if you face the opposite problem, the problem to mask some part of graphical elements, you can always do so.

I don't even know what else to discuss; everything looks clear.

If you want some harder way, you can also consider the following possibility: have a custom control with transparent background, position it on top of your other controls and draw on its surface. But don't tell me I recommended it; it's just another possibility, hardly the best. You decide.

Please see my past answers on related topics:
Drawing Lines between mdi child forms[^] (on somewhat similar attempt by the inquirer),
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^],
capture the drawing on a panel[^],
How to speed up my vb.net application?[^],
Zoom image in C# .net mouse wheel[^],
How to avoid Red Cross in DatagridView C#[^].

—SA


这篇关于如何在父母的子控件上显示绘图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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