Search_Blog

Blog_Archive

|
KHSW Soft Blog

|
Author: |
Ken Huysmans |
Created: |
2008-11-08T10:35:21 |
|
|
Some thoughts about .NET, programming and software in general |
By Ken Huysmans on
2006-03-08T11:16:56
You just have finished your application, the only thing you need is an icon. You don't have icons on your machine and you don't have the graphical skills to create one. But... you have an image on your PC or you found one on Google (watch out for copyrights!) that could be used, too bad it's not in .ico format.
But since you're a .NET-coder, you can create an application to convert an image to an icon in less then one minute!
Have a look at this demo application.
Create a new Windows Application
Set the value of the AllowDrop property of the form to True
Add this code to the DragEnter event of the form
Private Sub Form1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles MyBase.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Add code to the DragDrop event of the form
Private Sub Form1_DragDrop(ByVal sender As Object,...
Read More »
|
By Ken Huysmans on
2006-03-08T08:27:25
Some months ago I published an article explaining how to copy a file with a progressbar in VB.NET. I would like to thank you all for the great feedback on that article! Some days ago I received a mail with the question how to copy a whole directorystructure while showing the progress. So here's a possible solution. Please have a look at the original article first (http://www.khswsoft.be/Blog/tabid/81/EntryID/12/Default.aspx).
The necessary 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...
Read More »
|
By Ken Huysmans on
2006-01-12T14:15:00
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
|
By Ken Huysmans on
2005-08-03T10:49:02
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 »
|
By Ken Huysmans on
2005-03-25T08:25:42
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>
|
By Ken Huysmans on
2005-02-18T11:27:59
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 »
|
By Ken Huysmans on
2004-11-28T13:51:37
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.
|
By Ken Huysmans on
2004-11-25T11:02:00
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 »
|
By Ken Huysmans on
2004-09-28T10:52:16
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 »
|
By Ken Huysmans on
2004-08-27T08:35:26
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>
|
|