472,352 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 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 3709
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...
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...
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...
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...
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...
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...
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....
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...
2
by: therefor | last post by:
I have the following in Flash 8 BriefLook_mc.btnStudentLife_mc.onRelease = function():Void { this.createEmptyMovieClip("craveLoader_mc",...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.