创建线实例 [英] Create instances of lines

查看:27
本文介绍了创建线实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我想知道是否可以在不使用Paint Event Handler的情况下创建行实例吗?

我的问题是我有一个用户控件,但是当我使用paint事件时,它没有显示在我的用户控件中.帮我.谢谢! :)

Hi. I would like to know if there''s a possibility to create instances of lines without using Paint Event Handler?

My problem is that I have a user control but when I''m using paint event, it did not show in my user control. Help me. Thanks! :)

推荐答案

Panel确实有一个Paint事件,我在项目中已经使用了几次.您是否尝试过在事件中设置断点以查看是否被调用?

您如何画线? GDI?其他需要检查的是使用什么坐标绘制线以确保它们相对于正确的父控件,等等.
A Panel does indeed have a Paint event and I''ve used it several times in my projects. Have you tried putting a break point in the event to see if it is getting called at all?

How are you attempting to draw the lines? GDI? Other things to check are what coordinates you are using to draw lines to make sure they are relative to the correct parent control, etc.


如果使用面板绘制事件,则不需要图片盒子;您需要在面板的画布上绘制.在这种情况下,永远不要使用CreateGraphics.当您为事件创建处理程序时,已经为您创建了图形,并将第二个参数(事件参数)传递给了您的处理程序.沃尔特·费尔(Walt Fair)试图向您解释这一点,但您似乎需要更多细节.像这样的东西:

If you use panel paint event you do not need a picture box; you need to draw on the canvas of the panel. In this case, you should never use CreateGraphics. When you create a handler to the event, graphics is already created for you and passed in second parameter (event argument) to your handler. Walt Fair tried to explain this to you, but it looks you need more detail. Something like that:

MyPanel.Paint += (sender, args) => {
    args.Graphics.DrawLine(...
    args.Graphics.DrawImage(...
};



很公平? ;)



Fair enough? ;)


这篇关于创建线实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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