1

I have created a form (using WinForms, VS 2019, Framework 4.8), set the background image to an image I chose, set the background colour of the form to a specific colour and then specified that colour as the TransparencyKey. The opacity of the form is still 100%.

I created a context menu for when you click on the form. That works.

I turned off all the other visible parts of the form (min/max buttons, borders, icon, etc) so that all that displays is the Image, which is exactly what I wanted. What I would like to know though is if it is possible to allow dragging and/or resizing of the form (of which only the background image is visible).

Just for completeness, the only other question I can find close to this topic is here.

Edit 1: Resize workaround

As a workaround, I created another form called from the context menu, with two numeric up/down controls. Code looks like this:

Public Class FrmResize
    Dim OldHeight As Integer
    Dim OldWidth As Integer
    Private Sub FrmResize_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        OldHeight = FrmShieldMenu.Height
        OldWidth = FrmShieldMenu.Width
        HeightNumericUpDown.Value = OldHeight
        WidthNumericUpDown.Value = OldWidth
    End Sub

    Private Sub BtnReset_Click(sender As Object, e As EventArgs) Handles BtnReset.Click
        FrmShieldMenu.Height = OldHeight
        FrmShieldMenu.Width = OldWidth
    End Sub

    Private Sub BtnApply_Click(sender As Object, e As EventArgs) Handles BtnApply.Click
        FrmShieldMenu.Height = HeightNumericUpDown.Value
        FrmShieldMenu.Width = WidthNumericUpDown.Value
        Me.Close()
    End Sub
End Class

It's not elegant, but in concept, it works. The various solutions given in the pages linked in the comments are a) C# not vb.net, b) Waaay too complicated c) Overkill really.

Edit 2: Drag Solved

Thanks to the comments, I found a piece of code which I translated to vb.net and applied directly without, as recommended there, creating a class. Turns out it's very simple. First, define some variables after the form class statement, then add three sub-routines. To generate the subs, use the lightening bolt on the form to select mousedown, mouseup and mousemove. Then just add a few lines of code.

Public Class FrmShieldMenu
    Private movX, movY As Integer
    Private isMoving As Boolean
Private Sub FrmShieldMenu_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
        If isMoving Then
            SetDesktopLocation(MousePosition.X - movX, MousePosition.Y - movY)
        End If
    End Sub

    Private Sub FrmShieldMenu_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
        isMoving = False
    End Sub

    Private Sub FrmShieldMenu_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        isMoving = True
        movX = e.X
        movY = e.Y
    End Sub
End Class
John Dovey
  • 21
  • 5
  • See [How to move and resize a form without a border?](https://stackoverflow.com/q/2575216/719186) – LarsTech Mar 11 '21 at 20:02
  • Try [this Per-pixel-alpha Layered Form](https://stackoverflow.com/a/60688580/7444103). It can be *moved around* (and it's much better than a Form with transparency). – Jimi Mar 11 '21 at 20:12
  • Those look like great possibilities, thank you. – John Dovey Mar 11 '21 at 20:21
  • See [How to move form without form border (visual studio)](https://stackoverflow.com/a/24449733/719186) – LarsTech Mar 11 '21 at 22:24

0 Answers0