我应该存储Graphics对象吗? [英] Should I store Graphics object ?

查看:74
本文介绍了我应该存储Graphics对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们目前正在将我们的项目从VB6移植到VB .NET。


之前我们曾经进行过规模转换像pictureBox,

形式等对象。现在这样的转换是在

表格/图片框的图形对象上进行的。


如果从我的pictureBox中加载一个图形对象加载

表单的事件处理程序并将其存储为表单的成员变量,应该更好吗,使得

转换为何时必需(我们真的需要这样的转换

从mils到像素。)。最后我可以在表格处理好后处理它。


但我已经读过某个地方,图形对象永远不应该存储为

成员的一个类的varibale。所以我真的很困惑我应该怎么做?$ / b

Plz帮我解决这个问题..


sanjay

解决方案

你绝对不应该存储图形对象。所有使用

Graphics的代码理想情况下都应封装在Paint / OnPaint程序中。


Sanjay < SA *********** @ gmail.com>在消息中写道

新闻:eS ************** @ TK2MSFTNGP15.phx.gbl ...

hi,

我们目前正在将项目从VB6移植到VB .NET。

之前我们曾经对像boxBox,
表单等对象进行缩放转换。现在进行了这样的转换在
form / pictureBox的图形对象上。

如果在我的pictureBox中加载一个图形对象加载
表单的事件处理程序并将其存储为成员应该更好形式的变量,
在需要时进行转换(我们真的需要从mils到像素的转换。)。最后我可以在处理表单时处理它。

但我已经读过某个地方,应该永远不要将Graphics对象存储为类的成员varibale。所以我我真的很困惑我应该做什么?

Plz帮我解决这个问题..

sanjay



否。从来没有。


-

鲍勃鲍威尔[MVP]

Visual C#,System.Drawing

在Windows窗体中查找优秀的Windows窗体文章提示和技巧
http://www.bobpowell.net/tipstricks.htm


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


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

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


Sanjay < SA *********** @ gmail.com>在消息中写道

新闻:eS ************** @ TK2MSFTNGP15.phx.gbl ...

hi,

我们目前正在将项目从VB6移植到VB .NET。

之前我们曾经对像boxBox,
表单等对象进行缩放转换。现在进行了这样的转换在
form / pictureBox的图形对象上。

如果在我的pictureBox中加载一个图形对象加载
表单的事件处理程序并将其存储为成员应该更好形式的变量,
在需要时进行转换(我们真的需要从mils到像素的转换。)。最后我可以在处理表单时处理它。

但我已经读过某个地方,应该永远不要将Graphics对象存储为类的成员varibale。所以我我真的很困惑我应该做什么?

Plz帮我解决这个问题..

sanjay



Hi Hederman,

感谢您的回复。

但我们的'是一个不同的要求。我们做所有的绘图单位为

密尔(0.001英寸)。所以我们正在进行大量的转换

来自/来自mils的支持单位。如果我放油漆中的所有

转换,它真的会很乱。但是现在的实现可能不会是b $ b。


也可以告诉我为什么反对制作一个数据

会员。


我会感谢你为同样的/>

感谢你

sanjay


-----原始消息-----

来自:" Sean Hederman" < us *** @ blogentry.com>

新闻组:

microsoft.public.dotnet.framework,microsoft.public .dotnet.framework.drawing,
microsoft.public.dotnet.framework.windowsforms,mic rosoft.public.dotnet.gener

al,microsoft.public.dotnet.languages.vb

发送时间:2005年3月11日星期五下午6:10

主题:Re:我应该存储图形对象吗?

你应该肯定没有存储图形对象。理想情况下,所有使用
Graphics的代码都应封装在Paint / OnPaint
程序中。
Sanjay < SA *********** @ gmail.com>在消息中写道
新闻:eS ************** @ TK2MSFTNGP15.phx.gbl ...

hi,
我们目前正在将我们的项目从VB6移植到VB .NET。

之前我们曾经对像boxBox
,表格等对象进行缩放转换。现在这种转换是在图形对象上进行的
形式/ pictureBox。

