Vb.net touch screen: in VB.net, how do I get a panel to scroll on a touch screen?

vb.net FlowLayoutPanel Touchscreen Scrolling — Stack Overflow



Ask Question


Asked


Modified
6 years, 10 months ago


Viewed
1k times

I’ve managed to get some form of scrolling on my FlowLayoutPanel when using a touchscreen by implementing the following code…

Dim mouseDownPoint As Point
Private Sub FlowLayoutPanelUsers_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers.MouseDown
    If (e.Button = MouseButtons.Left) Then
        Me.mouseDownPoint = e.Location
    End If
End Sub
Private Sub FlowLayoutPanelUsers_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers. MouseMove
    If (e.Button <> MouseButtons.Left) Then
        Return
    End If
    If ((mouseDownPoint.X = e.Location.X) _
                AndAlso (mouseDownPoint.Y = e.Location.Y)) Then
        Return
    End If
    Dim currAutoS As Point = FlowLayoutPanelUsers.AutoScrollPosition
    If (mouseDownPoint.Y > e.Location.Y) Then
        'finger slide UP
        If (currAutoS.Y <> 0) Then
            currAutoS.Y = (Math.Abs(currAutoS.Y) - 1)
        End If
    ElseIf (mouseDownPoint.Y < e.Location.Y) Then
        'finger slide down
        currAutoS.Y = (Math.Abs(currAutoS.Y) + 1)
    Else
        currAutoS.Y = Math.Abs(currAutoS.Y)
    End If
    If (mouseDownPoint.X > e.Location.X) Then
        'finger slide left
        If (currAutoS.X <> 0) Then
            currAutoS.X = (Math.Abs(currAutoS.X) - 1)
        End If
    ElseIf (mouseDownPoint.X < e.Location.X) Then
        'finger slide right
        currAutoS.X = (Math.Abs(currAutoS.X) + 1)
    Else
        currAutoS. X = Math.Abs(currAutoS.X)
    End If
    FlowLayoutPanelUsers.AutoScrollPosition = currAutoS
    mouseDownPoint = e.Location
    'IMPORTANT
End Sub

This is some code I’ve already found on stackoverflow, so thanks for that initally!

What I want this code to do, if possible, is reverse the way it scrolls, so if I scroll left, the FlowLayoutPanel scrolls right, if I scroll up, the Panel scrolls down, a bit like a web browser does.

Does anyone have any insight on it? I’ve tried the simple bit of reversing the minus signs to plus and visa versa, but no effect.

Thanks in advance.

  • vb.net
  • flowlayoutpanel






1

Revised code…

Dim mouseDownPoint As Point
Private Sub FlowLayoutPanelUsers_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers.MouseDown
   If (e.Button = MouseButtons.Left) Then
       Me.mouseDownPoint = FlowLayoutPanelUsers. PointToClient(MousePosition)
   End If
End Sub
Private Sub FlowLayoutPanelUsers_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles FlowLayoutPanelUsers.MouseMove
   If (e.Button <> MouseButtons.Left) Then
       Return
   End If
   If ((mouseDownPoint.X = FlowLayoutPanelUsers.PointToClient(MousePosition).X) _
               AndAlso (mouseDownPoint.Y = FlowLayoutPanelUsers.PointToClient(MousePosition).Y)) Then
       Return
   End If
   Dim currAutoS As Point = FlowLayoutPanelUsers.AutoScrollPosition
   If (mouseDownPoint.Y > FlowLayoutPanelUsers.PointToClient(MousePosition).Y) Then
       'finger slide UP
       If (currAutoS.Y <> 0) Then
           currAutoS.Y = (Math.Abs(currAutoS.Y) - 1)
       End If
   ElseIf (mouseDownPoint.Y < FlowLayoutPanelUsers.PointToClient(MousePosition).Y) Then
       'finger slide down
       currAutoS.Y = (Math.Abs(currAutoS.Y) + 1)
   Else
       currAutoS.Y = Math.Abs(currAutoS.Y)
   End If
   If (mouseDownPoint.X > FlowLayoutPanelUsers. PointToClient(MousePosition).X) Then
       'finger slide left
       If (currAutoS.X <> 0) Then
           currAutoS.X = (Math.Abs(currAutoS.X) - 1)
       End If
   ElseIf (mouseDownPoint.X < FlowLayoutPanelUsers.PointToClient(MousePosition).X) Then
       'finger slide right
       currAutoS.X = (Math.Abs(currAutoS.X) + 1)
   Else
       currAutoS.X = Math.Abs(currAutoS.X)
   End If
   FlowLayoutPanelUsers.AutoScrollPosition = currAutoS
   mouseDownPoint = FlowLayoutPanelUsers.PointToClient(MousePosition)
   'IMPORTANT
