473,378 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problems using Me.Scale in Framework 2.0

A very useful feature was added in 2.0 of .NET framework which was the
scaling of a form and all the controls within it. This is really useful but
I am finding very little information of how to use it.

I have managed to implement it as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim addSize As New SizeF(0.5F, 0.5F)
Me.Scale(addSize)

End Sub

And this quite rightly reduces everything down to half of what it was.
However I am wanting to put this in the Form Resize event, and I tried this
rather clumsy approach:

Private Sub Form2_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize

Static OldWidth As Integer
Static OldHeight As Integer
If OldWidth = 0 Then OldWidth = Me.Width
If OldHeight = 0 Then OldHeight = Me.Height

Dim ScaleX As Decimal = Me.Width / OldWidth
Dim ScaleY As Decimal = Me.Height / OldHeightDim MyScale As New
SizeF(ScaleX, ScaleY)

Me.Scale(MyScale)

OldWidth = Me.Width
OldHeight = Me.Height

End Sub

The problem is that it suffers from re-entry. As soon as the form and
everything else is scaled, the Resize event is triggered again and so on.

How are we supposed to use this scale facility?

-Jerry
Jul 16 '06 #1
3 2001
I think that you can add a static Boolean variable that will be used a flag
to ignore the event

Static b As Boolean

b = not b

if b then
Scaling code goes here
end if
That will mean that the event will be implemented once though fired twice
(second time ignore)
hth,
Samuel Shulman
"Jerry Spence1" <je**********@somewhere.comwrote in message
news:44***********************@ptn-nntp-reader01.plus.net...
>A very useful feature was added in 2.0 of .NET framework which was the
scaling of a form and all the controls within it. This is really useful but
I am finding very little information of how to use it.

I have managed to implement it as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim addSize As New SizeF(0.5F, 0.5F)
Me.Scale(addSize)

End Sub

And this quite rightly reduces everything down to half of what it was.
However I am wanting to put this in the Form Resize event, and I tried
this rather clumsy approach:

Private Sub Form2_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize

Static OldWidth As Integer
Static OldHeight As Integer
If OldWidth = 0 Then OldWidth = Me.Width
If OldHeight = 0 Then OldHeight = Me.Height

Dim ScaleX As Decimal = Me.Width / OldWidth
Dim ScaleY As Decimal = Me.Height / OldHeightDim MyScale As New
SizeF(ScaleX, ScaleY)

Me.Scale(MyScale)

OldWidth = Me.Width
OldHeight = Me.Height

End Sub

The problem is that it suffers from re-entry. As soon as the form and
everything else is scaled, the Resize event is triggered again and so on.

How are we supposed to use this scale facility?

-Jerry


Jul 16 '06 #2
Thanks for that tip Samuel. Yes, that part did work OK, although the rest of
the code doesn't perform too well. The result is very jerky and only some of
my controls are actuall scaling. I think it doesn't help that I am
physically scaling the form with the mouse, and then it is also being scaled
through my code - one is fighting the other. I am surprised that help
doesn't help and there are no examples on the net anywhere.

-Jerry
"Samuel Shulman" <sa************@ntlworld.comwrote in message
news:u9**************@TK2MSFTNGP05.phx.gbl...
>I think that you can add a static Boolean variable that will be used a flag
to ignore the event

Static b As Boolean

b = not b

if b then
Scaling code goes here
end if
That will mean that the event will be implemented once though fired twice
(second time ignore)
hth,
Samuel Shulman
"Jerry Spence1" <je**********@somewhere.comwrote in message
news:44***********************@ptn-nntp-reader01.plus.net...
>>A very useful feature was added in 2.0 of .NET framework which was the
scaling of a form and all the controls within it. This is really useful
but I am finding very little information of how to use it.

I have managed to implement it as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim addSize As New SizeF(0.5F, 0.5F)
Me.Scale(addSize)

End Sub

And this quite rightly reduces everything down to half of what it was.
However I am wanting to put this in the Form Resize event, and I tried
this rather clumsy approach:

Private Sub Form2_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize

Static OldWidth As Integer
Static OldHeight As Integer
If OldWidth = 0 Then OldWidth = Me.Width
If OldHeight = 0 Then OldHeight = Me.Height

