vb.net titlebarless form upper border thickness remove - vb.net

i want to make title bar less resizable form.
so i add following code into form load event.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = String.Empty
Me.ControlBox = False
Me.FormBorderStyle = FormBorderStyle.SizableToolWindow
End Sub
this is vest way to make smoothly resizable form.
other every method which i use are not resize smoothly when try to resize from left or to side.
but there is a problem
upper margin of form is thick. how i solve this.

Related

PictureBox scrolling past edges of form erases contents

I am trying to create a simple winform application in VB. I have a form, a picturebox with a background image and a button. When I press the button, I want the picturebox to move left across the form until it disappears off the left side. Then I want it to reappear on the right side and move to the left again.
Initial condition:
The problem seems to be that the areas of the picturebox that exceed the boundaries of the form get erased. So the first time around the images slides nicely off the left side of the form and never comes back to the right side. Or rather, it does come back, I just can see it.
Second scroll around, parts of image in picturebox that exceeded the boundaries of the form have been erased (left) or distorted (right):
In the code below I have deliberately changed the boundaries for the picturebox so that I can see that it is actually looping back around. But as you can see in this image, the parts of the picture box that exceeded the boundaries of the form are either erased or distorted.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Do
PictureBox1.Left -= 1
Threading.Thread.Sleep(2)
If PictureBox1.Left <= -20 Then 'If PictureBox1.Left <= PictureBox1.Width Then
PictureBox1.Left = Me.Width - 40 'PictureBox1.Left = Me.Width
End If
Loop
End Sub
End Class
I have tried this with both VS2019 and VS2017 on two different computers and the same thing happens. I have also tried replacing the picturebox with a textbox and much the same thing happens.
I changed my code to this, and now it works perfectly.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Interval = 25
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Left -= 1
If PictureBox1.Left <= -PictureBox1.Width Then
PictureBox1.Left = Me.Width
End If
End Sub
End Class

Display an image in picturebox from specific position

I have a picturebox that "works" as button. I have load an image map as background image, to use it for buttons conditions (click, hover etc).
As default, background image shows it's top left position, the first icon. Let's say, how can I move (x) to 32px and (y) to 64? Something like css styles background-position: 32px 64px; for example.
If you need to reposition the image then I wouldn't use a PictureBox, just a Panel or draw the image on the surface of the form.
It is possible though with the following code. Notice that it removes the PictureBox's Image so you are losing the functionality of a PictureBox.
Public Class Form1
Private _moveIt As Boolean = False
Private _coyote As Image
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_coyote = PictureBox1.Image
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
_moveIt = True
PictureBox1.Invalidate()
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
If _moveIt = True Then
PictureBox1.Image = Nothing
e.Graphics.DrawImage(_coyote, New Rectangle(New Point(32, 64), _
New Size(_coyote.Width, _coyote.Height)))
End If
End Sub
End Class
To keep the PcitureBox's functionality (to use its Image property) you would have to create a new image which is a transformed version of the original image.

How do I display an Icon on the Taskbar but not on the form itself?

If I use ShowIcon in the form properties, I get the icon in the top left of my form (I don't want that), but I do get my icon in the taskbar.
If I turn ShowIcon off, then I get no icon on the form but I get the default winform icon on the taskbar.
I've tried changing border style, but FixedToolWindow creates an undesirable look that doesn't match the style of the other forms.
I have found a workaround. If you do Me.ShowIcon = False after the form is loaded, then it will display in the taskbar, but not on the program.
One way to do this is to have a timer enabled/begin as soon as form load ends, and then on tick, do Me.ShowIcon = False
As Below:
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Me.ShowIcon = False
Timer1.Enabled = False
End Sub
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Timer1.enabled = True
End Sub
Timer1 has an interval of 100ms (which works). If you just put the ShowIcon as True in the Form1_Load, a weird Icon shows (not the program's original icon). This is why we use the Timer.

Why does a Panel automatically scroll up when a different TextBox.Text is updated?

I've created a form and displayed it inside the panel but sadly the form can't fit. So I need to use Panel.Autoscroll = True in order to navigate the whole form.
When I click the textbox1.text in the lowest part of the form, the panel automatically scrolls up and the textbox can't be seen. Even if I scroll down it continuously scrolls up automatically.
How can I stop it from scrolling up?
Here is my code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.TopLevel = False
Me.Panel1.Controls.Clear()
Me.Panel1.Controls.Add(Form2)
Form2.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label2.Text = Date.Now.ToString("dd/MMM/yyyy ddddddddd")
Label1.Text = Date.Now.ToString("h:mm:ss tt")
End Sub
I realized the panel scrolls up when the date text is set to the label. Is there a way to prevent this?
You can resolve your problem by using your own panel and overriding the ScrollToControl function:
Public Class PanelEx
Inherits Panel
Protected Overrides Function ScrollToControl(c As Control) As Point
Return Me.DisplayRectangle.Location
End Function
End Class
Replace your Panel1 panel with this new one in your ToolBox after rebuilding your solution.

Draw rectangle around Textbox inside a Groupbox

I want to add a custom border around a TextBox control which is in a GroupBox.
Since I'm new to this Graphic stuff I'm having a hard time figuring out the problem.
This is the code i'm using:
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
Dim _g As Graphics = Me.GroupBox1.CreateGraphics
Dim pen As New Pen(Color.Red, 2.0)
_g.DrawRectangle(pen, New Rectangle(TextBox1.Location, TextBox1.Size))
pen.Dispose()
End Sub
This form is a secondary form that shows when I click on a button from the Main form. The Red Border appears for a second when the form loads and then disappears.
You need to handle the GroupBox paint event, not the form.
Private Sub HandleGroupBox1Paint(sender As Object, e As PaintEventArgs) Handles GroupBox1.Paint
Using p As New Pen(Color.Red, 2.0)
e.Graphics.DrawRectangle(p, Me.TextBox1.bound)
End Using
End Sub