Question how update picturebox graphics of mdichildform

aw48

Active member
Joined
Feb 9, 2013
Messages
36
Location
Germany
Programming Experience
10+
hi,
I'm developing a small picture editing application in VS10 c# using mdi. Loading an image from file or creating a new image will always open a new childform.
The childform has menustrip, picturebox,scrollbars (to scroll the picturebox image) and statusstrip
the issue I get is as long as I drag the childform inside the parent from (which usually is maximized) erverything's ok. but when I move the childform partially out of the parentform's client area, or even worse when I have more than one childform, the picturebox image is not redrawn.
What am I missing here. I've tried the childform move event but that did'nt help. When I load three imagefiles in succession activating a form by just clicking is ok only moving the form creates quite a mess.
any suggestion, thanks in advance
 
What you're missing is that we are not mind-readers. If code is not working then code is wrong. We cannot see what's wrong with code if we can't see code. Post the relevant code. Better still, create a test project that isolates just that specific functionality. That may allow you to solve the issue for yourself but, if it doesn't, it allows you to provide us with instructions/information/code to reproduce your issue with the minimum of effort. If we can reproduce the issue, we have a chance of resolving it.
 
Am I the only one reading this?
as I drag the childform inside the parent
A child form doesn't have a parent. Any form that is derived from another is either called as a new form or a model form dialog. None of which makes them a child of the model they represent. They are simply inherently independent.
but when I move the childform partially out of the parentform's client area
That doesn't make sense. And if it's maximised, dragging the bar at the top invokes the API to put it in "normal" mode, with the size of the form generally bound shy of the screens resolution.

Reading what you wrote, already has me confused as to what you're actually doing and trying to explain. I guess showing your code will leave me even more confused... Perhaps showing the relative code you're having a problem with might make us understand your issue a little better and what it is you're trying to explain. . .
 
Am I the only one reading this?

A child form doesn't have a parent. Any form that is derived from another is either called as a new form or a model form dialog. None of which makes them a child of the model they represent. They are simply inherently independent.

That doesn't make sense. And if it's maximised, dragging the bar at the top invokes the API to put it in "normal" mode, with the size of the form generally bound shy of the screens resolution.

Reading what you wrote, already has me confused as to what you're actually doing and trying to explain. I guess showing your code will leave me even more confused... Perhaps showing the relative code you're having a problem with might make us understand your issue a little better and what it is you're trying to explain. . .
I think you may have missed that this is an MDI application. The parent/child relationship is physical, not one of inheritance. There is a single parent form and the multiple child forms are embedded within it. Presumably this:
but when I move the childform partially out of the parentform's client area
means when only part of a child is visible within the parent's viewport.
 
when I move the childform partially out of the parentform's client area, or even worse when I have more than one childform, the picturebox image is not redrawn.
Sounds like a bug in your paint event handler code. And even worse, the bug is such that is can only handle painting just one child form at a time.
 
I think you may have missed that this is an MDI application.
Sorry, I clearly wasn't paying attention John. Lol

You can hide that post if you want, as it may just confuse others.
There is a single parent form and the multiple child forms are embedded within it.
Yes, if their main form is set as the main container. Yea yea my bad
 
hi,
thank you guys for your contribution
the only relevant code I can offer is

// ***********************************************************************
private void Canvas_Paint(object sender, PaintEventArgs e)
// ***********************************************************************
{
if (BMP == null) return;

e.Graphics.DrawImage(Canvas.Image, e.ClipRectangle, X, Y,
e.ClipRectangle.Width, e.ClipRectangle.Height, GraphicsUnit.Pixel);
}

I use Graphics.DrawImage here because one of the application's features is zooming and I don't want the picturebox growing with the enlarged image.
BMP is a class that provides the image and lot's of functionallity regarding image processing
the childform's paint event is empty
I have added a 'Window' menu item to the main form so I can switch from one child to another and there's no problem with the corresponding images
What should make a childform refresh itself when other childform on top is moved ?
please let me know what else I can provide
Franz
 
hi,
@Skydiver : thanks for the hint
I said I had tried the childforms move event but what I didn't was
this.Parent.Validate(true);
now it works fine
thanks to all of you
 
Should that be Invalidate rather than Validate? That is the method that tells a control that something needs to be repainted and thus to raise a Paint event.
 

Latest posts

Back
Top Bottom