473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Panel.BackgroundImage problem

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
Nov 23 '05 #1
12 18679
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...
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

Nov 23 '05 #2
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.)
Nov 24 '05 #3
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:
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.)

Nov 24 '05 #4
Hi Tim,

It a bit complicated to explain, but the Idea is that I'm writing my own
control to replace the PictureBox control that will be able to handle very
large images (about 850MB) with 1 Bit Per pixel format.

On the panel (which is the control windows I'm drawing on) I'm drawing using
the P/Invoke for GDI function, and then I'm doing Panel.BackgroundImage =
m_bmp, where the bmp is a transparent Bitmap that contain some drawn details.
And the stage of Panel.BackgroundImage = m_bmp does not show the bmp on the
panel when the m_bmp is data menber of the Form.
It only work if the bmp is a local variable of the OnPaint().

Any Idea?
-------
Thanks
Sharon
--
Thanks
Sharon
"Tim Wilson" wrote:
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...
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


Nov 24 '05 #5
Hi Tim,

It a bit complicated to explain, but the Idea is that I'm writing my own
control to replace the PictureBox control that will be able to handle very
large images (about 850MB) with 1 Bit Per pixel format.

On the panel (which is the control windows I'm drawing on) I'm drawing using
the P/Invoke for GDI function, and then I'm doing Panel.BackgroundImage =
m_bmp, where the bmp is a transparent Bitmap that contain some drawn details.
And the stage of Panel.BackgroundImage = m_bmp does not show the bmp on the
panel when the m_bmp is data menber of the Form.
It only work if the bmp is a local variable of the OnPaint().

Any Idea?
-------
Thanks
Sharon
Nov 24 '05 #6
So the routine that loads the image into the Bitmap object works if the
object is a local variable but does not work if the object is stored at the
class level? How are you loading the image into the Bitmap object? Maybe if
you post the code that you're using to render the image we can take a look
at it.

--
Tim Wilson
..NET Compact Framework MVP

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:4A**********************************@microsof t.com...
Hi Tim,

It a bit complicated to explain, but the Idea is that I'm writing my own
control to replace the PictureBox control that will be able to handle very
large images (about 850MB) with 1 Bit Per pixel format.

On the panel (which is the control windows I'm drawing on) I'm drawing using the P/Invoke for GDI function, and then I'm doing Panel.BackgroundImage =
m_bmp, where the bmp is a transparent Bitmap that contain some drawn details. And the stage of Panel.BackgroundImage = m_bmp does not show the bmp on the panel when the m_bmp is data menber of the Form.
It only work if the bmp is a local variable of the OnPaint().

Any Idea?
-------
Thanks
Sharon

Nov 24 '05 #7
Ok, the code is too large to post in here, so I summed it up, and here it is.

////////////////////////////////////////////////////////////////////////////////////////////////

m_bmp = new Bitmap(myPanel.Width, myPanel.Height);
m_bmpGrp = Graphics.FromImage(m_mapImg);
m_bmpGrp.Clear(Color.Transparent);

...... // some code

m_bmpGrp.DrawImage(otherBitmap_1 ,0, 0, m_mapImg.Width, m_mapImg.Height);
m_bmpGrp.DrawImage(otherBitmap_2 ,0, 0, m_mapImg.Width, m_mapImg.Height);

protected override void OnPaint(PaintEventArgs e)
{
// Drawing on the Panel window using the GDI function StretchDIBits(...)

m_DrawArea.BackgroundImage = m_bmp; // The m_bmp does not show on screen.

// If in here I do:
// m_bmp.Save("MapImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
// I can see in the file that the image is well drawn.
}

////////////////////////////////////////////////////////////////////////////////////////////////
I hope it give some more info.
----------
Thanks
Sharon
Nov 24 '05 #8
What happens if you draw the image directly to the form within the forms
OnPaint?

e.Graphics.DrawImage(m_bmp, ...);

Does it properly paint on the forms background?

--
Tim Wilson
..NET Compact Framework MVP

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:A1**********************************@microsof t.com...
Ok, the code is too large to post in here, so I summed it up, and here it is.
////////////////////////////////////////////////////////////////////////////
////////////////////
m_bmp = new Bitmap(myPanel.Width, myPanel.Height);
m_bmpGrp = Graphics.FromImage(m_mapImg);
m_bmpGrp.Clear(Color.Transparent);

..... // some code

m_bmpGrp.DrawImage(otherBitmap_1 ,0, 0, m_mapImg.Width, m_mapImg.Height);
m_bmpGrp.DrawImage(otherBitmap_2 ,0, 0, m_mapImg.Width, m_mapImg.Height);

protected override void OnPaint(PaintEventArgs e)
{
// Drawing on the Panel window using the GDI function StretchDIBits(...)

m_DrawArea.BackgroundImage = m_bmp; // The m_bmp does not show on screen.

// If in here I do:
// m_bmp.Save("MapImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
// I can see in the file that the image is well drawn.
}

////////////////////////////////////////////////////////////////////////////
////////////////////

I hope it give some more info.
----------
Thanks
Sharon

Nov 24 '05 #9
Yes, it does paint on the forms background?

Mmmm..... ?

-----
Thanks
Sharon
Nov 27 '05 #10
What if you create a custom control to handle the painting of the image
using its OnPaint override and the DrawImage method? Perhaps it's something
in the way that the image is handled through the BackgroundImage property of
the Panel.

--
Tim Wilson
..NET Compact Framework MVP

"Sharon" <Sh*****@newsgroups.nospam> wrote in message
news:4A**********************************@microsof t.com...
Yes, it does paint on the forms background?

Mmmm..... ?

-----
Thanks
Sharon

Nov 27 '05 #11
Hi Sharon,
Thanks for your feedback!
I mean that I have some more code, but it does not change the idea.

In this scenario, I hope you can provide me a simplified sample, which
reproduces your issue so that I could debug it on our side. I think it will
help us get closer to resolving your issue, so I appreciate your time in
performing them.

If there is any question, please feel free to let me know. Thanks for your
understanding!

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.)
Nov 28 '05 #12
I think it's too much.

I think I'll stick with your first idea.

--
Thanks
Sharon
Nov 28 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dunc | last post by:
I'm creating an XHTML page in aspx, and I've been using a Panel control to show and hide areas. I've just found, however, that depending on the browser you're using, sometimes it puts a DIV tag or...
1
by: Gary Coutts | last post by:
Hi, I am trying to center an panel using the following: <asp:Panel id="pnltest" HorizontalAlign="Center" BackColor="white" Width="800" Runat="server"> <asp:Button id=btnTest Runat="server"...
2
by: Burstock | last post by:
I have a page that uses a Panel server control with a vertical scroll bar. It is in a table on the page that uses a Master page for it basic layout. Occasionally, when the page displays in IE (not...
1
by: jediknight | last post by:
Hi All, I am trying to use the example in codeproject (http://www.codeproject.com/cs/media/flickerFreeDrawing.asp) called Flicker free drawing using GDI+ and C# which all well and good but I am...
4
by: =?Utf-8?B?cmF5IG4=?= | last post by:
I have a need to put an image on the background of a SplitterPanel. However, I need it to appear in the bottom right corner of the panel instead of the standard Centered/Tiled/Stretched found in...
0
by: Kalpana Naraboina | last post by:
Hi Toolstrips in a toolstrip panel are aligned in a stack even though added to a first row in a toolstrip panel. i.e. the blocks in the toolstrip should be aligned sequentially in a single...
2
JimWu
by: JimWu | last post by:
Do anyone know how to layout in Panel control. The code as follows labels.Text = "Album Name :"; labels.Text = "Title :"; labels.Text = "Tag :"; labels.Text = "Description :";
2
by: ATR2000 | last post by:
I have setup a Panel to have a width of 100% so that it will adjust to users screensize. Within the panel I have a table. Unfortunately the table holds a lot of data and exceeds the size of the...
5
by: kulabhishek | last post by:
Hi all, I am using panel with autoscroll = true in C# I have added dataGridView control inside panel. When the height and width of dataGridView increases and becomes more than panel size,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.