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 38 3033
John,
You can use in the event two static variables (or one static point) to see
everytime if it changed,
I hope this helps,
Cor
Hi John,
which sizechanged event are you handling? Because I have written a bit of
code which does the same thing, and tried it in these 3 events and they all
only fire once, when I finish dragging the form border
Private Sub ptbImg_Resize(B yVal sender As Object, ByVal e As
System.EventArg s) Handles ptbImg.Resize
End Sub
Private Sub ptbImg_SizeChan ged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles _ ptbImg.SizeChan ged
End Sub
Private Sub frmResize_SizeC hanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles _ MyBase.SizeChan ged
End Sub
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:uq******** ******@tk2msftn gp13.phx.gbl... John,
You can use in the event two static variables (or one static point) to see everytime if it changed,
I hope this helps,
Cor
Peter,
It's actually a Panel that I have the SizeChanged event attached to.
This is so the I get scrollbars when the image is larger than the
Panel.
If it's not any trouble, could you post some sample code that makes the
event fire only once? I just did a sample test on resizing a plain
form:
Private Sub Form1_SizeChang ed(...) Handles MyBase.SizeChan ged
MessageBox.Show ("Size Changed!")
End Sub
The form won't even resize because the messagebox pops up immediately.
If I could get the messagebox to show up after finishing the resize,
that would be awesome. I could then adapt it to my real app.
Thanks!
John
Thanks for the reply. You make it seem obvious! Could you describe
more of what you mean, as it's very unclear to me. Thanks!
John
Hi John,
when you run you code: Private Sub Form1_SizeChang ed(...) Handles MyBase.SizeChan ged MessageBox.Show ("Size Changed!") End Sub
the first time you see the messagebox pop up is because the form is
initialized, but after that the event normal only fires if you let go the
form border, so at the end of the SizeChanged event.
hth
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.
"johnb41" <or****@informa tik.com> schreef in bericht
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . Peter,
It's actually a Panel that I have the SizeChanged event attached to. This is so the I get scrollbars when the image is larger than the Panel.
If it's not any trouble, could you post some sample code that makes the event fire only once? I just did a sample test on resizing a plain form:
Private Sub Form1_SizeChang ed(...) Handles MyBase.SizeChan ged MessageBox.Show ("Size Changed!") End Sub
The form won't even resize because the messagebox pops up immediately. If I could get the messagebox to show up after finishing the resize, that would be awesome. I could then adapt it to my real app.
Thanks! John
"johnb41" Thanks for the reply. You make it seem obvious! Could you describe more of what you mean, as it's very unclear to me. Thanks!
\\\
Static OldSize As Size
If Not OldSize.Equals( MeControl.Size) Then
....procedure
End If
///
I hope this helps,
Cor
"johnb41" <or****@informa tik.com> schrieb: 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.
If you are experiencing a flicker, you could enable double buffering for the
picturebox control. To do so, create a class that inherits from
'System.Windows .Forms.PictureB ox' and provides the constructor shown in the
listing below:
\\\
Public Sub New()
Me.SetStyle( _
ControlStyles.R esizeRedraw Or _
ControlStyles.D oubleBuffer Or _
ControlStyles.A llPaintingInWmP aint, _
True _
)
Me.UpdateStyles ()
End Sub
///
Then you use your custom picturebox control instead of the standard Windows
Forms picturebox.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
I gotta leave and do family stuff on this Memorial Day, so i'll only
post this quick message:
For me, the SizeChanged event seems to keep firing again and again,
until I let go of the mouse. This is in my real app, not the sample
one w/ the messagebox. For example, the image constantly tries to
redraw its self until I let go of the mouse.
I'll have to do more testing, and then play w/ Cor and herfried's
suggestions...
John
Thanks for the code. But it made no difference. Here is what I now
have:
Private Sub Pnl_Image_SizeC hanged(...) Handles
Pnl_Image.SizeC hanged
Static OldSize As Size
If Not OldSize.Equals( Pnl_Image.Size) Then
' call procedure to resize and display image
End If
End Sub
What am I missing?
John This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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...
|
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...
|
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?
| |
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);
}
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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...
|
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,...
|
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...
|
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...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |