Sizechanged event question...

J

Jonathan Allen

Windows has an option called "Show Windows Contents While Dragging".

If this is turned on, you will receive a continuous stream of SizeChanged
events. If it is turned off, you only get a single SizeChanged event. Since
this is a user-defined setting, you need to account for both cases and make
your SizeChanged code as quick as possible. The same goes for Move events.
 
J

johnb41

Jonathan,

Thanks for that info. I thought i was going crazy! So it looks like
i'm stuck w/ a sluggishly slow app when the user resizes the image
window. :(

John
 
C

Cor Ligthert

John,

Can you try this one, I have taken the sample from Peter to test it this
time.

\\\
Public SwMoving As Boolean
Private Sub Panel1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.SizeChanged
SwMoving = True
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = &HA0 Then 'is up &HA1 is nonclientarea down
If SwMoving Then
If Not ptbImg.Image Is Nothing Then
loadimage(CStr(ptbImg.Tag))
End If
SwMoving = False
End If
End If
MyBase.WndProc(m)
End Sub
///

I hope that it this time helps,

Cor
 
P

Peter Proost

Hi Cor,

your example works nicely, I think John will be very pleased with it

Greetz Peter
 
J

johnb41

Cor,

Wow, thanks for the extra effort and help! I tried your code
(obviously had to tweak it a little to fit my app), and here's what
happened:

The panel (with picturebox) gets resized without any sluggishness in
the app. BUT the image does not get redrawn when i let go of the
mouse.

But whenever i move my mouse over the bar at the top of the form (i
can't remember the name; the bar that has the minimize, maximize and
close buttons) then sub routine fires that resizes and redisplays the
image.

Strange. If the image would resize to the new Panel size without having
to run my mouse over the top bar, then it would be perfect!!!

Here's my code:

Public SwMoving As Boolean
Private Sub Pnl_Image_SizeChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Pnl_Image.SizeChanged
SwMoving = True
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = &HA0 Then 'is up &HA1 is nonclientarea down
If SwMoving Then
If Not Pb_image.Image Is Nothing Then
'below is routine that resizes
'and redisplays the image.
'The image gets displayed in the
'form that THIS code is in.
Call displayimage(m_image, Me)
End If
SwMoving = False
End If
End If
MyBase.WndProc(m)
End Sub


Anyway to tweak it a little? Thanks so much!
John
 
C

Cor Ligthert

John,

What you did not tell all the time in this thread is how you resize your
panel. I have the same as I think for others assumed that it was resized
accoording the resizing of the form. However was in doubt if it was because
of a slider.

Cor
 
J

johnb41

I "thought" I mentioned it briefly somewhere. Anyway, here's how my
Panel gets resized:

The Panel is docked (Fill) on Form1. To the right of the panel is a
dockable window (thanks to dotnetbar (www.devcomponents.com)). When
the dockable window is resized (left to right) or hidden, the Panel
will resize accordingly. So that's how it's resized!

Is your code adaptable for my situation?

(by the way, if i resize my main form, it works really nice! :)

John
 
C

Cor Ligthert

John,

This works than like a splitter (I wrote slider) and when I had understood
this earlier, a lot easier. You set in the splitter mouse down event (your
control) a swMouseDown (a global value) to true.

In the Mouse Up event of that you set your resizing code in a kind of the
same way as in the previous example (of course a call to a sub) and set the
swMouseDown again to false.

As long as that mouse is down you do nothing and when it goes up again you
do your code.

Because that I don't know that control, did I write it in this way, I hope
that this explains it.

Cor
 
J

johnb41

In the MouseUp event, you say to call a sub. Do you mean the sub that
I created to do the resizing calculations, or the Sub WndProc that you
created? I tried the latter, and it needs a "message" argument. I
don't know what to put in there.

If i totally ignore the Sub WndProc, and just put in my procedure, then
i get unusual results. Sometimes my image gets redrawn, and sometimes
it does not. Most of the time it does not redraw. It's unpredictable.

So in summary, what of your original code do I keep?

John
 
C

Cor Ligthert

John,

When it is in the case of a splitter you can use this code.
\\\
Private Sub Splitter2_SplitterMoved(ByVal sender As Object, _
ByVal e As System.Windows.Forms.SplitterEventArgs) Handles
Splitter2.SplitterMoved
If Not ptbImg.Image Is Nothing Then
loadimage(CStr(ptbImg.Tag))
End If
End Sub
///

When that wont go you can try this.

\\\However gives a little bit stranger effect
Public SwMoving As Boolean
Public swSplitterMouseMoving As Boolean
Private Sub Panel1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.SizeChanged
SwMoving = True
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = &HA0 Then
If SwMoving Then
If Not ptbImg.Image Is Nothing Then
loadimage(CStr(ptbImg.Tag))
End If
SwMoving = False
End If
SwMoving = False
End If
MyBase.WndProc(m)
End Sub
Private Sub Splitter2_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Splitter2.MouseEnter
swSplitterMouseMoving = True
End Sub
Private Sub Splitter2_MouseLeave(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Splitter2.MouseLeave
If swSplitterMouseMoving Then
If SwMoving Then
If Not ptbImg.Image Is Nothing Then
loadimage(CStr(ptbImg.Tag))
End If
SwMoving = False
End If
SwMoving = False
End If
swSplitterMouseMoving = False
End Sub
///
I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

Addendum:

\\\
Private m_Image As Image
Private m_Redraw As Boolean = True

Private Sub Form1_Load( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles MyBase.Load
m_Image = Image.FromFile("C:\WINDOWS\Angler.bmp")
End Sub

Protected Overrides Sub WndProc( _
ByRef m As Message _
)
Const WM_ENTERSIZEMOVE As Int32 = &H231
Const WM_EXITSIZEMOVE As Int32 = &H232
Select Case m.Msg
Case WM_ENTERSIZEMOVE
m_Redraw = False
Case WM_EXITSIZEMOVE
m_Redraw = True
Me.Panel1.Invalidate()
End Select
MyBase.WndProc(m)
End Sub

Private Sub Panel1_Paint( _
ByVal sender As Object, _
ByVal e As PaintEventArgs _
) Handles Panel1.Paint
If m_Redraw Then
e.Graphics.DrawImage( _
m_Image, _
0, 0, _
Me.Panel1.ClientSize.Width, Me.Panel1.ClientSize.Height _
)
End If
End Sub
///

However, this solution would prevent the panel from redrawing if the window
is dragged by the mouse.
 
C

Cor Ligthert

Herfried,

The main problem is a
dockable window (thanks to dotnetbar (www.devcomponents.com)).

The rest of the solutions where already given (I think mine is nicer), do
you know something about this control and to stop actions using this while
resizing.

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
\\\
Public SwMoving As Boolean
Private Sub Panel1_SizeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Panel1.SizeChanged
SwMoving = True
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = &HA0 Then 'is up

'&HA0' is 'WM_NCMOUSEMOVE'! In addition to that, note that the user can
change the size of a window using the keyboard (Alt+Space -> "Resize" ->
arrow keys), which won't fire non-client mouse events. All together I don't
see the benefits of your solution.
 
C

Cor Ligthert

Herfried,
In addition to that, note that the user can change the size of a window
using the keyboard (Alt+Space -> "Resize" ->

A good addition. However for that can be tested in this procedure probably
just keyup &H291 with orelse (I did not test it).

I could not find all those shortcuts from C++ on Google, however I have now
copied a page from Bob Powell where it is was in, therefore I have them now
saved in my HKW system.

I thought yesterday it would be a nice extension if somebody like Herfried
makes a nice dll so that we can get those in the same way as all other
enumerations.

When you need that information from Bob Powell to make this than I can sent
them you by mail. (Before you say it, yes I can make it myself as well
however it looks so nice as a link to your page)

The Herfried.K.Wagner namespace extension to the framework.

:)

Cor
 
C

Cor Ligthert

Herfried,

I will have a look at it, (as you know, do I hate sites which wants my
emailadres, although I know from you that this one is harmless)

Thanks,

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
I will have a look at it, (as you know, do I hate sites which wants my
emailadres, although I know from you that this one is harmless)

Yeah, I hate them too because I have to lookup my password every time I log
in.
 
J

johnb41

Sorry I couldn't try your suggestions out until now. ... and thanks
for the continued help with this! Unfortunately the dotnetbar
"dockable window" does not have a splitter that has events. No
splitter at all that I can see. It's probably using one in the
background, but I have no idea how to access it.

I think i'm just going to lay this issue to rest. I will not bother
having an instantly re-drawable picturebox/panel. Thanks again for all
your help!!!

John
 
J

johnb41

Herfried,

I tried your code, but in my app it produced some side effect errors
that I could not figure out. As I wrote to Cor above, I decided to
just give up on this effect. But at least this thread was not for
nothing... it does have some valuable code for having the SizeChanged
event fire once if the "form" itself is resized.

Thanks!
John
 

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