473,394 Members | 1,671 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,394 software developers and data experts.

zooming (scaling) a window using a trackbar

I'd like to allow the user to zoom a window using a trackbar, say from 80%
to 120% the size of the original window. I'm trying to do this with the
following code, but it fails pretty miserably:
(from the form)

Dim per As Decimal

per = CDec(zoomit.Value)

setzoom(Me, Me.Font, per) ' per is the current value of the trackbar as a
decimal

----------------------

Public Sub setzoom(ByRef senderform As Form, ByRef senderfont As Font, ByVal
per As Decimal)

per = per * 0.01

Dim iwidth As Int32 = SystemInformation.PrimaryMonitorSize.Width

Dim sizeold As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

senderfont = New Font(senderfont.FontFamily, senderfont.Size * iwidth /
1280)

' 1280 is my current environment width

Dim sizenew As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

sizenew.Width = sizenew.Width * per

sizenew.Height = sizenew.Height * per

senderform.Scale(sizenew.Width / sizeold.Width, sizenew.Height /
sizeold.Height)

End Sub

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #1
4 3806
Cor
Hi Bernie,

Have a look of this code, I did want to send it to you yesterday, but I did
not really test it.
The idea of this is that it changes recursevly the controls in a child
control.

I first made it with height and width, but when I saw your solution with
scale I changed it.
But I think that with height and width it is even nicer.

Cor

\\\To test
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim mescale As Single = 1.1
doScale.scale(Me, mescale)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim mescale As Single = 1 / 1.1
doScale.scale(Me, mescale)
End Sub
End Class
///
\\\
Public Class doScale
Public Shared Sub scale(ByVal ctr As Control, ByVal mescale As Single)
ctr.Width = CInt(ctr.Width * mescale)
ctr.Height = CInt(ctr.Height * mescale)
ctr.Scale(mescale)
Dim Berny As New doCtr(ctr, mescale)
End Sub
Private Class doCtr
Public Sub New(ByVal parentCtr As Control, ByVal mescale As Single)
Dim ctr As Control
For Each ctr In parentCtr.Controls
ctr.Scale(mescale)
Dim newdoCtr As _
New doCtr(ctr, mescale)
Next
End Sub
End Class
///

Nov 20 '05 #2
Bernie,
I see two problems, well one problem and one potential problem.

I believe you want to only scale the font:
senderfont = New Font(senderfont.FontFamily, senderfont.Size * iwidth /
1280 * per)
Also while attempting to get it to work I would remove the "iwidth /1280"
logic, once your zooming works, I would then attempt at incorporating that
back in...
Now the "bigger" problem, which I currently don't have a solution.

After the first call to SetZoom, you are scaling the scaled form. Somehow
each time you call SetZoom, you need to "reset" the form to the original
size, then apply the new scale. Or maybe only zoom original values (not
current values)...

If you don't have it, you may want to review the section in Petzold's book
that explains how the code I gave you works...

Hope this helps
Jay

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... I'd like to allow the user to zoom a window using a trackbar, say from 80%
to 120% the size of the original window. I'm trying to do this with the
following code, but it fails pretty miserably:
(from the form)

Dim per As Decimal

per = CDec(zoomit.Value)

setzoom(Me, Me.Font, per) ' per is the current value of the trackbar as a
decimal

----------------------

Public Sub setzoom(ByRef senderform As Form, ByRef senderfont As Font, ByVal per As Decimal)

per = per * 0.01

Dim iwidth As Int32 = SystemInformation.PrimaryMonitorSize.Width

Dim sizeold As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

senderfont = New Font(senderfont.FontFamily, senderfont.Size * iwidth /
1280)

' 1280 is my current environment width

Dim sizenew As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

sizenew.Width = sizenew.Width * per

sizenew.Height = sizenew.Height * per

senderform.Scale(sizenew.Width / sizeold.Width, sizenew.Height /
sizeold.Height)

End Sub

Thanks for any help.

Bernie Yaeger

Nov 20 '05 #3
Hi Jay,

Actually, the code you gave me yesterday works splendidly when I scale based
purely on the current resolution of a given monitor. That's because it
scales only once.

I now want to extend that logic to a trackbar scale, but I now realize that
once I scale I don't have the original form to rescale - it's now another
size, not the resolution size. So, yes, either I maintain the original size
somewhere (could be done) or I scale the current scale value (eg, now it's
at .95 so multiply everything appropriately, etc).

As always, you've helped to put me on the right track. If you have any
further thoughts, please send them to me.

Thanks again,

Bernie

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uv**************@tk2msftngp13.phx.gbl...
Bernie,
I see two problems, well one problem and one potential problem.

I believe you want to only scale the font:
senderfont = New Font(senderfont.FontFamily, senderfont.Size * iwidth /
1280 * per)


Also while attempting to get it to work I would remove the "iwidth /1280"
logic, once your zooming works, I would then attempt at incorporating that
back in...
Now the "bigger" problem, which I currently don't have a solution.

