lennonbradbury

October 21, 2010

Automatically change the control once and for all so that the size of VB

Filed under: Uncategorized

- When the form is resized, how to dynamically change the size of the control of many VB programmers headaches. Some people set Resizable form the size of the control but do not change; some people are under the control of absolute position and window size with addition and subtraction approach to re-position the control and change the size, this approach is relatively more complicated and can not be reused; Of course, some people are limited not to change the window altogether. Is there a simple way? The answer is yes, here are a permanent solution, source code is as follows:
Option Explicit
Private FormOldWidth As Long
`Save the form of the original width
Private FormOldHeight As Long
`Save the form of the original height

`In the call to call this function before ResizeForm
Public Sub ResizeInit (FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & “” & Obj.Top & “”
& Obj.Width & “” & Obj.Height & “”
Next Obj
On Error GoTo 0
End Sub

`Change in proportion to the size of each component within the form,
Call before the call ReSizeForm ReSizeInit function
Public Sub ResizeForm (FormName As Form)
Dim Pos (4) As Double
Dim I As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double

ScaleX = FormName.ScaleWidth / FormOldWidth
`Save the form width scaling
ScaleY = FormName.ScaleHeight / FormOldHeight
Save the form `a high degree of scaling
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For I = 0 To 4
`Read the original location and size of the control

TempPos = InStr (StartPos,
Obj.Tag, “”, vbTextCompare)
If TempPos> 0 Then
Pos (I) = Mid (Obj.Tag,
StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos (I) = 0
End If
`According to the original location and form control to change the size of the
The proportion of the controls reposition and resize
Obj.Move Pos (0) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news : 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleX, Pos (1)
backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only ScaleY, Pos (2) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleX, Pos (3) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news : 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleY
Next I
Next Obj
On Error GoTo 0
End Sub

Private Sub Form_Load ()
Call ResizeInit (Me) `the procedure must be added into
End Sub

Private Sub Form_Resize ()
Call ResizeForm (Me) `to ensure that change control and changes the form
End Sub

—- In this case are given two functions: ResizeInit and ResizeForm, before calling ResizeForm must call ResizeInit. You can by copying the program code in the form, and then adding any controls on the form where you can test - when the form is resized, how to dynamically change the size of the control of many VB programmers headaches. Some people set Resizable form the size of the control but do not change; some people are under the control of absolute position and window size with addition and subtraction approach to re-position the control and change the size, this approach is relatively more complicated and can not be reused; Of course, some people are limited not to change the window altogether. Is there a simple way? The answer is yes, here are a permanent solution, source code is as follows:
Option Explicit
Private FormOldWidth As Long
`Save the form of the original width
Private FormOldHeight As Long
`Save the form of the original height

`In the call to call this function before ResizeForm
Public Sub ResizeInit (FormName As Form)
Dim Obj As Control
FormOldWidth = FormName.ScaleWidth
FormOldHeight = FormName.ScaleHeight
On Error Resume Next
For Each Obj In FormName
Obj.Tag = Obj.Left & “” & Obj.Top & “”
& Obj.Width & “” & Obj.Height & “”
Next Obj
On Error GoTo 0
End Sub

`Change in proportion to the size of each component within the form,
Call before the call ReSizeForm ReSizeInit function
Public Sub ResizeForm (FormName As Form)
Dim Pos (4) As Double
Dim I As Long, TempPos As Long, StartPos As Long
Dim Obj As Control
Dim ScaleX As Double, ScaleY As Double

ScaleX = FormName.ScaleWidth / FormOldWidth
`Save the form width scaling
ScaleY = FormName.ScaleHeight / FormOldHeight
Save the form `a high degree of scaling
On Error Resume Next
For Each Obj In FormName
StartPos = 1
For I = 0 To 4
`Read the original location and size of the control

TempPos = InStr (StartPos,
Obj.Tag, “”, vbTextCompare)
If TempPos> 0 Then
Pos (I) = Mid (Obj.Tag,
StartPos, TempPos - StartPos)
StartPos = TempPos + 1
Else
Pos (I) = 0
End If
`According to the original location and form control to change the size of the
The ratio of the re-orientation and change the size of the control
Obj.Move Pos (0) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news : 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleX, Pos (1)
backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar. gz xml2dict-read-only ScaleY, Pos (2) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news: 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleX, Pos (3) backup bin bin_old conf config crawler.tar.gz crawler_bin.tar.gz data eshow eshow_sitemap.html generate.sh google.html google.html.md5 log maint news: 10 news: 11 news: 12 news: 13 news: 14 news: 15 news: 16 news: 17 news: 18 news: 2 news: 3 news: 4 news: 5 news: 6 news : 7 news: 8 news: 9 outboundLinksMgr.sql seeds sitemap.html svn tasks tmp xml2dict-2008.6-tar.gz xml2dict-read-only ScaleY
Next I
Next Obj
On Error GoTo 0
End Sub

Private Sub Form_Load ()
Call ResizeInit (Me) `the procedure must be added into
End Sub

Private Sub Form_Resize ()
Call ResizeForm (Me) `to ensure that change control and changes the form
End Sub

—- In this case are given two functions: ResizeInit and ResizeForm, before calling ResizeForm must call ResizeInit. You can by copying the program code in the form, and then adding any controls on the form where you can test

Recommended links:

Recorded with the popular film of your wonderful life

MBS 2007 fiscal YEAR have something to say

Illustrator and Photoshop to create gorgeous wallpaper patterns

SA118 Chinese TRANSLATION 2

Easy to use E-Mail List MANAGEMENT

Next-generation console out of stock, 2007 to continue

Baidu cheating, Universally condemned?

comparison Project MANAGEMENT

Operation of supermarkets to dealers Suggestions

Xi'an: A6 Experiential Training Shock City

How To Convert And Import Mts M2ts Files To Imovie

XviD to MP4

MPEG to 3GP

Motorola will split into two independent Companies

AVI to MPEG4

Comments »

The URI to TrackBack this entry is: http://bradburylennon39.blogsome.com/2010/10/21/automatically-change-the-control-once-and-for-all-so-that-the-size-of-vb/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.






















Get free blog up and running in minutes with Blogsome
Theme designed by Hadley Wickham