Module Module1 ‘ MCTS70-536/1/1/3 ‘ Extending an existing class ”’ <summary> ”’ A simple base class ”’ </summary> ”’ <remarks></remarks> Public Class Customer Private _naam As String Private _adres As String Private _woonplaats As String Public Property Naam() As String Get Return _naam End Get Set(ByVal value As String) _naam = value End Set End […]
Author: bobnoordam
Demonstration of structures and overriding operators
Module Module1 ‘ MCTS70-536-1-1 ‘ VB.NET ‘ Demonstration of a structure with ‘ an operator (+) ‘ an Override (toString) ‘ Public Structure DemoStruct Private _waarde As Integer ‘ — Read and write initial & current value Public Property Value() As Integer Get Return _waarde End Get Set(ByVal value As Integer) _waarde = value End […]
Demonstration of creating an event handler and attaching to an event
Public Class Form1 ‘ MCTS70-536-1-3 ‘ Registering and handling Events Private t As Timer Private p As ProgressBar Private Sub t_Tick(ByVal sender As Object, ByVal e As EventArgs) p.Value += 1 If p.Value = 100 Then p.Value = 1 End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load […]
Changing the runtime priority of your application
Module Module1 Sub Main() ‘ — Idle time only, the lowest priority. Use with care as your application could get very little cpu ‘ time allocated on a busy system System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Idle ‘ — Below normal priority System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal ‘ — Default priority, equal to other programms System.Diagnostics.Process.GetCurrentProcess().PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal ‘ — High […]
Compressing and decompressing files with GZIPStream or Deflatestream
These samples whow how to compress and decompress files with the build in framework methods. For real world applications consider using something like .netzip from codeplex, since the compression quality from the build in methods is limited. Also, the build in methods will allow you to just compress and decompress a single file. Compressing a […]
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 […]
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 […]
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, […]
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 […]
Update a winforms control from a background thread
This is the absolute minimum you need to update a control on the GUI thread from a background thread. The key here is the line Invoke(new Action<int>(UpdateGuiText), result); Which will invoke an update on the GUI thread from another thread. The interface consists of a single button and a single textbox. Each click on the […]