After the first call to SetZoom, you are scaling the scaled form. Somehow
each time you call SetZoom, you need to "reset" the form to the original
size, then apply the new scale. Or maybe only zoom original values (not
current values)...

If you don't have it, you may want to review the section in Petzold's book
that explains how the code I gave you works...

Hope this helps
Jay

"Bernie Yaeger" <be*****@cherwellinc.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I'd like to allow the user to zoom a window using a trackbar, say from 80% to 120% the size of the original window. I'm trying to do this with the
following code, but it fails pretty miserably:
(from the form)

Dim per As Decimal

per = CDec(zoomit.Value)

setzoom(Me, Me.Font, per) ' per is the current value of the trackbar as a decimal

----------------------

Public Sub setzoom(ByRef senderform As Form, ByRef senderfont As Font,

ByVal
per As Decimal)

per = per * 0.01

Dim iwidth As Int32 = SystemInformation.PrimaryMonitorSize.Width

Dim sizeold As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

senderfont = New Font(senderfont.FontFamily, senderfont.Size * iwidth /
1280)

' 1280 is my current environment width

Dim sizenew As SizeF =
System.Windows.Forms.Form.GetAutoScaleSize(senderf ont)

sizenew.Width = sizenew.Width * per

sizenew.Height = sizenew.Height * per

senderform.Scale(sizenew.Width / sizeold.Width, sizenew.Height /
sizeold.Height)

End Sub

Thanks for any help.

Bernie Yaeger


Nov 20 '05 #4
Hi Cor,

Thanks for your help. Yes, my problem is that I have to scale recursively
and my current code does not do that, so that is where I think I'm failing.

I will review your code, which has already given me some ideas.

Tx again for all your help,

Bernie

"Cor" <no*@non.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
Hi Bernie,

Have a look of this code, I did want to send it to you yesterday, but I did not really test it.
The idea of this is that it changes recursevly the controls in a child
control.

I first made it with height and width, but when I saw your solution with
scale I changed it.
But I think that with height and width it is even nicer.

Cor

\\\To test
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim mescale As Single = 1.1
doScale.scale(Me, mescale)
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim mescale As Single = 1 / 1.1
doScale.scale(Me, mescale)
End Sub
End Class
///
\\\
Public Class doScale
Public Shared Sub scale(ByVal ctr As Control, ByVal mescale As Single)
ctr.Width = CInt(ctr.Width * mescale)
ctr.Height = CInt(ctr.Height * mescale)
ctr.Scale(mescale)
Dim Berny As New doCtr(ctr, mescale)
End Sub
Private Class doCtr
Public Sub New(ByVal parentCtr As Control, ByVal mescale As Single) Dim ctr As Control
For Each ctr In parentCtr.Controls
ctr.Scale(mescale)
Dim newdoCtr As _
New doCtr(ctr, mescale)
Next
End Sub
End Class
///

Nov 20 '05 #5

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

Similar topics

1
by: Ron Crump | last post by:
Hi, I have a small javascript (scalegr.js) that re-scales a sequence of images on a page to be less than the frame width, thus: function scalegr(a) { var imgs = document.images; var fw =...
1
by: Pls Help | last post by:
Hi, I've encountered a weird TrackBar issue, it seems to hang completely when the TrackBar.Maximum is set to certain large values.. what's going on? Have tried this on a few different 2000/XP...
2
by: juergen | last post by:
how to design a trackbar/slider with diff. look??? For my win-application I need a trackbar/slider, that doesnt look like the control-trackbar offered by vb.net. ; e.g. something like the slider...
1
by: ACaunter | last post by:
Hi all, I really am in desperate need of some code that can zoom in on an image. I don't want to just make the whole image bigger, i want to have a box ( <p> tag ) that is the zooming window......
0
by: RuffAroundTheEdges | last post by:
I'm trying to get an aspx page to display a TrackBar. There is no TrackBar in the System.Web.UI.WebControls. Is there a TrackBar like control in System.Web.UI.WebControls? If not, is there a way to...
3
by: Sakharam Phapale | last post by:
Hi All, How to set the background image for TrackBar control. Since BackgroundImage property doesn't visible in design mode, I tried doing it in run time as follows, ...
1
by: Kris | last post by:
Hi. We are developing an application in VS2005 in C#, .NET, that has lots of tabs. On one of these tabs, there is a horizontal trackbar. However, we are unable to set the background color of the...
1
by: John | last post by:
I have an app where I want to show an icon in a large PictureBox. I've set the SizeMode to Zoom but the icon image is extremely fuzzy because the scaling up also anti-aliases. Is there a way to...
2
by: therefor | last post by:
I have the following in Flash 8 BriefLook_mc.btnStudentLife_mc.onRelease = function():Void { this.createEmptyMovieClip("craveLoader_mc", this.getNextHighestDepth()); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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...
0
Oralloy
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,...

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.