473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sizechanged event question...

I have a Picturebox that has an image displayed inside. Through code,
I was able to have the "whole image" display in it without distortion.
(Like a "Fit All" in most any image viewer program)

Now, when the Picturebox gets resized by the user, I want the image to
recalculate and display as "Fit All" again.

So I have code in my SizeChanged event of the picturebox. When the
"size changed", it does it's calculation, and displays properly.

It works, but there is a problem: If the user drags the Picturebox
window larger or smaller, the SizeChanged event fires many times per
second. This causes alot of sluggishness in the app when trying to
display the image.

Is there anyway that i can have the SizeChanged event fire ONCE when
i'm done resizing the picturebox?

(By the way, the picturebox gets resized indirectly. It's dock is set
to Fill. When the interface "Next" to it gets resized, the Picturebox
naturally will resize accordingly)

Thanks for all your help!

John

Nov 21 '05
38 3035
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.

--
Jonathan Allen
"Peter Proost" <pp*****@nospam .hotmail.com> wrote in message
news:O$******** ********@TK2MSF TNGP10.phx.gbl. ..
I also find it very strange, if I put a msgbox in the sizechanged event of
a
form, it first pops up before the form is even visible (that's just the
form
initializing) and then when the form is loaded it only pops up AFTER I let
go of the mouse button, no extra code required.

For example the example I posted at my pc only fires the sizechanged event
after I let go of the mousebutton.

Greetz Peter
a messagebox inside a Sizechanged event (for a Form), the messagebox
does not appear until AFTER you let go of the mouse button? No extra
code required?

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.

"johnb41" <or****@informa tik.com> schreef in bericht
news:11******** *************@g 14g2000cwa.goog legroups.com...
I have VS 2003 also. So let me get this straight, if you simply put in
a messagebox inside a Sizechanged event (for a Form), the messagebox
does not appear until AFTER you let go of the mouse button? No extra
code required?

Amazing. I can't even resize a form because the messagbox pops up too
soon.

If anyone else is reading this, does this happen to you also?

If this is true, i'm surprised that the others that posted in this
thread didn't mention it. Cor really went out of his way to help w/ a
couple potential solutions. Now i'm more confused than ever! (but that
isn't new)

John


Nov 21 '05 #21
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

Nov 21 '05 #22
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_SizeChan ged(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Panel1.SizeChan ged
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
Nov 21 '05 #23
Hi Cor,

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

Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning.
"Cor Ligthert" <no************ @planet.nl> schreef in bericht
news:#v******** ******@TK2MSFTN GP12.phx.gbl...
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_SizeChan ged(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Panel1.SizeChan ged
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

Nov 21 '05 #24
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_SizeC hanged(ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles Pnl_Image.SizeC hanged
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

Nov 21 '05 #25
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
Nov 21 '05 #26
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

Nov 21 '05 #27
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
Nov 21 '05 #28
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

Nov 21 '05 #29
John,

When it is in the case of a splitter you can use this code.
\\\
Private Sub Splitter2_Split terMoved(ByVal sender As Object, _
ByVal e As System.Windows. Forms.SplitterE ventArgs) Handles
Splitter2.Split terMoved
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 swSplitterMouse Moving As Boolean
Private Sub Panel1_SizeChan ged(ByVal sender As Object, _
ByVal e As System.EventArg s) Handles Panel1.SizeChan ged
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_Mouse Enter(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Splitter2.Mouse Enter
swSplitterMouse Moving = True
End Sub
Private Sub Splitter2_Mouse Leave(ByVal sender As Object, ByVal e As
System.EventArg s) Handles Splitter2.Mouse Leave
If swSplitterMouse Moving 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
swSplitterMouse Moving = False
End Sub
///
I hope this helps,

Cor
Nov 21 '05 #30

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

Similar topics

18
2893
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
2
17037
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
0
1007
by: Mike hofer | last post by:
I am studying up for my MCAD, and came across an interesting conundrum. According to my textbook, there are FOUR steps to publish an event: 1. Define a delegate type that specifies the prototype of the event handler. If the event generates no data, use the predefined EventHandler delegate. 2. Define an event based on the delegate type defined in the preceding step. 3. Define a protected, virtual method that raises the event. 4. When the...
5
3372
by: Mike Salter | last post by:
I created a page that reads a DB for questions and possible answers (usuallyYes/No). I create a panel for each group of questions, and add a panel for each question to the Group panel. To the Question panel I add a label with the question text, and a radiobuttonlist with the answers. I have an eventhandler I add to each radiobuttonlist, which is the same for all. The Group panels are then added to Placeholder1.Controls. I then add...
6
1710
by: Tim | last post by:
Hi, I have a module that acts as a publisher of events. The clients subscribe for the events using the '+=' operator. Instead, I would like the clients to call a method like "RegisterForXEvent" passing the required information. Inside that method, I would like to add the client to the list of subscribers. Is it possible to implement the above. If so, how do I do it? What kinda information should the client pass to the Event publisher?
3
1670
by: jm | last post by:
>From a C. Petzold book I have Programming Windows C#. It's a little old now, but anyway, it has on page 71 (shortened): form.Paint += new PaintEventHandler(MyPaintHandler); static void MyPaintHandler(object objSender, PaintEventArgs pea) { Graphics grfx = pea.Graphics; grfx.Clear(Color.Chocolate); }
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.