@bobnoordam

Category: VB.NET

Reading screen pixels from the main screen, and specific other application windows

Reading from the full screen This code sample reads the pixel of the screen that the mouse points to, and changes the form’s background color to match that pixel’s color. Note that this code attaches to the main screen, and not to the window of a specific application. If you want to attach to a specific application’s window and read inside that, the sample lower on the page applies. Public Class Form1 Public Declare Function […]

Making a form transparant

This code sample displays a method to seemingly draw anywhere freely on the screen. The key to this technique is the TransparanceKey offered by the .net framework, which makes this a fairly straightforward task. To make the background of a form transparant, the *only* thing we need to do is this; oDrawform.AllowTransparency = True oDrawform.TransparencyKey = oDrawform.BackColor If we add code to that to hide the control boxes, title bar and maximize the form we […]

Creating a superimposed centered watermarked image at runtime

”’ <summary> ”’ Watermarks the file sOrinignalfilehandle with the content of sWatermarkfilehandle. The resulting ”’ watermarked picture is written to sOriginalfilehandle. ”’ ”’ Returns 1 for success, -1 if the operation can not be performed because of size mismatches ”’ </summary> ”’ <param name=”sOriginalfilehandle”></param> ”’ <param name=”sWatermarkfilehandle”></param> ”’ <remarks></remarks> Private Function WaterMarkFile(ByVal sOriginalfilehandle As String, ByVal sWatermarkfilehandle As String) As Integer Dim oCanvas As Bitmap Using oFs As New FileStream(sOriginalfilehandle, FileMode.Open, FileAccess.Read) Using oSourceimage As […]

Static class implementing a filecopy function while showing a progress bar

Imports System.IO ”’ <summary> ”’ Copy a file from the source to the target location, and shows a progressbar to the user ”’ ”’ Call: ”’ ”’ CopyFileWithBar.DoCopy(“c:\somesource.bin”,”c:\sometarget.bin”) ”’ ”’ Returns FALSE if the source file does not exists ”’ Returns TRUE if the copy succeeded ”’ You need to trap exceptions for e.g. non writable target files in the wrapping code using this class. ”’ ”’ H.P. Noordam (b.noordam@nhcoding.nl) ”’ ”’ </summary> ”’ <remarks></remarks> […]

Retrieving data from a hidden GridView column

In Visual Studio Winforms applications you can set a column to hidden, and still use it to retrieve data from. If you set a column to inviisble in an ASP.NET application, the column is *not* available to get data from. If you set a column to invisible ad design time, the column is never bound to the data, and thus not availavle in your web application. thus, the solution is to set the column to […]

Determine response time from an ip ping

‘ — ping the ip adress in the string s_ipaddr, and get ‘ the response time in the int32 n_response ‘ imports system.net.networkinformation Dim ping As New System.Net.NetworkInformation.Ping Dim reply As System.Net.NetworkInformation.PingReply reply = ping.Send(s_ipaddr) If reply.Status = IPStatus.Success Then ‘ — handle reachable here MsgBox(“ping time ” & reply.RoundtripTime) Else ‘ — handle non reachable here End If

Enumerating the active forms within an application

VB.NET Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘ — Build a list of all active forms, and display it to the user Dim activeforms As String = String.Empty For Each item As Form In Application.OpenForms activeforms = String.Format(“{0}{1}{2}”, activeforms, item.Name, vbCrLf) Next MsgBox(String.Format(“The names of the active forms are:{0}”, activeforms)) ‘ // End Sub

Monitoring the file system for changes

This code sample sets up a handler to monitor the c:\ disk for changes in any file’s size, and report those changes to the console. Imports System.IO Module Module1 ”’ <summary> ”’ Display the change events detected by the file system watcher on the console ”’ </summary> ”’ <param name=”sender”></param> ”’ <param name=”e”></param> ”’ <remarks></remarks> Private Sub DisplayChangeEvent(ByVal sender As Object, ByVal e As FileSystemEventArgs) Console.WriteLine(“{0}{1} {2} “, e.FullPath, e.Name, e.ChangeType) End Sub ”’ <summary> […]

Creating a threaded windows service

Creating the project and installation procedures Start Visual Studio, and choose the windows service project type. And empty objects panel appears. Drag any controls you will use onto this panel. Many examples use a timer control, but i choose a different concept for two reasons; Timer controls can be problematic in windows services. The default timer control of a forms application is bugged, and will not – or not always fire. Usage of a system.threading […]

« Previous Page