Minimum Vb.net Form size - vb.net

Can we shrink the width of form size less than 132 and height less than 38 Please help me about it.
Here is the code:
For i As Integer = 0 To meWidth
If (Me.Width > 0) Then
Me.Width = Me.Width - 20
Me.Refresh()
For FadeCount = 40 To 40 Step 20
Me.Opacity = FadeCount / 100
Threading.Thread.Sleep(10)
Next
Else
Exit For
End If
Next

You can define your minimun form size with the property Form.MinimumSize. Check the MSDN Documentation about it.
Basically:
This property enables you to limit the size of a form to a specified minimum size. You can use this feature to prevent a user from sizing a window to an undesirable size. If this property is set to a Size object that is 0 in height and 0 in width, the form will have no minimum size beyond the limits set by Windows.

I couldn't find this answer anywhere and I would like to share my solution:
Me.Text = ""
Me.ControlBox = False
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.MinimumSize = New System.Drawing.Size(1, 1) 'HERE IS MY FIX
Me.Size = New System.Drawing.Size(200, 23)
By not allowing the MinimumSize property to remain at (0,0) by default, it seems to have cleared this bug up for me.

U can Control Minimum Size : Example
Dim MinWidth As Integer = 396
Dim MinHeigh As Integer = 369
If Me.Width <= MinWidth Then
Me.Width = MinWidth
End If
If Me.Height <= MinHeigh Then
Me.Height = MinHeigh
End If

Related

Resizing controls in a form

I have 3 controls and wanted to resize and reposition them based on what percentage increase or decrease the form WindowWidth property is. I came up with two formulas
One for increasing the .width and .Left properties and the other is for reducing the .width and .Left properties.
The form consists of a subform which is anchored to stretch down and across. All the textboxes are anchored to the left.
The initial size of the form is 20.5cm = 11624 twips
The anchored and maximised size of the form becomes 36.01cm = 20415 twips
These values are found using Me.Width and Me.WindowWidth properties respectively.
I want to be able to use the Me.Width and Me.WindowWidth properties to manipulate the position and width of the controls when the form gets resized.
I have the below code which works on form load but does not work if a user tries to resize using the access window. Any help or direction is highly welcome.
Private Sub Form_Resize()
Dim widthFactor As Double
If Me.WindowWidth = Me.Width Then
Exit Sub
widthFactor = 1 - ((Me.WindowWidth - Me.Width) / Me.WindowWidth) 'for decreasing the controls size and position
Me.txtFirst.Left = Me.txtFirst.Left * widthFactor
Me.txtSecond.Left = Me.txtSecond.Left * widthFactor
Me.txtThird.Left = Me.txtThird.Left * widthFactor
Me.txtFirst.Width = Me.txtFirst.Width * widthFactor
Me.txtSecond.Width = Me.txtSecond.Width * widthFactor
Me.txtThird.Width = Me.txtThird.Width * widthFactor
ElseIf Me.Width < Me.WindowWidth Then
widthFactor = ((Me.WindowWidth - Me.Width) / Me.Width) + 1 ' for increasing the controls size and position
Me.txtFirst.Left = Me.txtFirst.Left * widthFactor
Me.txtSecond.Left = Me.txtSecond.Left * widthFactor
Me.txtThird.Left = Me.txtThird.Left * widthFactor
Me.txtFirst.Width = Me.txtFirst.Width * widthFactor
Me.txtSecond.Width = Me.txtSecond.Width * widthFactor
Me.txtThird.Width = Me.txtThird.Width * widthFactor
End If
End Sub

Zoom in a picturebox image 100 times

