You are here : Blog
Search_Blog Minimize

KHSW Soft Blog Minimize
Author: Ken Huysmans Created: 2008-11-08T10:35:21
Some thoughts about .NET, programming and software in general

If you use the default TreeView in Visual Studio 2003, the SelectedNode property doesn't always return the correct selected node in the Click event.

If you inherit from the TreeView, you can override the OnMouseDown event with this code:

Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
Me.SelectedNode = Me.GetNodeAt(New Point(e.X, e.Y))
MyBase.OnMouseDown(e)
End Sub


Otherwise, you can add this code to your form in the OnClick event of the Treeview:
Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown
TreeView1.SelectedNode = TreeView1.GetNodeAt(New Point(e.X, e.Y))
End Sub

Today I wanted to create a control that could copy files in VB.NET with some progress indication. I did some searches on the Internet and managed to build a working control. However, I would like to share the basics with all of you... First declare some API functions: Private Delegate Function CopyProgressRoutine(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32 Private Declare Auto Function CopyFileEx Lib "kernel32.dll" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal lpProgressRoutine As CopyProgressRoutine, ByVal lpData As Int32, ByVal lpBool As Int32, ByVal dwCopyFlags As Int32) As Int32 Add a button (Button1) to your form and add this code to the Click event: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)...

Read More »

This looks like normal behaviour to me, but recently someone asked how to prevent this as he just called a Javascript function in a hyperlink. Something like this:

<a href="javascript:DoSomething()"><img src="animated.gif" border="0"></a>

He didn't want the animations to stop when clicking that link, so we rewrote this line to:
<a href="#" onclick="javascript:DoSomething();return false"><img src="animated.gif" border="0"></a>

One day you might encounter a user who has done some cleaning (thouroughly) on his PC. Your program crashes because it can't find some necessary files... A reinstall will do the trick, but there's a more user-friendly way to cope with 'deleters'. I'm going to use images in my example, but you could do this with every file you want (since you'll be getting a Stream). Add an image to your project and make sure to put the Build Action to Embedded Resource. Now here's some code to retrieve the image, the function GetEmbeddedImagePath() will return the filename, the function GetEmbeddedImage() will return an Image object. They both need 1 parameter, the name of the image you want to retrieve. Public Shared Function GetEmbeddedImagePath(ByVal imageName As String) As String Dim f, fn As String f = Application.StartupPath If Not f.EndsWith("\") Then f &= "\" f &= "Images\" fn = f & imageName If File.Exists(fn) Then Return fn Else If Not Directory.Exists(f) Then Directory.CreateDirectory(f) End If...

Read More »

This is a question I received a while ago. After an upgrade to Windows XP SP2 the 'My Documents' folder always opened when Windows was started.
I ran msconfig, but couldn't find anything suspicious... After a while I found out there was something wrong with the 'userinit'-key in the registry.

The value of this key (HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\UserInit) was C:\WINDOWS\system32\userinit.exe,C:\WINDOWS\system32\userinit.exe.
Changing this key to only C:\WINDOWS\system32\userinit.exe solved the problem.

If you have a picture as background of your MDI, that picture is not resized when you resize your form. There seems no easy way (like a property) to accomplish this. So I wrote a little piece of code that will create a new image starting from the original background image, but with the dimensions of the main form. Declare a global variable for your form: Private myBackground As Image Add this code to the Resize-event of your form: If myBackground Is Nothing Then myBackground = Me.BackgroundImage End If If Me.ClientSize.Width = 0 Then Exit Sub 'Remark1 Dim bmp As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height, Imaging.PixelFormat.Format24bppRgb) 'Remark2 Dim gr As Graphics = Graphics.FromImage(bmp) gr.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic gr.DrawImage(myBackground, 0, 0, bmp.Width, bmp.Height) Me.BackgroundImage = bmp If you have a statusbar (called myStatus in this example) on the bottom of your form, alter the line marked with 'Remark1...

Read More »

If you want to delete an assembly in the GAC that's still in use, you'll get the message: Assembly 'XXXXXXXXXXX' could not be uninstalled because it is required by other applications. If you have stopped all services and still don't succeed in removing it, try this little trick. - Go to Start > Run - Type regsvr32 -u "C:\Windows\Microsoft.NET\Framework\v1.1.4322\shfusion.dll" - Browse to C:\Windows\Assembly, the 'GAC-view' has gone - Open the GAC-folder - Delete the folder with the name of the assembly you want to remove - Go to Start > Run - Type regsvr32 "C:\Windows\Microsoft.NET\Framework\v1.1.4322\shfusion.dll" Warning: I take no responsability at all, try it at your own risk!

...

Read More »

If you want to close the main browser window, Internet Explorer will popup this messagebox:

"The Web page you are viewing is trying to close the window.
Do you want to close this window?"

Internet Explorer is checking the window.opener object to see if the current window has been opened by another window. If not, it will display this question.

So, the little trick is to make sure that the window.opener object differs from undefined ;-)

<script language="javascript">
function CloseWindow() {
window.opener = 'http://kHSw.blogspot.com';
window.close();
}
</script>

Don't you hate it when a program just reboots Windows without asking after an installation? I do.

Today I found a little program on the web that will prevent this shutdown. It's called Anti-Shutdown by xCAT-Industries. The program itself can be downloaded from http://www.xcat-industries.nl/softwareinfo.php?software=37.

 

When a customer gets a messagebox (for example an errormessage), they mostly take a printscreen, copy this bitmap in a Word-document and send it to my already overloaded mailbox.
Those customers who do think about my mailbox size, are manually typing the text from the messagebox in an email.

It's much easier to just copy the text of the messagebox to the clipboard by pressing
<Ctrl>-<C>.
You'll get something like this (an example coming from the Database Configuration Application of Microsoft Content Management Server):


---------------------------Stop service?---------------------------In order to continue, the IIS service and all dependent services must be stopped. Do you want to stop IIS now? Answering No will exit this program.---------------------------Yes No ---------------------------


Copyright 2007 by KHSW Soft BVBA
Privacy StatementTerms Of Use