|
Hello
I have the same problem , i also have tabs
Have you being able to adapt the code and would you be able to sent it?
Thank you
best regards
Patrick
|
|
|
|
|
I modified the code to cope with a DataGridView, which is essentially a complex container control.
It should be quite straightforward to do the same for Tab controls.
|
|
|
|
|
Actually, i'm working in Vc++ so please convert code into Vc+
|
|
|
|
|
That Code Works Fine If Control Have Dock = None Else Its Not Working
|
|
|
|
|
Hi
I use resizer class in my app
and its work fine except for NumericUpDown control
that refuse to resize no for its text and no for its body( its body width changed but not its height)
and another question if I want to keep form width/height ratio
when resizing what change I need to do in the resizer class.
do some one have a solution for this.
Thank you.
Hi
l found that this class is more accurate
Resize form relatively
'modify size of controls on form
'change location of controls dynamically as width or height
'changes on the form
'class designed by MathLover, free to be used by anybody
'if you need explanations about anything
'please feel free to contact me at
' mathlover47@hotmail.com
Public Class Relative
Private OriginalWidthForm, OriginalHeightForm As UInt32
Private NewWidthForm, NewHeightForm As UInt32
Private ControlSizeLocation(,) As Point
Private SizeLocationContainer(,,) As Point
Private fontContainer(,) As UInt16
Private f1 As Form
Public Sub New(ByRef f12 As Form)
' j here reflects the number of containers inside form
Dim i,a1 As Integer
Static j As UInt32 = 0
OriginalWidthForm = f12.Width
OriginalHeightForm = f12.Height
f1 = f12
ReDim ControlSizeLocation(f1.Controls.Count, 1)
ReDim Preserve SizeLocationContainer(120, 1, 120)
ReDim fontContainer(121, 120)
For i = 0 To f1.Controls.Count - 1
ControlSizeLocation(i, 0) = New Point(f1.Controls(i).Size.Width, f1.Controls(i).Size.Height)
ControlSizeLocation(i, 1) = New Point(f1.Controls(i).Location.X, f1.Controls(i).Location.Y)
fontContainer(i, 0) = f1.Controls(i).Font.Size
If IsContainer(f1.Controls(i)) Then
For a1 = 0 To f1.Controls(i).Controls.Count - 1
SizeLocationContainer(a1, 0, j) = New Point(f1.Controls(i).Controls(a1).Size.Width, f1.Controls(i).Controls(a1).Size.Height)
SizeLocationContainer(a1, 1, j) = New Point(f1.Controls(i).Controls(a1).Location.X, f1.Controls(i).Controls(a1).Location.Y)
fontContainer(a1, j + 1) = f1.Controls(i).Controls(a1).Font.Size
Next
j += 1
End If
Next
AddHandler f1.Resize, AddressOf NewFormResizer
End Sub
Private Sub NewFormResizer()
NewWidthForm = f1.Width
NewHeightForm = f1.Height
ModifyControls()
End Sub
Private Sub ModifyControls()
Dim ControlsCount As UInt16 = f1.Controls.Count - 1
Dim n As UInt16 = 0
Dim i As Integer
For i = 0 To ControlsCount
f1.Controls(i).Location = ReLocater(ControlSizeLocation(i, 1))
f1.Controls(i).Size = ReSizer(ControlSizeLocation(i, 0))
f1.Controls(i).Font = FontSize(f1.Controls(i).Font.Name, fontContainer(i, 0), ControlSizeLocation(i, 1), f1.Controls(i).Location)
'ControlArray(i) = f1.Controls(i)
'f1.Controls.Remove(f1.Controls(0))
If IsContainer(f1.Controls(i)) Then
For m As UInt16 = 0 To f1.Controls(i).Controls.Count - 1
f1.Controls(i).Controls(m).Location = ReLocater(CType(SizeLocationContainer(m, 1, n), Point))
f1.Controls(i).Controls(m).Size = ReSizer(CType(SizeLocationContainer(m, 0, n), Point))
f1.Controls(i).Controls(m).Font = FontSize(f1.Controls(i).Controls(m).Font.Name, fontContainer(m, n + 1), SizeLocationContainer(m, 1, n), f1.Controls(i).Controls(m).Location)
Next
n += 1
End If
Next
End Sub
Private Function ReLocater(ByVal p As Point) As Point
Dim OldLocationX As UInt32 = p.X
Dim OldLocationY As UInt32 = p.Y
Dim NewLocationX As UInt32 = CInt((OldLocationX * NewWidthForm) / OriginalWidthForm)
Dim NewLocationY As UInt32 = CInt((OldLocationY * NewHeightForm) / OriginalHeightForm)
ReLocater = New Point(NewLocationX, NewLocationY)
End Function
Private Function ReSizer(ByVal p As Point) As Point
Dim OldWidthControl As UInt32 = p.X
Dim OldHeightControl As UInt32 = p.Y
Dim NewWidthControl As UInt32 = CInt((OldWidthControl * NewWidthForm) / OriginalWidthForm)
Dim NewHeightControl As UInt32 = CInt((OldHeightControl * NewHeightForm) / OriginalHeightForm)
Return New Point(NewWidthControl, NewHeightControl)
End Function
Private Function IsContainer(ByVal con As Control) As Boolean
If con.GetType.Name = "TableLayoutPanel" Or _
con.GetType.Name = "GroupBox" Or _
con.GetType.Name = "Panel" Or _
con.GetType.Name = "FlowLayoutPanel" Or _
con.GetType.Name = "SplitContainer" Or _
con.GetType.Name = "TabControl" Then
Return True
End If
Return False
End Function
Private Function FontSize(ByVal FontName As String, ByVal OrginalFontSize As UInt16, ByVal OldLoc As Point, ByVal NewLoc As Point) As Font
Dim ns As UInt16
ns = 0.75 * OrginalFontSize * NewLoc.X / OldLoc.X
Dim f1 As New Font(FontName, ns)
Return f1
End Function
End Class
modified 19-Mar-20 4:54am.
|
|
|
|
|
Nicely Done. However it makes my fonts smaller than originally specified and moves alignment. Could this be due to Autosizemode being set to dpi rather than font?
|
|
|
|
|
It work for me
Thank you so much
|
|
|
|
|
Excellent class for resizing the control.
I have a small issue, i am having a line and rectangle shape control in my form and these two are not getting resized.
Please guide me how to solve it.
Thanks in advance.
|
|
|
|
|
Hi Member 10974085
Two things to you.
1. The resizer class work ok for
me except the buttons are
Somewhat distorted.
2. I want to do a small change
and for that I need your help.
I want to keep height/width
Of original form ratio to be fix
Manly after form dragging
The form height staying as is
And the width will be changed
So to keep the fix ratio.
Thank you in advanced
This is my form
<global.microsoft.visualbasic.compilerservices.designergenerated()> _
Partial Class ehRegExForm
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<system.diagnostics.debuggernonusercode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<system.diagnostics.debuggerstepthrough()> _
Private Sub InitializeComponent()
Me.RETextBox = New System.Windows.Forms.TextBox()
Me.ReplaceSplitTextBox = New System.Windows.Forms.TextBox()
Me.InputTextBox = New System.Windows.Forms.TextBox()
Me.RELabel = New System.Windows.Forms.Label()
Me.ReplceSplitLabel = New System.Windows.Forms.Label()
Me.InputLabel = New System.Windows.Forms.Label()
Me.OutputLabel = New System.Windows.Forms.Label()
Me.OutputTextBox = New System.Windows.Forms.TextBox()
Me.ShowReTextBox = New System.Windows.Forms.TextBox()
Me.MatchButton = New System.Windows.Forms.Button()
Me.ReplaceButton = New System.Windows.Forms.Button()
Me.SplitButton = New System.Windows.Forms.Button()
Me.ClearButton = New System.Windows.Forms.Button()
Me.CloseButton = New System.Windows.Forms.Button()
Me.IgnoreCaseCheckBox = New System.Windows.Forms.CheckBox()
Me.SingleLineCheckBox = New System.Windows.Forms.CheckBox()
Me.MultilineCheckBox = New System.Windows.Forms.CheckBox()
Me.ExplicitCaptureCheckBox = New System.Windows.Forms.CheckBox()
Me.RightToLeftCheckBox = New System.Windows.Forms.CheckBox()
Me.OpenAllButton = New System.Windows.Forms.Button()
Me.SaveAllButton = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'RETextBox
'
Me.RETextBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RETextBox.Location = New System.Drawing.Point(23, 90)
Me.RETextBox.Multiline = True
Me.RETextBox.Name = "RETextBox"
Me.RETextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.RETextBox.Size = New System.Drawing.Size(520, 250)
Me.RETextBox.TabIndex = 0
Me.RETextBox.WordWrap = False
'
'ReplaceSplitTextBox
'
Me.ReplaceSplitTextBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ReplaceSplitTextBox.Location = New System.Drawing.Point(603, 90)
Me.ReplaceSplitTextBox.Multiline = True
Me.ReplaceSplitTextBox.Name = "ReplaceSplitTextBox"
Me.ReplaceSplitTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.ReplaceSplitTextBox.Size = New System.Drawing.Size(520, 250)
Me.ReplaceSplitTextBox.TabIndex = 1
Me.ReplaceSplitTextBox.WordWrap = False
'
'InputTextBox
'
Me.InputTextBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.InputTextBox.Location = New System.Drawing.Point(23, 390)
Me.InputTextBox.Multiline = True
Me.InputTextBox.Name = "InputTextBox"
Me.InputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.InputTextBox.Size = New System.Drawing.Size(1100, 250)
Me.InputTextBox.TabIndex = 2
Me.InputTextBox.WordWrap = False
'
'RELabel
'
'Me.RELabel.AutoSize = False
Me.RELabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RELabel.Location = New System.Drawing.Point(154, 59)
Me.RELabel.Name = "RELabel"
Me.RELabel.Size = New System.Drawing.Size(258, 25)
Me.RELabel.TabIndex = 4
Me.RELabel.Text = "Regular Expressions Pattern"
Me.RELabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'ReplceSplitLabel
'
'Me.ReplceSplitLabel.AutoSize = False
Me.ReplceSplitLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ReplceSplitLabel.Location = New System.Drawing.Point(772, 59)
Me.ReplceSplitLabel.Name = "ReplceSplitLabel"
Me.ReplceSplitLabel.Size = New System.Drawing.Size(182, 25)
Me.ReplceSplitLabel.TabIndex = 5
Me.ReplceSplitLabel.Text = "Replacement String"
Me.ReplceSplitLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'InputLabel
'
'Me.InputLabel.AutoSize = False
Me.InputLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.InputLabel.Location = New System.Drawing.Point(524, 353)
Me.InputLabel.Name = "InputLabel"
Me.InputLabel.Size = New System.Drawing.Size(99, 25)
Me.InputLabel.TabIndex = 6
Me.InputLabel.Text = "Input Text"
Me.InputLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'OutputLabel
'
'Me.OutputLabel.AutoSize = False
Me.OutputLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.OutputLabel.ForeColor = System.Drawing.Color.Green
Me.OutputLabel.Location = New System.Drawing.Point(516, 653)
Me.OutputLabel.Name = "OutputLabel"
Me.OutputLabel.Size = New System.Drawing.Size(115, 25)
Me.OutputLabel.TabIndex = 9
Me.OutputLabel.Text = "Output Text"
Me.OutputLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'OutputTextBox
'
Me.OutputTextBox.BackColor = System.Drawing.Color.White
Me.OutputTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.OutputTextBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.OutputTextBox.ForeColor = System.Drawing.Color.Green
Me.OutputTextBox.Location = New System.Drawing.Point(23, 691)
Me.OutputTextBox.Multiline = True
Me.OutputTextBox.Name = "OutputTextBox"
Me.OutputTextBox.ReadOnly = True
Me.OutputTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.OutputTextBox.Size = New System.Drawing.Size(1100, 250)
Me.OutputTextBox.TabIndex = 8
Me.OutputTextBox.WordWrap = False
'
'ShowReTextBox
'
Me.ShowReTextBox.BackColor = System.Drawing.Color.White
Me.ShowReTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.ShowReTextBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ShowReTextBox.ForeColor = System.Drawing.Color.Blue
Me.ShowReTextBox.Location = New System.Drawing.Point(23, 12)
Me.ShowReTextBox.Name = "ShowReTextBox"
Me.ShowReTextBox.ReadOnly = True
Me.ShowReTextBox.Size = New System.Drawing.Size(1254, 23)
Me.ShowReTextBox.TabIndex = 12
'
'MatchButton
'
Me.MatchButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.MatchButton.Location = New System.Drawing.Point(1138, 90)
Me.MatchButton.Name = "MatchButton"
Me.MatchButton.Size = New System.Drawing.Size(131, 35)
Me.MatchButton.TabIndex = 13
Me.MatchButton.Text = "Matches"
Me.MatchButton.UseVisualStyleBackColor = True
'
'ReplaceButton
'
Me.ReplaceButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ReplaceButton.Location = New System.Drawing.Point(1138, 141)
Me.ReplaceButton.Name = "ReplaceButton"
Me.ReplaceButton.Size = New System.Drawing.Size(131, 35)
Me.ReplaceButton.TabIndex = 14
Me.ReplaceButton.Text = "Replace"
Me.ReplaceButton.UseVisualStyleBackColor = True
'
'SplitButton
'
Me.SplitButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.SplitButton.Location = New System.Drawing.Point(1138, 192)
Me.SplitButton.Name = "SplitButton"
Me.SplitButton.Size = New System.Drawing.Size(131, 35)
Me.SplitButton.TabIndex = 15
Me.SplitButton.Text = "Split"
Me.SplitButton.UseVisualStyleBackColor = True
'
'ClearButton
'
Me.ClearButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ClearButton.Location = New System.Drawing.Point(1138, 244)
Me.ClearButton.Name = "ClearButton"
Me.ClearButton.Size = New System.Drawing.Size(131, 35)
Me.ClearButton.TabIndex = 16
Me.ClearButton.Text = "Clear"
Me.ClearButton.UseVisualStyleBackColor = True
'
'CloseButton
'
Me.CloseButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.CloseButton.Location = New System.Drawing.Point(1138, 886)
Me.CloseButton.Name = "CloseButton"
Me.CloseButton.Size = New System.Drawing.Size(130, 35)
Me.CloseButton.TabIndex = 17
Me.CloseButton.Text = "Close"
Me.CloseButton.UseVisualStyleBackColor = True
'
'IgnoreCaseCheckBox
'
'Me.IgnoreCaseCheckBox.AutoSize = True
Me.IgnoreCaseCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.IgnoreCaseCheckBox.Location = New System.Drawing.Point(1138, 329)
Me.IgnoreCaseCheckBox.Name = "IgnoreCaseCheckBox"
Me.IgnoreCaseCheckBox.Size = New System.Drawing.Size(141, 29)
Me.IgnoreCaseCheckBox.TabIndex = 18
Me.IgnoreCaseCheckBox.Text = "Ignore Case"
Me.IgnoreCaseCheckBox.UseVisualStyleBackColor = True
'
'SingleLineCheckBox
'
'Me.SingleLineCheckBox.AutoSize = True
Me.SingleLineCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.SingleLineCheckBox.Location = New System.Drawing.Point(1138, 399)
Me.SingleLineCheckBox.Name = "SingleLineCheckBox"
Me.SingleLineCheckBox.Size = New System.Drawing.Size(115, 29)
Me.SingleLineCheckBox.TabIndex = 19
Me.SingleLineCheckBox.Text = "SigleLine"
Me.SingleLineCheckBox.UseVisualStyleBackColor = True
'
'MultilineCheckBox
'
'Me.MultilineCheckBox.AutoSize = True
Me.MultilineCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.MultilineCheckBox.Location = New System.Drawing.Point(1138, 364)
Me.MultilineCheckBox.Name = "MultilineCheckBox"
Me.MultilineCheckBox.Size = New System.Drawing.Size(112, 29)
Me.MultilineCheckBox.TabIndex = 20
Me.MultilineCheckBox.Text = "MultiLine"
Me.MultilineCheckBox.UseVisualStyleBackColor = True
'
'ExplicitCaptureCheckBox
'
'Me.ExplicitCaptureCheckBox.AutoSize = True
Me.ExplicitCaptureCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ExplicitCaptureCheckBox.Location = New System.Drawing.Point(1138, 434)
Me.ExplicitCaptureCheckBox.Name = "ExplicitCaptureCheckBox"
Me.ExplicitCaptureCheckBox.Size = New System.Drawing.Size(104, 54)
Me.ExplicitCaptureCheckBox.TabIndex = 21
Me.ExplicitCaptureCheckBox.Text = "Explicit" & Global.Microsoft.VisualBasic.ChrW(13) & Global.Microsoft.VisualBasic.ChrW(10) & "Capture"
Me.ExplicitCaptureCheckBox.UseVisualStyleBackColor = True
'
'RightToLeftCheckBox
'
'Me.RightToLeftCheckBox.AutoSize = True
Me.RightToLeftCheckBox.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.RightToLeftCheckBox.Location = New System.Drawing.Point(1138, 493)
Me.RightToLeftCheckBox.Name = "RightToLeftCheckBox"
Me.RightToLeftCheckBox.Size = New System.Drawing.Size(134, 29)
Me.RightToLeftCheckBox.TabIndex = 23
Me.RightToLeftCheckBox.Text = "RightToLeft"
Me.RightToLeftCheckBox.UseVisualStyleBackColor = True
'
'OpenAllButton
'
Me.OpenAllButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.OpenAllButton.Location = New System.Drawing.Point(1138, 548)
Me.OpenAllButton.Name = "OpenAllButton"
Me.OpenAllButton.Size = New System.Drawing.Size(131, 39)
Me.OpenAllButton.TabIndex = 25
Me.OpenAllButton.Text = "Open"
Me.OpenAllButton.UseVisualStyleBackColor = True
'
'SaveAllButton
'
Me.SaveAllButton.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.SaveAllButton.Location = New System.Drawing.Point(1138, 601)
Me.SaveAllButton.Name = "SaveAllButton"
Me.SaveAllButton.Size = New System.Drawing.Size(131, 39)
Me.SaveAllButton.TabIndex = 26
Me.SaveAllButton.Text = "Save"
Me.SaveAllButton.UseVisualStyleBackColor = True
'
'ehRegExForm
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.AutoScroll = True
'Me.AutoSize = True
Me.ClientSize = New System.Drawing.Size(1302, 953)
Me.Controls.Add(Me.SaveAllButton)
Me.Controls.Add(Me.OpenAllButton)
Me.Controls.Add(Me.RightToLeftCheckBox)
Me.Controls.Add(Me.ExplicitCaptureCheckBox)
Me.Controls.Add(Me.MultilineCheckBox)
Me.Controls.Add(Me.SingleLineCheckBox)
Me.Controls.Add(Me.IgnoreCaseCheckBox)
Me.Controls.Add(Me.CloseButton)
Me.Controls.Add(Me.ClearButton)
Me.Controls.Add(Me.SplitButton)
Me.Controls.Add(Me.ReplaceButton)
Me.Controls.Add(Me.MatchButton)
Me.Controls.Add(Me.ShowReTextBox)
Me.Controls.Add(Me.OutputLabel)
Me.Controls.Add(Me.OutputTextBox)
Me.Controls.Add(Me.InputLabel)
Me.Controls.Add(Me.ReplceSplitLabel)
Me.Controls.Add(Me.RELabel)
Me.Controls.Add(Me.InputTextBox)
Me.Controls.Add(Me.ReplaceSplitTextBox)
Me.Controls.Add(Me.RETextBox)
Me.HelpButton = True
'Me.MaximumSize = New System.Drawing.Size(1320, 1000)
'Me.MinimumSize = New System.Drawing.Size(1320, 1000)
Me.Name = "ehRegExForm"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "ehRegExTester : Programed by Haviv Elbaz Sep 2019"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents RETextBox As System.Windows.Forms.TextBox
Friend WithEvents ReplaceSplitTextBox As System.Windows.Forms.TextBox
Friend WithEvents InputTextBox As System.Windows.Forms.TextBox
Friend WithEvents RELabel As System.Windows.Forms.Label
Friend WithEvents ReplceSplitLabel As System.Windows.Forms.Label
Friend WithEvents InputLabel As System.Windows.Forms.Label
Friend WithEvents OutputLabel As System.Windows.Forms.Label
Friend WithEvents OutputTextBox As System.Windows.Forms.TextBox
Friend WithEvents ShowReTextBox As System.Windows.Forms.TextBox
Friend WithEvents MatchButton As System.Windows.Forms.Button
Friend WithEvents ReplaceButton As System.Windows.Forms.Button
Friend WithEvents SplitButton As System.Windows.Forms.Button
Friend WithEvents ClearButton As System.Windows.Forms.Button
Friend WithEvents CloseButton As System.Windows.Forms.Button
Friend WithEvents IgnoreCaseCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents SingleLineCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents MultilineCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents ExplicitCaptureCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents RightToLeftCheckBox As System.Windows.Forms.CheckBox
Friend WithEvents OpenAllButton As System.Windows.Forms.Button
Friend WithEvents SaveAllButton As System.Windows.Forms.Button
End Class
What I need to change so the resize
Be smooth.
Because the font don't proportional.
Thank you agay.
modified 21-Oct-19 23:39pm.
|
|
|
|
|
|
it was very useful to me, many thanks
|
|
|
|
|
Thanks For The Code It works like Charma
|
|
|
|
|
Brilliant solution. Excellent coding and code documentation. I copied and pasted the code and it worked perfectly.
|
|
|
|
|
Public Class BaseForm
Public rs As New FormResizer
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
rs.ResizeAllControls(Me, Me.Width, Me.Height)
End Sub
'Sub New()
' rs.FindAllControls(Me)
'End Sub
Public Class FormResizer
Private Structure ControlInfo
Public name As String
Public left As Integer
Public top As Integer
Public originalHeight As Integer
Public originalWidth As Integer
Public originalFontSize As Single
End Structure
Public originalHeight As Integer = -1
Public originalWidth As Integer = -1
Private ctrlDict As Dictionary(Of String, ControlInfo) = New Dictionary(Of String, ControlInfo)
Public Sub FindAllControls(thisCtrl As Control)
If originalHeight = -1 Then
originalHeight = thisCtrl.Height
End If
If originalWidth = -1 Then
originalWidth = thisCtrl.Width
End If
For Each ctl As Control In thisCtrl.Controls
Try
Dim c As New ControlInfo
c.name = ctl.Name
c.top = ctl.Top
c.left = ctl.Left
c.originalFontSize = ctl.Font.Size
c.originalHeight = ctl.Height
c.originalWidth = ctl.Width
ctrlDict.Add(c.name, c)
Catch ex As Exception
Debug.Print(ex.Message)
MsgBox(ex.Message)
End Try
If ctl.Controls.Count > 0 Then
FindAllControls(ctl)
End If
Next
End Sub
Public Sub ResizeAllControls(thisCtrl As Control, FormWidth As Integer, FormHeight As Integer)
If originalHeight = -1 Or originalWidth = -1 Then
Exit Sub
End If
Dim currentHeightFactor As Double = FormHeight / originalHeight
Dim currentWidthFactor As Double = FormWidth / originalWidth
For Each ctl As Control In thisCtrl.Controls
Try
Dim c As New ControlInfo
Dim ret As Boolean = False
Try
ret = ctrlDict.TryGetValue(ctl.Name, c)
If (ret) Then
'-- Position
ctl.Top = Int(c.top * currentHeightFactor)
ctl.Left = Int(c.left * currentWidthFactor)
ctl.Width = Int(c.originalWidth * currentWidthFactor)
ctl.Height = Int(c.originalHeight * currentHeightFactor)
'-- Font
Dim f As Font = ctl.Font
Dim fratio As Single = (currentHeightFactor + currentWidthFactor) / 2
ctl.Font = New Font(f.FontFamily, c.originalFontSize * fratio, f.Style)
End If
Catch
End Try
Catch ex As Exception
End Try
If ctl.Controls.Count > 0 Then
ResizeAllControls(ctl, FormWidth, FormHeight)
End If
Next
End Sub
End Class
End Class
|
|
|
|
|
|
Thank You for sharing this version.
A small unsharpness happens. At runtime I received the unfriendly message: "An item of same key has already been added".
After some investigation I've found the point that produced this error.
I modified the code in Your class inside the FindAllControls subroutine as following:
If Not ctrlDict.ContainsKey(c.name) Then
ctrlDict.Add(c.name, c)
End If
I hope there are no side effects now
|
|
|
|
|
Instead of calling FindAllControls() inside MyBase.Load >> Try to do it on the Form Initialization
Sub New()
rs.FindAllControls(Panel1)
End Sub
Otherwise, works great!
THANKS!
|
|
|
|
|
Working Great,,,Nice Tut sir,,,
|
|
|
|
|
|
worked great but two problems
slow when changing sizes|
the text and some component became bigger and didn`t maintain good position
|
|
|
|
|
Thank you for sharing - this is a most elegant solution for something that I have pondered for some time.
I have used the code on my project and the only control that does not resize is the DataGridView control. Are you able to suggest a fix for this control ?
|
|
|
|
|
You could put the DataGridView in a Container, dock it and set:
.Dock.Fill +
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
An for all the Columns set Autosizemode to Fill + MOdify the FillWeight Property of each Column to specify the actual width during rezising
This worked pretty well for me
|
|
|
|
|
|
is there a way to exclude one control from resizing using a custom class for a imageviewer and it comes with its on auto resizing. so is there a way for me to exclude just that?
should add the control does not have a auto resize option
|
|
|
|
|
In form's maximize mode, the font of combo-box items get correctly its dimensions (larger font). But, in minimize mode, the font remain large (not reduced).
The problem is solved by adding:
If (ctl.GetType() Is GetType(ComboBox)) Then
' Skip ComboBox
Else
ctl.Font = New Font(f.FontFamily, c.originalFontSize * fontRatio, f.Style)
End If
In ResizeAllControls Sub
Anyway, thank you very much for this great code, it saves me a lot of time in resizing each controls on form manually.
modified 15-Nov-16 20:04pm.
|
|
|
|
|