画线形式? [英] Draw Line of Form?

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

问题描述

可以通过按钮点击事件在我的表单上画一条线但是在我愿意的时候不能在

加载事件上。没有更多的线对象所以使用如下:

Dim bit As Bitmap = New Bitmap(Me.Width,Me.Height)

Dim g As Graphics = Graphics.FromImage( bit)

Dim myPen Pen = New Pen(Color.Blue,1)

Me.CreateGraphics.DrawLine(myPen,0,5,Me.Width,5)

感谢一些帮助。


Ed

Can draw a line on my form with a button click event but cannot upon the
Load event when I wish. No more line object so used the following:
Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen As Pen = New Pen(Color.Blue, 1)
Me.CreateGraphics.DrawLine(myPen, 0, 5, Me.Width, 5)
Appreciate some help.

Ed

推荐答案

Ed,


" Ed Bitzer" < ED ****** @ yahoo.com> schrieb:
Ed,

"Ed Bitzer" <ed******@yahoo.com> schrieb:
可以通过按钮点击事件在我的表单上画一条线但是在我希望的时候不能在
加载事件。没有更多的线对象如此使用如下:
Dim bit As Bitmap = New Bitmap(Me.Width,Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen作为Pen = New Pen(Color.Blue,1)
Me.CreateGraphics.DrawLine(myPen,0,5,Me.Width,5)
Can draw a line on my form with a button click event but cannot upon the
Load event when I wish. No more line object so used the following:
Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen As Pen = New Pen(Color.Blue, 1)
Me.CreateGraphics.DrawLine(myPen, 0, 5, Me.Width, 5)



当时表单''''Load''事件被提出,表单尚未显示可见的
。因此,当显示表单时,图形将不可见。在

..NET的绘图模型中,只要模糊的

表格的一部分再次可见,就需要更新图纸。您可能希望将'

绘图代码放在'''Paint''事件处理程序或覆盖''OnPaint''

方法中。只要表单的一部分需要重新绘制
,就会调用这些方法:


\\\

受保护的覆盖Sub OnPaint(ByVal e As PaintEventArgs)

MyBase.OnPaint(e)

e.Graphics.DrawLine(Pens.Blue,0,5,Me.Width, 5)

结束子

///


不要忘记调用''Dispose''方法''图形''和''笔''对象
你自己创建的
(''CreateGraphics'',''新笔(...)'')当你不需要

他们了。


-

MS Herfried K. Wagner

MVP< URL :http://dotnet.mvps.org/>

VB< URL:http://classicvb.org/petition/>


At the time when the form''s ''Load'' event is raised, the form is not yet
visible. Thus the drawing will not be visible when the form is shown. In
..NET''s drawing model, drawings need to be renewed whenever a part of the
form which is obscured gets visible again. You may want to place your
drawing code in the form''s ''Paint'' event handler or an overridden ''OnPaint''
method. These methods will be called whenever a part of the form needs to
be redrawn:

\\\
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawLine(Pens.Blue, 0, 5, Me.Width, 5)
End Sub
///

Don''t fotget to call the ''Dispose'' method of ''Graphics'' and ''Pen'' objects
you created yourself (''CreateGraphics'', ''New Pen(...)'') when you don''t need
them any more.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


请参阅GDI +常见问题解答,了解为什么CreateGraphics是一个坏主意。


-

Bob Powell [MVP]

Visual C#,System.Drawing


找到很棒的Windows窗体ar Windows窗体提示和技巧中的文章
http://www.bobpowell.net /tipstricks.htm


用GDI + FAQ回答那些GDI +问题
http://www.bobpowell.net/faqmain.htm


所有新文章都提供C#和VB代码.NET。

订阅提供的RSS源,绝不会错过任何新文章。


Ed Bitzer < ED ****** @ yahoo.com>在消息中写道

新闻:O0 ************** @ TK2MSFTNGP15.phx.gbl ...
See the GDI+ FAQ for explanations of why CreateGraphics is a bad idea.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Ed Bitzer" <ed******@yahoo.com> wrote in message
news:O0**************@TK2MSFTNGP15.phx.gbl...
可以画一条线我的表单上有一个按钮点击事件但是在我希望的时候不能在
加载事件。没有更多的线对象如此使用如下:
Dim bit As Bitmap = New Bitmap(Me.Width,Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen Pen = New Pen(Color.Blue,1)
Me.CreateGraphics.DrawLine(myPen,0,5,Me.Width,5)
感谢一些帮助。

Ed
Can draw a line on my form with a button click event but cannot upon the
Load event when I wish. No more line object so used the following:
Dim bit As Bitmap = New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bit)
Dim myPen As Pen = New Pen(Color.Blue, 1)
Me.CreateGraphics.DrawLine(myPen, 0, 5, Me.Width, 5)
Appreciate some help.

Ed



>
不要忘记调用''图形'的''Dispose''方法当你不再需要它们时,你自己创造了''笔''物品(''CreateGraphics'',''New Pen(...)'')。
Don''t fotget to call the ''Dispose'' method of ''Graphics'' and ''Pen'' objects
you created yourself (''CreateGraphics'', ''New Pen(...)'') when you don''t
need them any more.




垃圾收集器一旦离开

范围,难道不是这样吗?如果这是一个愚蠢的问题,请道歉。


Martin。



Doesn''t the Garbage Collector handle this sort of thing once they go out of
scope? Apologies if this is a silly question.

Martin.


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

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