End Sub






1







Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Email

Required, but never shown

Post as a guest


Email

Required, but never shown






vb.

net — Using a touchscreen to Scroll a Panel while dragging the Panel’s controls



Ask Question


Asked


Modified
5 years, 11 months ago


Viewed
404 times

My Form has a scrollable Panel that can be scrolled using a touchscreen monitor. My Panel will contain a TableLayoutPanel with Buttons inside of it. I can use a MouseWheel to scroll the Panel fine, no matter where my cursor is. Using a touchscreen, I can only scroll the Panel when my finger slides over the empty space around my TableLayoutPanel, not within the TableLayoutPanel itself.

Is there a way to pass through anything besides a MouseClick to the underlying Panel?

Ignoring the TableLayoutPanel for now, here is a simplified example of what I’ve been trying with a Panel and tall Button.

Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    Dim p As New Panel
    With p
        .Top = 0
        .Left = 0
        .Width = Me.ClientSize.Width
        .Height = Me.ClientSize.Height
        p.BackColor = Color.LightBlue
        .HorizontalScroll.Maximum = 0
        .AutoScroll = False
        .VerticalScroll.Visible = False
        .AutoScroll = True
    End With
    Me.Controls.Add(p)
    Dim b As New MyButton
    With b
        .Top = 0
        .Left = 0
        .Width = 400
        .Height = 1000
        b.BackColor = Color.LightCoral
    End With
    AddHandler b.Click, Sub() MessageBox.Show("Clicked!")
    p.Controls.Add(b)
End Sub
Private Class MyButton
    Inherits Button
    Protected Overrides Sub WndProc(ByRef m As Message)
        Dim HTTRANSPARENT As Integer = -1
        Dim WM_LBUTTONDOWN As Integer = &h301
        Dim WM_VSCROLL As Integer = &h215
        Dim WM_MOUSEMOVE As Integer = &h300
        Dim WM_MOUSEWHEEL As Integer = &h30A
        Dim WM_NCMOUSEHOVER As Integer = &h3A0
        Dim WM_MOUSEHOVER As Integer = &h3A1
        If m. Msg = WM_VSCROLL _
        OrElse m.Msg = WM_MOUSEMOVE _
        OrElse m.Msg = WM_MOUSEWHEEL _
        OrElse m.Msg = WM_NCMOUSEHOVER _
        OrElse m.Msg = WM_MOUSEHOVER Then
            m.Result = CType(HTTRANSPARENT, IntPtr)
        End If
        MyBase.WndProc(m)
    End Sub
End Class
End Class
  • vb.net
  • winforms
  • scrollbar
  • panel
  • touchscreen







Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Post as a guest

Email

Required, but never shown

Post as a guest


Email

Required, but never shown






Starting a debug session for a UWP app — Visual Studio (Windows)

  • Article
  • Reading takes 7 minutes

Applies to: Visual StudioVisual Studio for Mac Visual Studio Code

This article describes how to start a Visual Studio debug session for a UWP app. UWP apps can be written in XAML and C++, XAML, and C#/Visual Basic. To start debugging your UWP app, set up a debug session and choose how the app will launch. nine0017

Note

Beginning with Visual Studio 2019, HTML and JavaScript UWP apps are no longer supported.

Starting debugging from the Visual Studio toolbar

The easiest way to set up and start debugging is the standard Visual Studio toolbar.

  1. From the Configuration drop-down list on the Standard toolbar, select Debug .

  2. nine0003

    From the drop-down list Platform , select the target platform to build.

  3. Select the debug target from the drop-down list next to the green arrow. You can select the local computer, a directly connected device, a local Visual Studio simulator, a remote device, or an emulator.

  4. To start debugging, on the toolbar, click the green arrow Start or select Debug > Start debugging or press F5 .

    Visual Studio builds and runs an application with a debugger attached.

Debugging continues until a breakpoint is reached, manual execution pauses, an unhandled exception, or the application terminates.

Deployment target settings

The debug target can be set on the Visual Studio toolbar or on the project’s debug property page. Choose one of the following options. nine0017

