Windows form to be shown topmost from taskbar - vb.net

Using VB.NET I create a form with TopMost=True, FormBorderStyle=FixedDialog, ControlBox=False, text="", size 400x50.
I display this form above Windows 10 taskbar. When I click on the taskbar, the form occupies only a taskbar's portion, the form is moved behind the taskbar. The form remains topmost if it is moved on the working area of the screen.
Is there a way to keep the form topmost above Windows 10 taskbar?
Sample code is given below. Using the arrows keys the form can be relocated for testing.
***UPDATE sample code added.
Public Class Form1
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
Dim istep As Integer = 1
If e.Alt Then istep = 10
Select Case e.KeyCode
Case Keys.Down
Me.Top += istep
Case Keys.Up
Me.Top -= istep
Case Keys.Left
Me.Left -= istep
Case Keys.Right
Me.Left += istep
End Select
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim b As Rectangle = My.Computer.Screen.Bounds
Dim w As Rectangle = My.Computer.Screen.WorkingArea
Me.Top = w.Height
Me.Left = 500
End Sub
End Class

You can resize the dialog manually according to the screen size in the Load function of the form.
The code would look something like (posting c# code):
Location = new Point(0, 0);
TopMost = true;
var screen = Screen.FromHandle(Handle);
Size = new Size(screen.Bounds.Width, screen.Bounds.Height);

Related

Maximize form but do not cover the taskbar

When I click the button to maximize my form, it covers the entire screen including the taskbar. I managed to find a solution and it works, I used my code in form load event but I cannot return the form into normal state.
Private Sub frmDashboard_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
End Sub
Private Sub btnMaximizeMin_Click(sender As Object, e As EventArgs) Handles btnMaxMin.Click
If Me.WindowState = FormWindowState.Normal Then
'maximize but dont cover taskbar
Me.Top = Screen.PrimaryScreen.WorkingArea.Top
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.Height = Screen.PrimaryScreen.WorkingArea.Height
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
Else
Me.WindowState = FormWindowState.Normal
End If
End Sub
The problem is that you aren't maximising the form. You specifically DON'T want to maximise the form because that covers the Windows Task Bar. You can't set the WindowState "back" to Normal because it's already in that state, because it never leaves that state. It's up to you to remember the state for yourself and also the previous bounds, e.g.
Private isMaximised As Boolean = False
Private normalBounds As Rectangle
Private Sub MaximiseOrRestore()
isMaximised = Not isMaximised
If isMaximised Then
normalBounds = Bounds
Bounds = Screen.PrimaryScreen.WorkingArea
Else
Bounds = normalBounds
End If
End Sub

Temporarily disable all other windows vb.net

I'm making a color picker and I want it so on button press it will disable everything but the program (like what snipping tool does, but not add grey to the screen).
So when I click somewhere, it can capture the color from mouse pointer, and re-enable all other programs. The reason why I want it to disable all other programs is so when you click to pick the color then it won't interfere with anything and change the color.
Any help is very much appreciated.
In this sample, there are two form FrmDesktopDisplay and FrmCaller
Public Class FrmDesktopDisplay
Public myResultStts As Boolean = False
Public myResultValue As Integer = -1
Private Sub FrmDesktopDisplay_Click(sender As Object, e As EventArgs) Handles Me.Click
'Here your code, not just in click event, you must modify according to your need
'And for example the result as follow:
myResultStts = True
myResultValue = 30
Me.Hide()
End Sub
Private Sub FrmDesktopDisplay_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Escape Then
'Here Just Hide, don't be closed or disposed, because you need the result
Me.Hide()
End If
End Sub
Private Sub FrmDesktopDisplay_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'First you must hide this form, to take desktop image
Me.Hide()
'This to make borderless
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Refresh()
Dim g As Graphics
Dim bmp As Bitmap
'This to take size of screen
Dim myWidth As Integer = My.Computer.Screen.Bounds.Size.Width
Dim myHeight As Integer = My.Computer.Screen.Bounds.Size.Height
'This to make this form's Size is same as screen size
Me.Width = myWidth
Me.Height = myHeight
'Create Blank Bitmap with size as same as screen size
bmp = New Bitmap(myWidth, myHeight)
'Create graphic with composition of bitmap
g = Graphics.FromImage(bmp)
'Take Image from screen, and move to graphic g
g.CopyFromScreen(0, 0, 0, 0, bmp.Size)
'Relocate this form to (0,0)
Me.Top = 0
Me.Left = 0
'Set this form's backgroundimage with bitmap of bmp, that have been taken by graphic g
Me.BackgroundImage = bmp
Me.Show()
Me.Refresh()
End Sub
End Class
The Caller Form
Public Class FrmCaller
Private Sub ButtonToPick_Click(sender As Object, e As EventArgs) Handles ButtonToPick.Click
'Hide the caller form if don't need this form when you run your sniff or clip
Me.Hide()
FrmDesktopDisplay.ShowDialog()
'To show again this form
Me.Show()
'Take the result from FrmDesktopDisplay, you can do it, because the form still active
Dim myResultStts As Boolean = FrmDesktopDisplay.myResultStts
Dim myResultValue As Integer = FrmDesktopDisplay.myResultValue
'Here you close the FrmDesktopDisplay
FrmDesktopDisplay.Close()
FrmDesktopDisplay.Dispose()
PictureBox1.Visible = False
End Sub
End Class
'Here you must have PictureBox1 in Your Form, and the form must be as parent container
Private Sub ButtonToPick_Click(sender As Object, e As EventArgs) Handles ButtonToPick.Click
PictureBox1.Visible = False
Me.Refresh()
Dim g As Graphics
Dim bmp As Bitmap
bmp = New Bitmap(Me.Width, Me.Height)
g = Graphics.FromImage(bmp)
Dim myFRect As Rectangle
myFRect = Me.RectangleToScreen(Me.DisplayRectangle)
g.CopyFromScreen(myFRect.Left, myFRect.Top, 0, 0, bmp.Size)
PictureBox1.Top = 0
PictureBox1.Left = 0
PictureBox1.Width = Me.Width
PictureBox1.Height = Me.Height
PictureBox1.Image = bmp
PictureBox1.Visible = True
PictureBox1.BringToFront()
'Me.Refresh()
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
'Here you process before picture box be hidden again
PictureBox1.Visible = False
End Sub

If something gets out of the panel in the top side then make it go to (0, 0) position, if in the botton side then (0, Panel Height Size)

So basically I've been trying to program a custom ScrollBar for my WinForm written in VB.NET and I don't seem to make it have a limit of the movement.
Code without limit tries:
Public Class GoldSrcScrollBar
Dim drag As Boolean
Dim mousey As Integer
Private Sub GoldSrcScrollBtn1_MouseDown(sender As Object, e As MouseEventArgs) Handles GoldSrcScrollBtn1.MouseDown
drag = True
mousey = Cursor.Position.Y - GoldSrcScrollBtn1.Top
End Sub
Private Sub GoldSrcScrollBtn1_MouseUp(sender As Object, e As MouseEventArgs) Handles GoldSrcScrollBtn1.MouseUp
drag = False
End Sub
Private Sub GoldSrcScrollBtn1_MouseMove(sender As Object, e As MouseEventArgs) Handles GoldSrcScrollBtn1.MouseMove
If drag Then
GoldSrcScrollBtn1.Top = Cursor.Position.Y - mousey
End If
End Sub
I have no idea how to make it have a limit
Slider = GoldSrcScrollBtn1
ScrollBar Background = GoldSrcScrollBarBg1
Without limit it works like this:
As you can see, it gets out of the Panel (GoldSrcScrollBarBg1).
Could someone help me please? Thanks :)

