background images in mdi container

G

Guest

I need to display my company's corporate logo on the mdi container form of my
windows app. The image is fairly small. I do not want it tiling, and i do not
want it covering any mdi child forms/controls. How can I do this?
 
J

Jeffrey Tan[MSFT]

Hi denmast,

Thanks for your post.

Can you provide some detailed information about where you want to display
the background image on MDI container? I think Form's Icon should be the
best place for logo image, especially for small logo image. If you want to
place at this place, we can use Form.Icon property.

If you want to display the logo image on the background, we can first find
the MdiClient on the MDI container, then set its BackgroundImage property.
Please refer to the link below:
"34.8 How can I change the background of my MDI Client container?"
http://64.78.52.104/FAQ/WinForms/FAQ_c4c.asp#q799q

However, BackgroundImage property will do tiling for the image, which is
not what you wanted. Then I suggest you place a PictureBox control on the
MDI container, then use it Image property to display the logo image. But
the MDI child form may overlay this picturebox, so I still think Icon
property should be a suitable place.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Jeffrey,

My logo image is 355px by 241px.....much too large for use as an icon. In
order to ensure that the image is always centered regardless of the size of
the mdi container window, I use a picturebox to hold the image. This also
prevents the image from tiling, which I do not want. This works great, if I
don't show any mdi child forms! But when I do, the image (or more precisely
I'm sure, the picturebox control) on the mdi container displays over top of
any mdi child form. I tried to use the .sendtoback method on the picturebox
when a mdi child is loaded, but this renders the image completely invisible
on the mdi container, which i dont want either. How can I get the image to
display, but not have it completely cover the mdi child form?....and in such
a way that if the user resized the mdi child the image might be still visible
outside the edge of the mdi child form, but obviously (and intuitively) the
image is covered where the mdi child form exists?

I hope that that gives you enough detail to be able to provide some
guidance, thanks.
 
J

Jeffrey Tan[MSFT]

Hi denmast,

Thanks for your feedback.

Oh, because in the original post, you said "The image is fairly small", I
suspect your image is small enough to display as Icon :). It seems that it
is not so small.

I think you currently want to display the image in the background of MDI
container, so MDI child window can overlay it, and can display out when the
child form moves away. It seems that the MDI client window is an ideal
place for paiting the image. The MDI Client Window is a child window on the
MDI container which we see as a "black" window. And it fulfill the entire
client area of MDI container form.

We should first find this form, and use NativeWindow class to do
subclassing to it. This technology is documented by the article below:
"Painting in the MDI Client Area"
http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows/MDI_Client_Area
_Painting/article.asp

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Hi Jeffrey,

Thanks for the info on the link....I have to admit that I didn't try it out,
for 2 reasons...1) i'm not terribly proficient at C#, and 2) it doesn't look
like a simple way to do what I want.....putting a logo on the mdi
container/client form isn't so crucial that i can afford to spend too much
time on it ... I would have thought that doing this would be easier than it
appears to be....clearly not. No worry.....thanks for your help though.
 
J

Jeffrey Tan[MSFT]

Hi denmast,

Yes, I see your concern. However, there is a sample project in the link I
provided, I think you can just cut the necessary code from that project and
use in your project. This should be much easier. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
M

Mick Doherty

Here's a simple method in VB:

\\\
Private WithEvents mdi As MdiClient
Private bufferImage As Bitmap

Private Sub MainForm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
For Each child As Control In Me.Controls
If TypeOf child Is MdiClient Then
mdi = DirectCast(child, MdiClient)
Exit For
End If
Next
MyBase.OnResize(EventArgs.Empty)
End Sub

Private Sub MainForm_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Resize
CreateBufferImage()
End Sub

Private Sub CreateBufferImage()
If mdi.Size.Equals(Size.Empty) Then Return
Dim someImage As Bitmap = Me.Icon.ToBitmap
bufferImage = New Bitmap(mdi.Width, mdi.Height)
Dim g As Graphics = Graphics.FromImage(bufferImage)
g.Clear(Color.PowderBlue)
g.DrawImage(someImage, (mdi.Width - someImage.Width) \ 2, _
(mdi.Height - someImage.Height) \ 2)
g.Dispose()
Me.BackgroundImage = bufferImage
End Sub
///
 
M

Mick Doherty

In fact to be even simpler you can just modify the Designer generated code
to add an MDIClient control:

\\\
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private WithEvents MDI As MdiClient
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MDI = New System.Windows.Forms.MdiClient
Me.SuspendLayout()
'
'MDI
'
Me.MDI.BackColor = System.Drawing.Color.Salmon
Me.MDI.Dock = System.Windows.Forms.DockStyle.Fill
Me.MDI.Location = New System.Drawing.Point(0, 0)
Me.MDI.Name = "MDI"
Me.MDI.TabIndex = 0
'
'MainForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(360, 209)
Me.Controls.Add(Me.MDI)
Me.IsMdiContainer = True
Me.Name = "MainForm"
Me.Text = "MainForm"
Me.ResumeLayout(False)

///

You can't select the MDIClient by clicking on it, but you can select it by
dragging the mouse on it or choosing it from the dropdown combo in the
properties window. You won't see any of the property changes at Design-Time
though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top