name Description
Local computer Debugging an application in the current session on the local computer.
Simulator Debugging an app in the Visual Studio simulator for UWP apps. The simulator is a desktop window that simulates device functionality that is not available on the local computer, such as touch input and device rotation. This option is only available if the value is The minimum target platform version is less than or equal to the version number of the operating system on the local machine. For more information, see Run UWP apps in the simulator.
Remote computer Debugging an application on a device connected to the local computer over a network or Ethernet cable. The Remote Tools for Visual Studio must be installed and running on the remote device. For more information, see Run UWP apps on a remote computer. nine0086
Device Debugging an application on a connected USB device. The device must be unlocked by the developer and the screen must be unlocked.
Mobile device emulator Load the emulator specified in the emulator name, deploy the application, and start debugging. Emulators are only available on computers that support Hyper-V.

Debugging setting in project properties page

To configure advanced debugging options, use the project’s debugging property page.

Opening Debug Properties:

  1. In Solution Explorer , select the project and click the Properties icon, or right-click the project and select Properties .

  2. In the Properties panel in the left pane, do the following:

Debugger selection

By default, in C# and Visual Basic applications, Visual Studio debugs managed code. You can choose to debug other or additional types of code. You can also set Debugger type for all background tasks that are part of the project.

By default, in a C++ application, Visual Studio debugs native code. You can choose to debug a specific type of code instead of or in addition to native code.

Specifying code types for debugging

  • For C# and Visual Basic applications, select one of the following debuggers from the drop-down lists Application type and Background process type under Debugger type on the property page Debug

  • For C++ applications, select one of the following debuggers from the drop-down lists Debugger type on the property page Debugging .

name Description
Managed code only Debugging managed code in an application. JavaScript code and native C/C++ code are ignored.
Machine code only Debugging native C/C++ code in an application. Managed code and JavaScript code are ignored.
Mixed (driven and machine) Debugging native C/C++ and managed code in an application. JavaScript code is ignored. In C++ projects, this setting is called Steered and machined .
Scenario Debugging JavaScript code in the application. Managed code and native code are ignored.
Machine code with script Debugging native C/C++ and JavaScript code in an application. Managed code is ignored. Only available in C++ projects or background tasks.
GPU only (C++ AMP) Debugging native C++ code that runs on a graphics processing unit (GPU). Only available in C++ projects. nine0086

Disable network loopback (optional)

For security reasons, a standard installed UWP app is not allowed to make network calls to the device on which it is installed. Visual Studio excludes deployed applications from this rule by default, so you can test communication procedures on a single machine. Before you release your application, you must test it without this exception.

