How to again display vanished icon from my form? - vb.net

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.

Related

VB.NET Displaying All Form on Different Monitor

I'm trying to my 3 Forms to three of my Monitors but I can't seem to display the other 2 I can only display Form1 on my Second Monitor. Is it the wrong syntax in my code?
Dim numberofmonitors As Integer = Screen.AllScreens.Length
If numberofmonitors > 1 Then
Me.Bounds = Screen.AllScreens(1).Bounds
ElseIf numberofmonitors > 2 Then
Me.Bounds = Screen.AllScreens(1).Bounds
Form2.Bounds = Screen.AllScreens(2).Bounds
Form2.Show()
ElseIf numberofmonitors > 3 Then
Me.Bounds = Screen.AllScreens(1).Bounds
Form2.Bounds = Screen.AllScreens(2).Bounds
Form2.Show()
Form3.Bounds = Screen.AllScreens(3).Bounds
Form3.Show()
End If
And i also try this command
Dim myScreens() As Screen = Screen.AllScreens
If (myScreens.Length = 3) Then
'Position form 1 in the middle of screen 1
Me.Left = myScreens(0).WorkingArea.Width / 2 - Me.Width / 2
Me.Top = myScreens(0).WorkingArea.Height / 2 - Me.Height / 2
'Position the top left corner of form 2 in the middle of screen 2
Dim myForm2 As New Form2
myForm2.Show()
myForm2.Left = myScreens(0).Bounds.Width + myScreens(1).WorkingArea.Width / 2
myForm2.Top = myScreens(1).WorkingArea.Height / 2
Dim myForm3 As New Form2
myForm3.Show()
myForm3.Left = myScreens(0).Bounds.Width + myScreens(2).WorkingArea.Width / 3
myForm3.Top = myScreens(2).WorkingArea.Height / 3
End If
but the problem is this command is Form3 is not displaying to my 1rst monitor/left side monitor but then the Main form is displaying to my Middle Monitor and Form2 is displaying to my Right Monitor
Me.Bounds = Screen.AllScreens(0).Bounds
Me.StartPosition = FormStartPosition.Manual
Form2.Bounds = Screen.AllScreens(1).Bounds
Form2.Show()
Form2.StartPosition = FormStartPosition.Manual
Form3.Bounds = Screen.AllScreens(2).Bounds
Form3.StartPosition = FormStartPosition.Manual
Form3.Show()
So i did this command someone helped me in reedit thanks anyway guys

What Is The Best Way To Animate A Panel Container Opening And Closing (With Added Controls)

