Panel.BackgroundImage问题 [英] Panel.BackgroundImage problem

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

问题描述

我在我的表单中使用Panel控件来显示背景图像。

所以在Form OnPaint()中我写道:

myPanel.BackgroundImage = m_bmp;


虽然m_bmp是Form Bitmap成员。


问题是图像没有显示在屏幕上。 />

但是如果将OnPaint()中的代码更改为:

位图bmp =新位图(m_bmp,m_bmp.Width,m_bmp.Height);

myPanel.BackgroundImage = bmp;


工作正常。


经过一些更多测试后,我发现如果Ia ??我附加

到myPanel.BackgroundImage的图像是Form的类成员?? *它没有

工作。

但是如果附加的图像是OnPaint()的本地图像?*它工作正常。


任何人都可以告诉我它为什么会发生以及如何使它与位图一起工作

会员?

---------

谢谢

Sharon

Ia??m using a Panel control in my form to display a background image.
So in the Form OnPaint() I wrote:
myPanel.BackgroundImage = m_bmp;

While the m_bmp is the Form Bitmap member.

The problem is that the image is not shown on the screen.

But if change the code in the OnPaint() to:
Bitmap bmp = new Bitmap(m_bmp, m_bmp.Width, m_bmp.Height);
myPanel.BackgroundImage = bmp;

It works fine.

After doing some more testing, I found that if the image that Ia??m attaching
to the myPanel.BackgroundImage is a class member of the Form ??* It does not
work.
But if the attached image is a local image of the OnPaint() ??* It works OK.

Can anybody tell me why it happens and how to make it work with a bitmap
member?
---------
Thanks
Sharon

推荐答案

为什么要在Forms

OnPaint方法中设置Panel的BackgroundImage属性?在你的情况下这是否有必要?


-

Tim Wilson

..NET Compact Framework MVP


" Sharon" <嘘***** @ newsgroups.nospam>在留言中写道

news:9E ********************************** @ microsof t.com ...
Why are you setting the Panel''s BackgroundImage property in the Forms
OnPaint method? Is this somehow necessary in your situation?

--
Tim Wilson
..NET Compact Framework MVP

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:9E**********************************@microsof t.com...
我在表单中使用Panel控件来显示背景图像。
所以在Form OnPaint()中我写道:
myPanel .BackgroundImage = m_bmp;

虽然m_bmp是Form Bitmap成员。

问题是图像没有显示在屏幕上。
但是如果将OnPaint()中的代码更改为:
位图bmp =新位图(m_bmp,m_bmp.Width,m_bmp.Height);
myPanel.BackgroundImage = bmp;

经过一些更多的测试,我发现如果附加到myPanel.BackgroundImage的我是
的图像是Form的类成员?它没有工作。
但如果附加的图像是OnPaint()的本地图像?它工作正常。

任何人都可以告诉我它为什么会发生以及如何使用位图
成员吗?

-------- -
谢谢
Sharon
I''m using a Panel control in my form to display a background image.
So in the Form OnPaint() I wrote:
myPanel.BackgroundImage = m_bmp;

While the m_bmp is the Form Bitmap member.

The problem is that the image is not shown on the screen.

But if change the code in the OnPaint() to:
Bitmap bmp = new Bitmap(m_bmp, m_bmp.Width, m_bmp.Height);
myPanel.BackgroundImage = bmp;

It works fine.

After doing some more testing, I found that if the image that I''m attaching to the myPanel.BackgroundImage is a class member of the Form ? It does not
work.
But if the attached image is a local image of the OnPaint() ? It works OK.

Can anybody tell me why it happens and how to make it work with a bitmap
member?
---------
Thanks
Sharon



您好Sharon,

欢迎来到MSDN新闻组!


我不确定你如何在代码中使用类位图成员。但是,如果我们按照以下方式使用它,它可能会很好用。您可以参考以下

代码,如果我误解了您,请随时告诉我。谢谢!


命名空间WindowsApplication1