Remove network loopback rule exception:

  • For Visual C# and Visual Basic applications, clear the Allow loopback on LAN check box in the Launch Options section of the Debugging property page .

  • For C++ applications, select No in the list Allow LAN Loopback in the property page Debugging .

  • nine0013

    Reinstall application when debugging starts (optional)

    To diagnose installation problems with a C# or Visual Basic application, select Uninstall and reinstall my package on the property page Debug . This option allows you to recreate the original installation when you start debugging. This option is not available for C++ projects.

    Configure authentication settings for remote debugging

    Default when option 9 is selected0015 Remote computer Deployment target requires Windows credentials to run the remote debugger. You can change this authentication requirement.

    Authentication mode Generic (Unencrypted protocol) is for IoT devices, Xbox and HoloLens, Windows 11 PCs, and Windows 10 PCs with Creators Update or later.

    Change authentication method

    • For C# and Visual Basic applications, on the Debug property page , select Remote computer for Target device . Then select No or Generic (unencrypted protocol) for the Authentication mode option.

    • For C++ applications, select Remote computer under Debugger to run on property page Debug . Then select No authentication or Generic (unencrypted protocol) for the Authentication type option.

    Attention!

    Running the remote debugger in mode No verification or Generic (unencrypted protocol) Network security is not ensured. Choose these types only for trusted networks that are definitely not at risk for malicious code or malicious traffic. nine0017

    Debug launch options

    Selecting Debug > Start Debugging or pressing F5 Visual Studio launches the application with a debugger attached. Execution continues until a breakpoint is reached, execution is manually suspended, an unhandled exception, or the application terminates.

    Start debugging with delayed application launch

    By default, Visual Studio starts the application immediately when you start debugging. An application can also be configured to run in debug mode, but start it with a different method than the debugger. For example, you may need to debug launching an application from menu Start Windows or debug a background process in an application. When this option is selected, the application runs in the debugger at startup.

    Disable automatic launch of the application

    • For C# and Visual Basic applications, select Do not run, but debug my code when I open in the Launch options section of the property page Debugging .

    • For C++ applications, select No in the drop-down list Launching the application in the property page Debug .

    For more information about debugging background tasks, see Raising Suspend, Resume, and Background Events for UWP Apps.

    Debug an installed or running UWP app

    To debug a UWP app that is already installed or running on a local or remote device, you can use option Debug installed application package . The app might have been installed from the Microsoft Store, or it might not be a Visual Studio project. For example, an application might have a custom build system that doesn’t use Visual Studio projects and solutions.

    You can run an installed application immediately, or you can set it to run in the debugger when launched using another method. For more information, see Raising Suspend, Resume, and Background Events for UWP Apps. nine0017

    To run an installed or running UWP application in the debugger, select Debug > Other Debug Targets > Debug Installed Application Package . For more instructions, see Debugging an Installed Application Package.

    Attaching a debugger to a running Windows 8.x app

    To attach a debugger to a Windows 8 or later Store app, you must use the Debug Package Manager and configure the app to run in debug mode. The Debuggable Package Manager is installed with the Remote Debugging Tools for Visual Studio. nine0017

    1. Install the Remote Debugging Tools for Visual Studio on the device where the application is installed. For more information, see Installing Remote Installation Tools.

    2. On the Windows Start screen, search for and run Debuggable Package Manager .

      A PowerShell window configured to work with the AppxDebug cmdlets is displayed.

    3. Specify the PackageFullName of the application. nine0017

      1. To see a list of all apps with the PackageFullName ID, type Get-AppxPackage at the PowerShell command prompt.

      2. At the PowerShell command prompt, type Enable-AppxDebug , where is the PackageFullName of the application.

    4. Select Debug > Attach to process .

    5. nine0003

      In the Attach to Process dialog box, specify the remote device in the Connection target field.

      You can enter a name for the device, select it from the drop-down list in the Connection target field, or select Find to find the device in the Remote Connections dialog box.

    6. To specify the type of code to debug next to the field Append to press Select .

    7. In the Select Code Type dialog, select one of the following:

      • Automatically detect the type of code being debugged or
      • Debug the following types of code and select one or more types of code from the list.
    8. In the Available Processes list, select the application process to debug.

    9. Select Connect .

    Visual Studio attaches a debugger to a process. Execution continues until a breakpoint is reached, execution is manually suspended, an unhandled exception, or the application terminates.

    See also

    • Debugging applications in Visual Studio

    Working with the console and the Console class in VB.NET

    Last updated: 10/30/2015

    To work with the console in Visual Basic.NET, enter some data and, conversely, display something on the screen, we need enable class
    console. In previous topics, a number of his methods have already been used, in particular, method WriteLine for
    console output. Now let’s analyze this class and its methods in more detail.

    When working with the console, we can use the following methods of the Console class:

    • Beep: beeps

    • Clear: clears the console window

    • WriteLine: outputs a line of text with a newline

    • Write: prints a line of text without a newline

    • ReadLine: reads the text entered by the user

    • Read: reads a single entered character as a numeric code for that character

    • ReadKey: Reads the pressed keyboard key ( Dim key As ConsoleKeyInfo = Console. ReadKey() )

    The Console class also defines a number of properties with which we can change the display of the console window:

    • BackgroundColor: console background color

    • ForegroundColor: console font color

    • BufferHeight: console buffer height

    • BufferWidth: console buffer width

    • Title: console title

    • WindowHeight and WindowWidth: console height and width respectively

    Let’s write a small application. It will take two numbers entered by the user and display their sum. The application will
    have the following code:

    Module Module1

    SubMain()

    ' Set font color to red
    Console.ForegroundColor = ConsoleColor.Red
    Console.WriteLine("Enter console color (blue or green):")
    Dim color As String = Console.ReadLine()
    If(color="blue") Then
    Console.ForegroundColor = ConsoleColor. Blue
    ElseIf(color="green") Then
    Console.ForegroundColor = ConsoleColor.DarkGreen
    End If
    Console.WriteLine("Color selected: {0}", color)
    Console.ReadLine()
    end sub
    End Module
    nine0581

    First, set the console font color. All available colors are stored in the ConsoleColor enum .

    Then we prompt the user to enter a color and then we get the entered value using the Console.ReadLine() method

    Next, we reset the color and display the previously entered value.

    The second call to the Console.WriteLine method renders formatted output. That is, we can set several different values ​​of the most
    different types and then put them instead of placeholders in a string. Expression {0} is a placeholder indicating that instead of
    you will need to put the first parameter of the method (since the count starts from zero). But you can also use more parameters:

    Dim num1 As Integer = 3
    Dim num2 As Integer = 5
    Console.