Resize Bordless Form is Glitchy

My code to resize my form from the right hand side works, but is really glitchy or has a lot of lag. All my images blur and my drawn rectangles flicker while I'm resizing. Everything is normal however once mouseup.
I put the formborderstyle from borderless to sizable and the form resizes normally.
Hoping someone might be able to point out what is wrong with my code.
Dim myresize As Boolean = False
Dim cursorx As Integer
Dim cursory As Integer
Private Sub TableLayoutPanel1_MouseDown(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseDown
If e.Location.X > Me.Width - 7 And e.Location.Y > 11 And e.Location.Y < Me.Height - 10 Then
myresize = True
cursorx = Windows.Forms.Cursor.Position.X - Me.Width
cursory = Windows.Forms.Cursor.Position.Y - Me.Height
End If
End Sub
Private Sub TableLayoutPanel1_MouseMove(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseMove
If myresize = True Then
Me.Width = Windows.Forms.Cursor.Position.X - cursorx
End If
End Sub
Private Sub TableLayoutPanel1_MouseUp(sender As Object, e As MouseEventArgs) Handles TableLayoutPanel1.MouseUp
myresize = False
End Sub
For the flickering, the form does not pass the DoubleBuffered property to its child controls, such as your TableLayoutPanel. Instead try adding a new class to your project that will doubleBuffer the tableLayoutPanel.
Public Class DoubleBufferedTableLayoutPanel
Inherits TableLayoutPanel
Public Sub New()
Me.DoubleBuffered = True
End Sub
End Class
Build your project and the new version of the TableLayoutPanel will be in your toolbox as DoubleBufferedTableLayoutPanel. From there just use it as you would the TableLayoutPanel in your code.

Picturebox / Panel tearing when drag vb.net

I'm trying to make VB.net program and UI is like normal desktop. I have images in picture
boxes as desktop shortcuts. So user can drag them around in form. Btw im not skilled just started
to do things like this.
I can move picture boxes with mouse events its fine But pictures in pictureboxes are tearing when dragging. i have a big background picture, i guess this is the problem but i need help to get rid of tearing. heres code thx.
i also tryed as a panel and get same result.
Edit : pictures about dragging is png , 50x50 , transparent BG.
Public Class testform
Dim drag As Boolean
Dim mousex, mousey As Integer
Private Sub testform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.BackgroundImage = My.Resources.worldmap 'approx 1.03mb Picture size
End Sub
Private Sub dragbox_MouseDown(sender As Object, e As MouseEventArgs) Handles dragbox.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
drag = True
mousex = Windows.Forms.Cursor.Position.X - dragbox.Left
mousey = Windows.Forms.Cursor.Position.Y - dragbox.Top
Else
End If
End Sub
Private Sub dragbox_MouseMove(sender As Object, e As MouseEventArgs) Handles dragbox.MouseMove
If drag = True Then
dragbox.Left = Windows.Forms.Cursor.Position.X - mousex
dragbox.Top = Windows.Forms.Cursor.Position.Y - mousey
End If
End Sub
Private Sub dragbox_MouseLeave(sender As Object, e As EventArgs) Handles dragbox.MouseLeave
drag = False
End Sub
End Class
You need to make the picture form double buffered. That means that it will no longer tear as it will first completely make sure it's all in place before showing the next frame.