如果从我的pictureBox中加载
表单的事件处理程序中的图形对象并将其存储为表单的成员变量,应该更好吗? ,
在需要时进行转换(我们真的需要从mils到像素的转换。)。最后我可以在处理表单时处理它。

但我已经读过某个地方,应该永远不要将Graphics对象存储为类的成员varibale。所以我我真的很担心
我该怎么办?

Plz帮我解决这个问题..

sanjay




hi,

We are currently porting our project from VB6 to VB .NET.

Earlier we used to make scale transformations on objects like pictureBox ,
forms etc.Now Such transformations are made on the graphics object of the
form/pictureBox.

Should It be better if make a graphics object from my pictureBox in load
event handler of the form and store it as member variable of the form , make
transformations as and when required(we really require such transformations
from mils to pixels.). And finally I can dispose it when the form is
disposed.

But I have read somewhere that Graphics object should never be stored as
member varibale of a class.And so I am really confused as to what should I
do ?

Plz help me regarding this..

sanjay

解决方案

You should definately not store the graphics object. All the code using
Graphics should ideally be encapsulated within the Paint/OnPaint procedures.

"Sanjay" <sa***********@gmail.com> wrote in message
news:eS**************@TK2MSFTNGP15.phx.gbl...

hi,

We are currently porting our project from VB6 to VB .NET.

Earlier we used to make scale transformations on objects like pictureBox ,
forms etc.Now Such transformations are made on the graphics object of the
form/pictureBox.

Should It be better if make a graphics object from my pictureBox in load
event handler of the form and store it as member variable of the form ,
make
transformations as and when required(we really require such
transformations
from mils to pixels.). And finally I can dispose it when the form is
disposed.

But I have read somewhere that Graphics object should never be stored as
member varibale of a class.And so I am really confused as to what should I
do ?

Plz help me regarding this..

sanjay



No. Never.

--
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.

"Sanjay" <sa***********@gmail.com> wrote in message
news:eS**************@TK2MSFTNGP15.phx.gbl...

hi,

We are currently porting our project from VB6 to VB .NET.

Earlier we used to make scale transformations on objects like pictureBox ,
forms etc.Now Such transformations are made on the graphics object of the
form/pictureBox.

Should It be better if make a graphics object from my pictureBox in load
event handler of the form and store it as member variable of the form ,
make
transformations as and when required(we really require such
transformations
from mils to pixels.). And finally I can dispose it when the form is
disposed.

But I have read somewhere that Graphics object should never be stored as
member varibale of a class.And so I am really confused as to what should I
do ?

Plz help me regarding this..

sanjay



Hi Hederman,
thanks for your reply.
But our''s is a different requirement.We do all our drawing in units of
mils(0.001 inch).And so we are doing a lot of transformations
to/from supported units to/from mils here and there.If I put all the
transformations in the paint,It will really be messy.Anyway it is not
possible with the current implementations.

Also could u plz make me clear as to why r u against making in a data
member.

I will be thankful to u for the same

thanking u
sanjay

----- Original Message -----
From: "Sean Hederman" <us***@blogentry.com>
Newsgroups:
microsoft.public.dotnet.framework,microsoft.public .dotnet.framework.drawing,
microsoft.public.dotnet.framework.windowsforms,mic rosoft.public.dotnet.gener
al,microsoft.public.dotnet.languages.vb
Sent: Friday, March 11, 2005 6:10 PM
Subject: Re: Should I store Graphics object ?

You should definately not store the graphics object. All the code using
Graphics should ideally be encapsulated within the Paint/OnPaint procedures.
"Sanjay" <sa***********@gmail.com> wrote in message
news:eS**************@TK2MSFTNGP15.phx.gbl...

hi,

We are currently porting our project from VB6 to VB .NET.

Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the graphics object of the form/pictureBox.

Should It be better if make a graphics object from my pictureBox in load
event handler of the form and store it as member variable of the form ,
make
transformations as and when required(we really require such
transformations
from mils to pixels.). And finally I can dispose it when the form is
disposed.

But I have read somewhere that Graphics object should never be stored as
member varibale of a class.And so I am really confused as to what should I do ?

Plz help me regarding this..

sanjay




这篇关于我应该存储Graphics对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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