I want to zoom In the image of a picturebox which is inside a panel. Basically it's a Radar simulator where I need to show a map on picturebox and zoom it for the range from 100 NM to 1 NM. The zoom value is decided by a HScrollBar (Min-1, Max-100, corresponds to NM). If HScrollbar value is 100 (means 100 NM) , full image is shown without Zoom and when HScrollbar value is 1 (means 1 NM), the image needs to zoom in to 1/100 times smaller area at the center of picture.
In my present code I am increasing the size of the picturebox control and then setting its Left and Top properties to keep it centered. The image size is 577 X 577 and the picturebox size is equal to screen size (i.e maximized). But the problem is that, i am only able to zoom it upto 2.5 times only. More than 2.5 times zooming makes it extremely slow and after sometimes draws the error image i.e. red X mark in the picturebox.
If pb.Image IsNot Nothing Then
'calculate the new size from the original image size
Dim nWidth As Integer = CInt((panel1.Width + (100 * panel1.Width / frmLDA.HSRange.Maximum) * (frmLDA.HSRange.Maximum - _scale)))
Dim nHeight As Integer = CInt((panel1.Height + (100 * panel1.Height / frmLDA.HSRange.Maximum) * (frmLDA.HSRange.Maximum - _scale)))
newWidth = nWidth
newHeight = nHeight
'make sure you do not try to create a new bitmap that has a width or height of 0
If nWidth > 0 And nHeight > 0 Then
'create a new bitmap at the new size
Using bmp As New Bitmap(nWidth, nHeight)
'create a graphics object for the new bitmap
Using g As Graphics = Graphics.FromImage(bmp)
g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(OriginalImage, 0, 0, nWidth, nHeight)
End Using 'disposes the graphics object
pb.Image.Dispose() 'dispose the old bitmap that was assigned to the image property
pb.Image = New Bitmap(bmp) 'assign a copy of the new Bitmap
pb.ClientSize = pb.Image.Size 'reset the size of the picturebox
pb.Left = CInt(panel1.Width / 2 - pb.Width / 2)
pb.Top = CInt(panel1.Height / 2 - pb.Height / 2)
End Using 'disposes the Bitmap
End If
End If
Is there any way to zoom the image smoothly may be without actually increasing the picturebox size so that it does not encounter any error? Any help will be appreciated. Thanks.

Fitting runtime buttons inside a form

I have a number of buttons between 5-20 and it's variable each time the form loads based on the user settings. I am trying to fit all these buttons on my form no matter what the size of the form is. The buttons are generated during runtime. I would like the first button to be 20 points from the top bar (at any size) and the rest of the buttons simply to fit in the form. This is what I have now but I have to maximize the form to view them all and also while I'm expanding the form the space between the buttons decreases and they overlap with each other whereas they should keep a relative distance. Any ideas?
Dim iButtonWidth, iButtonHeight, iVerticalSpace As Integer
If UserButtons.Count > 0 Then
iButtonHeight = Me.Size.Height - (Me.Size.Height * 0.85)
iButtonWidth = Me.Size.Width - (Me.Size.Width * 0.5)
iVerticalSpace = iButtonHeight / 3
For Each btn In UserButtons
btn.Size = New System.Drawing.Size(iButtonWidth, iButtonHeight)
btn.Location = New Point(20, 20 + btn.TabIndex * iVerticalSpace * 3)
Next
End If
Here's a quick example using the TableLayoutPanel to play with:
Public Class Form1
Private UserButtons As New List(Of Button)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Static R As New Random
Dim NumButtons As Integer = R.Next(5, 21) ' "a number of buttons between 5-20 and it's variable each time"
UserButtons.Clear()
For i As Integer = 1 To NumButtons
Dim btn As New Button()
btn.Text = i.ToString("00")
btn.Dock = DockStyle.Fill ' Optional: See how you like it with this on vs. off
UserButtons.Add(btn)
Next
DisplayButtons()
End Sub
Private Sub DisplayButtons()
TableLayoutPanel1.SuspendLayout()
TableLayoutPanel1.Controls.Clear()
TableLayoutPanel1.ColumnStyles.Clear()
TableLayoutPanel1.ColumnCount = 5 ' Fixed Number of Columns
For i As Integer = 1 To TableLayoutPanel1.ColumnCount
TableLayoutPanel1.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 911)) ' the size doesn't matter here, as long as they are all the same
Next
' Variable Number of Rows:
Dim RowsRequired As Integer = ((UserButtons.Count - 1) \ TableLayoutPanel1.ColumnCount) + 1 ' Integer Division
TableLayoutPanel1.RowStyles.Clear()
TableLayoutPanel1.RowCount = RowsRequired
For i As Integer = 1 To TableLayoutPanel1.RowCount
TableLayoutPanel1.RowStyles.Add(New RowStyle(SizeType.Percent, 911)) ' the size doesn't matter here, as long as they are all the same
Next
TableLayoutPanel1.Controls.AddRange(UserButtons.ToArray)
TableLayoutPanel1.ResumeLayout()
End Sub
End Class
First of all what kind of container are the buttons in? You should be able to set the container's AutoScroll property to true - then when controls within it spill out of the visible bounds you will get a scroll bar.
Then also what you could do is draw each button in more of a table with a certain number next to each other before dropping down to the next line (instead of just 1 button on each line). If that is an option that works for you then you could get more buttons within the visible space.
I happen to have an example to do the same thing with picture boxes (and text boxes under each picture box). Hope this helps:
Dim point As New Point(0, 0)
'create 11 picture and text boxes-you can make this number the number your user selects.
Dim box(11) As PictureBox
Dim text(11) As TextBox
Dim i As UInt16
For i = 0 To 11 'or whatever your number is
box(i) = New PictureBox
box(i).Width = 250 'your button width
box(i).Height = 170 'your button height
box(i).BorderStyle = BorderStyle.FixedSingle
box(i).Location = point
layoutsPanel.Controls.Add(box(i)) 'my container is a panel
text(i) = New TextBox
text(i).Height = 50
text(i).Width = 250
point.Y += box(i).Height
text(i).Location = (point)
layoutsPanel.Controls.Add(text(i))
point.Y -= box(i).Height 'reset Y for next picture box
'Put 4 picture boxes in a row, then move down to next row
If i Mod 4 = 3 Then
point.X = 0
point.Y += box(i).Height + text(i).Height + 4
Else
point.X += box(i).Width + 4
End If
Next