I am trying to create an animated collapsible panel that consists of three different elements. Each element is created from a panel container that sits on a user control. It is made up of a header panel, a content panel and a footer panel (with the footer panel sitting inside the content panel):
Within each panel I override the draw event and do my own custom drawing. This includes rounding the corners, drawing a border, and filling the background (and drawing text in the cases of the header and footer).
The control also allows users to embed into the content panel at both design time and runtime.
When placed on a form, it looks exactly how I want it to, however, I cannot seem to animate the panel in a seamless 'smooth' transition. It is jerky, jittery and looks horrendous when expanding the panel (even with no content).
The way it should work is that when minimized, the content panel (including the footer panel) shrinks to only be the height of the header panel. The header panel then redraws itself to look different. Then when maximized, the panel basically does everything in reverse.
My animation code looks like such:
Dim m_Height As Integer = Me.Height
Dim m_HeaderHeight As Integer = 40
Dim m_FooterHeight As Integer = 35
Dim ShrinkStepSize As Integer = CInt((m_Height - m_HeaderHeight) / 10)
Dim ExpandStepSize As Integer = CInt((m_Height - m_HeaderHeight) / 4)
Private Sub picMinimize_Click(sender As Object, e As EventArgs) Handles picMinimize.Click
While (Me.Height > m_HeaderHeight)
Me.Height -= Math.Min(Me.Height - m_HeaderHeight, ShrinkStepSize)
Application.DoEvents()
End While
picMaximise.Visible = True
picMinimize.Visible = False
m_Minimized = True
Me.Invalidate(pnlHeader.ClientRectangle, True)
End Sub
Private Sub picMaximise_Click(sender As Object, e As EventArgs) Handles picMaximise.Click
While (Me.Height < m_Height)
Me.Height += Math.Min(m_Height - Me.Height, ExpandStepSize)
Application.DoEvents()
End While
picMaximise.Visible = False
picMinimize.Visible = True
m_Minimized = False
Me.Invalidate(pnlHeader.ClientRectangle, True)
End Sub
And without posting all of my code (unless it's required), here are all my paint events for the header, content and footer panels:
Private Sub pnlHeader_Paint(sender As Object, e As PaintEventArgs) Handles pnlHeader.Paint
Dim rect As Rectangle = pnlHeader.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
'Position the icon elements
picClose.Location = New Point(rect.Width - (picClose.Width + 8), CInt(((rect.Height - picClose.Height) / 2) + 3))
picOptions.Location = New Point(rect.Width - ((picClose.Width + picOptions.Width) + 10), CInt(((rect.Height - picOptions.Height) / 2) + 2))
picMinimize.Location = New Point(rect.Width - ((picMinimize.Width + picOptions.Width + picClose.Width) + 15), CInt(((rect.Height - picMinimize.Height) / 2) + 3))
picMaximise.Location = New Point(rect.Width - ((picMaximise.Width + picOptions.Width + picClose.Width) + 15), CInt(((rect.Height - picMaximise.Height) / 2) + 3))
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, Me.CornerRounding)
If m_Minimized Then
'Draw the background
Using br As Brush = New SolidBrush(Color.White)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
End If
'Draw the text
Dim textRect As Rectangle = rect
textRect.X += m_HeaderAdjustment
Using string_format As New StringFormat()
string_format.Alignment = StringAlignment.Near
string_format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(HeaderText, New Font("Segoe UI", 13, FontStyle.Bold, GraphicsUnit.Pixel), New SolidBrush(Color.FromArgb(157, 159, 162)), textRect, string_format)
End Using
End Sub
Private Sub pnlContent_Paint(sender As Object, e As PaintEventArgs) Handles pnlContent.Paint
Dim rect As Rectangle = pnlContent.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, Me.CornerRounding)
'Draw the background
Using br As Brush = New SolidBrush(Color.White)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
rect.Inflate(-1, -1)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
End Sub
Private Sub pnlFooter_Paint(sender As Object, e As PaintEventArgs) Handles pnlFooter.Paint
Dim rect As Rectangle = pnlFooter.ClientRectangle
rect.X = rect.X + 1
rect.Y = rect.Y + 1
rect.Width -= 2
rect.Height -= 2
Dim rounding As Corners = Corners.BottomLeft Or Corners.BottomRight
Dim path As Drawing2D.GraphicsPath = RoundRectangle(rect, CornerRadius, rounding)
'Draw the background
Using br As Brush = New SolidBrush(FooterBackColour)
e.Graphics.FillPath(br, path)
End Using
'Draw the border
Using br As Brush = New SolidBrush(BorderColour)
e.Graphics.DrawPath(New Pen(br, 1), path)
End Using
'Draw the text
Dim textRect As Rectangle = rect
textRect.X += m_FooterAdjustment
textRect.Y += 1
Using string_format As New StringFormat()
string_format.Alignment = StringAlignment.Near
string_format.LineAlignment = StringAlignment.Center
e.Graphics.DrawString(FooterText, New Font("Segoe UI", 11, FontStyle.Regular, GraphicsUnit.Pixel), New SolidBrush(FooterForeColour), textRect, string_format)
End Using
End Sub
Any help with this would be greatly appreciated.
Thanks heaps.

dynamically layout buttons .net