{

公共类Form1:System.Windows.Forms.Form

{

private System.Windows.Forms.Panel panel1;

private Bitmap m_bmp;


private System.ComponentModel。容器组件= null;


public Form1()

{

InitializeComponent();

}


protected override void Dispose(bool disposing)

{

if(disposing)

{

if(components!= null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


protected override void OnPaint(PaintEventArgs e )

{

base.OnPaint(e);

panel1.BackgroundImage = m_bmp;

}


#region Windows


private void InitializeComponent()

{

this.panel1 = new System.Windows.Forms.Panel();

this.SuspendLayout();

//

// panel1

//

this.panel1.Location = new System.Drawing.Point(56,56);

this.panel1.Name =" panel1";

this。 panel1.Size = new System.Drawing.Size(128,96);

this.panel1.TabIndex = 0;

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5,13);

this.ClientSize = new System.Drawing.Size(292,266);

this.Controls.Add(this.panel1);

this.Name =" Form1";

this.Text =" Form1";

this.ResumeLayout(false);


//

//位图

//

this.m_bmp =新位图(" c:\\ temp \\1.bmp");


}

#endregion


[STAThread]

static void Main()

{

Application.Run(新Form1());

}

}

}


如果有任何问题,请随时加入社区,我们将在这里为您提供方便的支持。再次感谢,祝你有愉快的一天。


最诚挚的问候,


Terry Fei [MSFT]

微软社区支持

安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)
Hi Sharon,
Welcome to MSDN Newsgroup!

I don''t make sure how you use a class bitmap member in code. However, if we
use it as follows, it could work well. You could refer to the following
code and if I misunderstood you, please feel free to let me know. Thanks!

namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private Bitmap m_bmp;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
panel1.BackgroundImage = m_bmp;
}

#region Windows

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(56, 56);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(128, 96);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

//
// Bitmap
//
this.m_bmp = new Bitmap("c:\\temp\\1.bmp");

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

If there is any question, please feel free to join the community and we are
here to support you at your convenience. Thanks again and have a nice day.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


嗨Terry,


您发布的代码非常简单,这就是我正在使用的代码,但关闭

当然我正在做一些事情;我的意思是我有更多的代码,但它确实没有改变这个想法。


所以,你可能已经明白了,我仍然有这个旋转问题。


任何想法都会受到热烈欢迎。

-------

谢谢

Sharon

-

谢谢

Sharon

"" TerryFei""写道:
Hi Terry,

The code you have posted is very simple and this is what I''m using, but off
course that I''m doing some; I mean that I have some more code, but it does
not change the idea.

So, as you probably already understand, I still have this whirred problem.

Any idea will be warmly welcome.
-------
Thanks
Sharon
--
Thanks
Sharon
""TerryFei"" wrote:
嗨Sharon,
欢迎来到MSDN新闻组!

我不确定你如何在代码中使用类位图成员。但是,如果我们按如下方式使用它,它可以很好地工作。您可以参考以下
代码,如果我误解了您,请随时告诉我。谢谢!

命名空间WindowsApplication1
公共类Form1:System.Windows.Forms.Form
{私有System.Windows.Forms.Panel panel1 ;私有位图m_bmp;

私有System.ComponentModel.Container组件= null;

public Form1()
{/> InitializeComponent( );
}

受保护的覆盖void Dispose(bool处理)
{
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
base.OnPaint(e);
panel1.BackgroundImage = m_bmp;
}

#region Windows

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
这个。 panel1.Location = new System.Drawing.Point(56,56);
this.panel1.Name =" panel1";
this.panel1.Size = new System.Drawing.Size(128, 96);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5 ,13);
this.ClientSize = new System.Drawing.Size(292,266);
this.Controls.Add(this.panel1);
this.Name =" Form1" ;;
this.Text =" Form1";
this.ResumeLayout(false);

//
//位图
//
this.m_bmp =新位图(" c:\\ temp \\1.bmp");

}
#endregion

[STAThread]
static void Main()
{Application.Run(new Form1());
}
}
}

如果有任何问题,请随时加入社区,我们将在您方便的时候为您提供支持。再次感谢,祝你有个愉快的一天。

最诚挚的问候,

特里菲[微软]微软社区支持
安全! www.microsoft.com/security
(此帖已提供按原样,没有保证,也没有赋予
权利。)
Hi Sharon,
Welcome to MSDN Newsgroup!

I don''t make sure how you use a class bitmap member in code. However, if we
use it as follows, it could work well. You could refer to the following
code and if I misunderstood you, please feel free to let me know. Thanks!

namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private Bitmap m_bmp;

private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint (e);
panel1.BackgroundImage = m_bmp;
}

#region Windows

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(56, 56);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(128, 96);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

//
// Bitmap
//
this.m_bmp = new Bitmap("c:\\temp\\1.bmp");

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}

If there is any question, please feel free to join the community and we are
here to support you at your convenience. Thanks again and have a nice day.

Best Regards,

Terry Fei[MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



这篇关于Panel.BackgroundImage问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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