How to again display vanished icon from my form?

i am using this code for form display in my form load event but after form load icon of the form vanished i want to show my icon please help me
Here is the code:
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None 'Turning off border
Me.SetBounds(meleft, metop, Me.Width, MinimumSize.Height) 'setting the loaction and the size of the form
For i As Integer = 0 To meheight Step 20
If (Me.Height < meheight) Then
Me.Top = Me.Top - 20
Me.Height = Me.Height + 20
Me.Refresh()
For FadeCount = 40 To 40 Step 20
Me.Opacity = FadeCount / 100
Threading.Thread.Sleep(10)
Next
Else
Exit For
End If
Next
Me.Height = meheight
Me.Top = (msize(1, 1) - Me.Height) / 2 + msize(1, 3)
Me.Opacity = 99
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
At the start of the code you declare:
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
This is what is making your border/icon not visible.
In Form1 Properties-->Window Style: Set ControlBox = True.

Referencing screen height and width in vb.net

How do I reference the screen height and width in vb.net? For example, the bottom right corner's locations, the top right corner's locations, etc.
I tried My.Computer.Screen but couldnt find anything that told me the size.
You can use:
My.Computer.Screen.Bounds
or:
Screen.PrimaryScreen.Bounds
Bounds is a rectangle that provides the size. Alternatively, you can look at the WorkingArea, which will not include the task bar and docked windows.
You can use something like:
My.Computer.Screen.Bounds.Size.Width
My.Computer.Screen.Bounds.Size.Height
For WPF you can use:
System.Windows.SystemParameters.PrimaryScreenWidth
System.Windows.SystemParameters.PrimaryScreenHeight
dim height as integer = Screen.PrimaryScreen.Bounds.Height
dim width as integer = Screen.PrimaryScreen.Bounds.Width
Insert this code into form_load. I put some resolutions...
Dim dw As Double
Dim dh as Double
Width = Screen.PrimaryScreen.Bounds.Width
If (Width = 1366) Then
dw = 1
ElseIf (Width = 1920) Then
dw = 1.4055
ElseIf (Width = 1280) Then
dw = 0.9379
End If
For Each c As Control In Me.Controls
c.Width = CInt(CDbl(c.Width * dw))
Next
Height = My.Computer.Screen.Bounds.Size.Height
If (Height = 768) Then
dh = 1
ElseIf (Height = 1080) Then
dh = 1.4062
ElseIf (Height = 1024) Then
dh = 1.3333
End If
For Each g As Control In Me.Controls
g.Height = CInt(CDbl(g.Height * dh))
Next