Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.net代码中的简化案例_Vb.net_Visual Studio_Visual Studio 2008 - Fatal编程技术网

VB.net代码中的简化案例

VB.net代码中的简化案例,vb.net,visual-studio,visual-studio-2008,Vb.net,Visual Studio,Visual Studio 2008,嘿,大家好,我在这里寻找,看看是否有人会有一个更好的方法来完成这项任务在更少的代码下面 Select Case mainMenu.theNumOpened Case 1 Me.Text = "NBMsg1" Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5) Case 2

嘿,大家好,我在这里寻找,看看是否有人会有一个更好的方法来完成这项任务在更少的代码下面

Select Case mainMenu.theNumOpened
            Case 1
                Me.Text = "NBMsg1"
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case 2
                Me.Text = "NBMsg2"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, Me.Height + 10, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case 3
                Me.Text = "NBMsg3"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 2) + 15, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case 4
                Me.Text = "NBMsg4"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 3) + 20, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case 5
                Me.Text = "NBMsg5"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg4")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 3) + 20, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 4) + 25, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case 6
                Me.Text = "NBMsg6"
                Dim hwnd As IntPtr = FindWindow(vbNullString, "NBMsg5")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, Me.Height + 10, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg4")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 2) + 15, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg3")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 3) + 20, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg2")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 4) + 25, 0, 0, 1)
                hwnd = FindWindow(vbNullString, "NBMsg1")
                SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, (Me.Height * 5) + 30, 0, 0, 1)
                Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
            Case Else
                Me.Close()
                Me.Dispose()
        End Select
它所做的是传递给它,现在许多窗口已经打开。所以如果是一个,那么它当然会进入案例1。如果有2个打开的,那么它会向下移动最旧的,并将最新的放在顶部。等等。我已经设置好,一次最多只能打开6个箱子

如果有人知道我如何“滑动”它们(有点像jQuery的效果),那么这也将是非常棒的o)

任何帮助/建议都会很好!:o)


David

由于很多代码要么只是重复,要么只是以某种方式递增,某种形式的For循环是可行的,我认为下面的代码应该可以工作,但它可能会以1或类似的方式关闭:

If mainMenu.theNumOpened > 0 And mainMenu.theNumOpened <= 6 Then
    Me.Text = "NBMsg" & Cstr(mainMenu.theNumOpened)
    Dim hwnd As IntPtr
    Dim h as integer = 5
    For i As Integer = mainMenu.theNumOpened - 1 To 1 Step -1
        FindWindow(vbNullString, "NBMsg" & CStr(i))        
        h += Me.Height + 5
        SetWindowPos(hwnd, 0, My.Computer.Screen.WorkingArea.Width - 302, h, 0, 0, 1)
    Next
    Me.SetDesktopLocation(My.Computer.Screen.WorkingArea.Width - 302, 5)
End If

如果main menu.theNumOpened>0和main menu.theNumOpened建议的编辑:在
处插入
步骤-1
For
语句;我相信
x
实际上是
主菜单。新菜单打开了
。谢谢,我还以为我忘记了for循环的一些东西,但是我在VB中做了一个
向后
循环已经太久了。谢谢你花时间这么做,呵呵。但是如果有超过1个显示,它似乎不会向下移动下一个框?它只是把它们叠在一起。还有其他人有什么建议吗?