Hie everyone
I have a procedure which puts buttons on a .net windows form using vb.net. It works ok but because I do not know the number of buttons I will be programming because they come from the database I would like a way to lay them out in rows of 10. I have programmed up to 50 which ios 5 rows but the method I am using will not work if there is more than 50. Is there a way do this. I have tried using mod of the number of boxes and it does not work.
Here is the code.
Private Sub AddButtons()
Dim xPos As Integer = 0
Dim yPos As Integer = 0
Dim n As Integer = 1
Dim numberOfBoxes As Integer
numberOfBoxes = txtNumberOfBoxes.Text
numberOfBoxes = numberOfBoxes + 1
' Declare and Initialize one variable
Dim btnArray(numberOfBoxes) As System.Windows.Forms.Button
For i As Integer = 0 To numberOfBoxes
btnArray(i) = New System.Windows.Forms.Button
Next i
While (n < numberOfBoxes)
With (btnArray(n))
.Tag = n + 1 ' Tag of button
.Width = 100 ' Width of button
.Height = 100 ' Height of button
If (n = 11) Then ' Location of second line of buttons:
xPos = 0
yPos = 120
ElseIf (n = 21) Then
xPos = 0
yPos = 240
ElseIf (n = 31) Then
xPos = 0
yPos = 360
ElseIf (n = 41) Then
xPos = 0
yPos = 480
ElseIf (n = 51) Then
xPos = 0
yPos = 600
End If
'If n Mod 10 = 0 Then
' xPos = xPos
' yPos = yPos + 50
'End If
' Location of button:
.Left = xPos
.Top = yPos
' Add buttons to a Panel:
pnlButtons.Controls.Add(btnArray(n)) ' Let panel hold the Buttons
xPos = xPos + .Width ' Left of next button
.Text = (n)
' for Event of click Button
AddHandler .Click, AddressOf Me.ClickButton
n += 1
End With
End While
btnAddButton.Enabled = False ' not need now to this button now
Label1.Visible = True
End Sub
I would suggest using a FlowLayoutPanel or, more likely, a TableLayoutPanel. You configure it to grow in the manner required and then all you have to do in code is Add the Button to its Controls collection. It handles all the layout so there's no calculation required.
Private Sub AddButtons()
Dim numberOfBoxes As Integer = txtNumberOfBoxes.Text
For i As Integer = 0 To numberOfBoxes - 1
'since row is an integer it won't have decimal places
'also \ divides without decimales-
Dim row As Integer = i \ 10
'The modulo operator is your friend. it gives you
'the rest of the devision.
' http://en.wikipedia.org/wiki/Modulo_operation
Dim col As Integer = i Mod 10
Dim newButton = New System.Windows.Forms.Button
With newButton
.Tag = i + 1 ' Tag of button
.Width = 100 ' Width of button
.Height = 100 ' Height of button
.Left = col * .Width
.Top = row * (.Height + 20)
.Text = i + 1
AddHandler .Click, AddressOf Me.ClickButton
End With
pnlButtons.Controls.Add(newButton)
Next i
btnAddButton.Enabled = False ' not need now to this button now
Label1.Visible = True
End Sub

Need the equivalent of screen.width and screen.height on vb for vb.net

In VB6 I had the following code to dock a window:
Public Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If IsBeingDragged = True And Button = MouseButtons.Left Then
'if the drag flag is true and left mouse button is pressed...
'set Left side docking
If Me.Left + (x - Xs) < DockScale Then
Me.Left = 0
Exit Sub
End If
'set Top side docking
If Me.Top + (y - Ys) < DockScale Then
Me.Top = 0
Exit Sub
End If
'set right side docking
If Me.Left + (x - Xs) + Me.Width > (Screen.Width - DockScale) Then
Me.Left = Screen.Width - Me.Width
Exit Sub
End If
'set bottom side docking
If Me.Top + (y - Ys) + Me.Height > (Screen.Height - DockScale) Then
Me.Top = Screen.Height - Me.Height
Exit Sub
End If
'move the form finally
Me.Left = Me.Left + (x - Xs)
Me.Top = Me.Top + (y - Ys)
End If
End Sub
I am using vb.net now and when I tried to copy and paste my code is telling me that screen.widht and screen.height are not members of the systems.window.form.screen, is there an equivalent to this on vb.net?
Sample code to access the screen dimensions in VB.NET :
Dim curScreen As Screen
curScreen = Screen.PrimaryScreen 'curScreen = Screen.AllScreens(0)
Dim height As Integer = curScreen.Bounds.Height
height = curScreen.WorkingArea.Height
You have to choose the screen you want and then decide what "framework" you want to deal with: Bounds (whole screen) or WorkingArea (whole screen without including the taskbar).

Minimum Vb.net Form size

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