如何在表单上绘制线条以创建自定义可打印表单。 [英] How to paint lines on a form to create a custom printable form.

查看:69
本文介绍了如何在表单上绘制线条以创建自定义可打印表单。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究这段代码:

I have been working on this code:

Private Sub ABToolStripMenuItem_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles ABToolStripMenuItem.Paint


       Dim var As System.Drawing.Graphics
       var = Me.CreateGraphics
       Dim pen1 As Pen
       pen1 = New Pen(Color.Black, 1)

       'Horizontal line

       '1st moves the line further in, towards the middle.
       '2nd And 4th must be the same number And they bring the line down
       '3rd Is the length of the line

       'var.DrawLine(pen1, 50, 90, 600, 90)
       var.DrawLine(pen1, 50, 200, 600, 200)
       var.DrawLine(pen1, 50, 230, 600, 230)

       'Vertical line

       '1st And 3rd numbers must be the same number to keep the line straight
       '2nd move the position of the line inward
       '4th Is the vertical length

       var.DrawLine(pen1, 50, 200, 50, 1000)



   End Sub





我想在我点击AB菜单项的地方进行设置然后填充,问题是它在我单击任何内容之前填充在表单上。我只是突出显示菜单项,它会自动绘制线条。我想将其设置为在菜单项单击上绘画。



附注,我还有一个基于ABmenuitemclick添加标签的活动。问题是,当我将两者加在一起时,线条根本不显示。阅读论坛我必须有一个专门用于绘制线条的事件。所以这就是我分开代码的原因。


我尝试了什么:



尝试切换到.click事件,但是程序因点击而做了一个paint eventargs崩溃。



I want to set it up where I click on the AB menu item then it populates, problem is that it populates on the form before I click anything. I just highlight the menu item and it automatically draws the lines. I would like to set it up to paint on menu item click.

Side note, I also have an event that adds labels based on ABmenuitemclick. The problem is when I add both together the lines do not show up at all. Reading forums I have to have an event that is specifically made to paint the lines. So that is why I separated the code.

What I have tried:

Tried switching to a .click event, but the program crashes from doing a paint eventargs with a click.

推荐答案

停止这样做!

你不应该在Paint事件中构造一个Graphics上下文,你应该使用PaintEventArgs参数中提供的上下文。

如果你构造任何图形相关的对象 - 特别是上下文,还要钢笔 - 您负责在完成后处理它们。如果不这样做,当剩余堆内存时,将会出现内存不足异常。 Grabge收藏家不会试图处理这些物品,直到堆空间变短,而且它们是一种非常稀缺的资源。



为什么你要创造一个自定义打印表单?使用PrintDocument,您可以精确控制打印输出的外观,而无需参考表单本身。打印输出通常看起来不像表格,只是因为你无法与打印输出进行交互,所以打印的按钮,DDL等都不好,让你的应用看起来很业余。
Stop doing that!
You should not construct a Graphics context in your Paint event, you should use the context that is provided in the PaintEventArgs parameter.
And if you construct any graphics related objects - particularly contexts, but also pens - you are responsible for Disposing of them when you are finished. If you don't you will get out of memory exceptions when there is loads of heap memory left. The Grabge collector will not try to dispose of these items until heap space gets short, and they are a very scarce resource.

And why are you trying to create a "custom printable form"? Use a PrintDocument and you can control exactly how your printout looks, without any reference to the form itself. Printouts don't normally look like forms, if only because you cant interact with a printout so printed buttons, DDLs etc. aren't good and make your app look amateur.


这篇关于如何在表单上绘制线条以创建自定义可打印表单。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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