Dim ScaleX As Decimal = Me.Width / OldWidth
Dim ScaleY As Decimal = Me.Height / OldHeightDim MyScale As New
SizeF(ScaleX, ScaleY)

Me.Scale(MyScale)

OldWidth = Me.Width
OldHeight = Me.Height

End Sub

The problem is that it suffers from re-entry. As soon as the form and
everything else is scaled, the Resize event is triggered again and so on.

How are we supposed to use this scale facility?

-Jerry



Jul 17 '06 #3
On Sun, 16 Jul 2006 19:35:50 +0100, "Jerry Spence1"
<je**********@somewhere.comwrote:
>A very useful feature was added in 2.0 of .NET framework which was the
scaling of a form and all the controls within it. This is really useful but
I am finding very little information of how to use it.

I have managed to implement it as follows:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim addSize As New SizeF(0.5F, 0.5F)
Me.Scale(addSize)

End Sub

And this quite rightly reduces everything down to half of what it was.
However I am wanting to put this in the Form Resize event, and I tried this
rather clumsy approach:

Private Sub Form2_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize

Static OldWidth As Integer
Static OldHeight As Integer
If OldWidth = 0 Then OldWidth = Me.Width
If OldHeight = 0 Then OldHeight = Me.Height

Dim ScaleX As Decimal = Me.Width / OldWidth
Dim ScaleY As Decimal = Me.Height / OldHeightDim MyScale As New
SizeF(ScaleX, ScaleY)

Me.Scale(MyScale)

OldWidth = Me.Width
OldHeight = Me.Height

End Sub

The problem is that it suffers from re-entry. As soon as the form and
everything else is scaled, the Resize event is triggered again and so on.

How are we supposed to use this scale facility?

-Jerry
When resizing the form, you don't want to scale the form, itself -
just the form's controls. The Try/Catch is needed as during starup,
the static variables are not initialized until the first pass through
of the resize event:
Private Sub Form1_Resize(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles Me.Resize
Static OldWidth As Integer
Static OldHeight As Integer
Try
Dim ScaleX As Decimal = CDec(Me.Width / OldWidth)
Dim ScaleY As Decimal = CDec(Me.Height / OldHeight)
Dim MyScale As New SizeF(ScaleX, ScaleY)

For Each ctl As Control In Me.Controls
ctl.Scale(MyScale)
Next
Catch
Finally
OldWidth = Me.Width
OldHeight = Me.Height
End Try

You also can selectively scale only specfic controls in the For Each
loop.
Gene
Jul 17 '06 #4

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

Similar topics

1
by: chaos | last post by:
Hello, i have problems using sqlj in the following environment. I use type 4 driver com.ibm.db2.jcc.DB2Driver and connect succesful to 8.1. db2-Database(DRDA)(Informational tokens are "DB2...
2
by: Paul Duncan | last post by:
diggityduncs (Programmer) Nov 13, 2003 Hello, I'm tring to use a win32/api dll in c# The vendor I received the dll from doesn't know anything about .net I received two files ACGAPI.DLL +
2
by: Tod Birdsall | last post by:
Hi All, I am trying to secure non-ASP.NET files (i.e. .html, .pdf) in an application running on IIS 6.0, Win2K3 using the .NET Framework 2.0. What has worked in the past using .NET Framework...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
1
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
0
by: CompuBoy | last post by:
I have a problem on retrieving information from web browser component; because I am using .Net framework 2.0 and it cannot use AxSHDocVw function. Currently I am using Microsoft.mshtml, how can I...
1
by: ampravin | last post by:
Hi all, I am using Atlas framework and while my session time out, am getting an unknown alert. Is it possible to avoid this? If possible can any one help me out of this? Thanks in advance.
8
by: _spitFIRE | last post by:
Is it possible to run a SMTP server that sends mail to recipients using standard libraries, without using twisted framework, and also without using any relay server?
3
by: Brett R. Wesoloski | last post by:
I am having problems using HttpContext.Current.Request.Url.Host. I have some code that does this... if (HttpContext.Current != null) { subdomain = HttpContext.Current.Request.Url.Host; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.