|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problems using Me.Scale in Framework 2.0scaling 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 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 Show quoteHide quote "Jerry Spence1" <jerry.spe***@somewhere.com> wrote in message news:44ba8708$0$22086$ed2619ec@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 > > 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 Show quoteHide quote "Samuel Shulman" <samuel.shul***@ntlworld.com> wrote in message news:u9P8WvRqGHA.4424@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" <jerry.spe***@somewhere.com> wrote in message > news:44ba8708$0$22086$ed2619ec@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 >> >> > > On Sun, 16 Jul 2006 19:35:50 +0100, "Jerry Spence1"
<jerry.spe***@somewhere.com> wrote: Show quoteHide quote >A very useful feature was added in 2.0 of .NET framework which was the When resizing the form, you don't want to scale the form, itself ->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 > 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
AS400 - Ado.Net from Vb.Net Slow Query Times
Can I make my Form visible during a debug session? Database Connection Problem. Please Help Is this a bug: 2.2 - 0.4 = 1.8 but 1.2 - 0.4 = 0.8000001 ? object reference not set to an instance of an object error enforce event calling on inherited classes Multiple executescalar() Commenting Out Controls In HTML View Convert Array of Objects to Generics List? multiple color + font selections in a richtextbox control |
|||||||||||||||||||||||