1

画面の右下隅にフォームを表示する必要があるプログラムがあります。私はいくつかの調査を行ったところ、 me.location= を設定するとフォームの場所がロックされると言われていますが、機能していないようです。コードは以下のとおりです。


 Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Position form to lower right hand corner of screen

    Me.Visible = True
    Dim x As Integer
    Dim y As Integer
    x = Screen.PrimaryScreen.WorkingArea.Width
    y = Screen.PrimaryScreen.WorkingArea.Height - Me.Height

    Do Until x = Screen.PrimaryScreen.WorkingArea.Width - Me.Width
        x = x - 1
        Me.Location = New Point(x, y)
    Loop

End Sub

フォームに最小化、閉じるボタンがあり、最小化または閉じられていないときに右下隅にロックする必要があります。

VB 2010 Express を使用しています

乾杯。

4

4 に答える 4

3

これを試して:

アップデート:

より良い解決策は次のとおりです。

Public Class Form1

' Just to set and store custom locations
Dim Corners As New Dictionary(Of String, Point) 

' Flag to make/unmake form moveable
Private bMoveable As Boolean = True

Private Declare Function EnableMenuItem Lib "user32.dll" Alias "EnableMenuItem" (ByVal hMenu As IntPtr, ByVal uIDEnableItem As Int32, ByVal uEnable As Int32) As Int32

Public Overridable Property Moveable() As Boolean
    Get
        Return bMoveable
    End Get
    Set(ByVal Value As Boolean)
        If bMoveable <> Value Then
            bMoveable = Value
        End If
    End Set
End Property

Protected Overrides Sub WndProc(ByRef m As Message)

    If m.Msg = &H117& Then
        'Handles popup of system menu.
        If m.LParam.ToInt32 \ 65536 <> 0 Then 'divide by 65536 to get hiword.
            Dim AbleFlags As Int32 = &H0&
            If Not Moveable Then AbleFlags = &H2& Or &H1&
            EnableMenuItem(m.WParam, &HF010&, &H0& Or AbleFlags)
        End If
    End If

    If Not Moveable Then
        'Cancels any attempt to drag the window by it's caption.
        If m.Msg = &HA1 Then If m.WParam.ToInt32 = &H2 Then Return
        'Redundant but cancels any clicks on the Move system menu item.
        If m.Msg = &H112 Then If (m.WParam.ToInt32 And &HFFF0) = &HF010& Then Return
    End If

    'Return control to base message handler.
    MyBase.WndProc(m)

End Sub

Private Sub Form1_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown

    ' Add a custom location to the dictionary
    Corners.Add("BottomRight", _
      New Point(Screen.PrimaryScreen.WorkingArea.Width - Me.Width, _
                Screen.PrimaryScreen.WorkingArea.Height - Me.Height))

    ' Move the form
    Me.Location = Corners("BottomRight")

    ' Make it unmoveable from there!
    Me.Moveable = False

End Sub

End Class
于 2013-10-17T18:56:28.880 に答える
2

この投稿 ( Win 7 ガジェット (VB.net) のようにフォームを常にデスクトップに固定する) をチェックしないでください。ここで、私は非常によく似た質問に答えました。

于 2013-10-17T19:10:20.380 に答える
0

次のようなことを試すことができます:

Private Sub Form1_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
    Me.Location = New Point(30, 30)
End Sub
于 2013-10-17T18:54:18.457 に答える