This blog is moved to
http://amalhashim.wordpress.com

Friday, March 27, 2009

User resizable panel

using System;
using System.Drawing;
using System.Windows.Forms;

public class SizeablePanel : Panel {
private const int cGripSize = 20;
private bool mDragging;
private Point mDragPos;

public SizeablePanel() {
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.BackColor = Color.White;
}

protected override void OnPaint(PaintEventArgs e) {
ControlPaint.DrawSizeGrip(e.Graphics, this.BackColor,
new Rectangle(this.ClientSize.Width - cGripSize, this.ClientSize.Height - cGripSize, cGripSize, cGripSize));
base.OnPaint(e);
}

private bool IsOnGrip(Point pos) {
return pos.X >= this.ClientSize.Width - cGripSize &&
pos.Y >= this.ClientSize.Height - cGripSize;
}

protected override void OnMouseDown(MouseEventArgs e) {
mDragging = IsOnGrip(e.Location);
mDragPos = e.Location;
base.OnMouseDown(e);
}

protected override void OnMouseUp(MouseEventArgs e) {
mDragging = false;
base.OnMouseUp(e);
}

protected override void OnMouseMove(MouseEventArgs e) {
if (mDragging) {
this.Size = new Size(this.Width + e.X - mDragPos.X,
this.Height + e.Y - mDragPos.Y);
mDragPos = e.Location;
}
else if (IsOnGrip(e.Location)) this.Cursor = Cursors.SizeNWSE;
else this.Cursor = Cursors.Default;
base.OnMouseMove(e);
}
}

Alt Key down - Underline not visible

control pannel-> easy of access center -> make the keyboard easier to use-> make it easier to use keyboard shutcuts->underline keyboard shortcuts and access keys".

Thursday, March 19, 2009

PDF to text

http://www.codeproject.com/KB/files/PDF_to_TEXT.aspx

http://www.codeproject.com/KB/string/pdf2text.aspx

http://www.codeproject.com/KB/cpp/ExtractPDFText.aspx?fid=47947&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=51&select=1192500

http://www.tallcomponents.com/

http://www.codeproject.com/showcase/TallComponents.asp

similar thread

it requires that you have the full version of Adobe installed on your PC so that you can gain access to the Adobe APIs (which doesn't technically qualify as a free way to do it). Here is the code I used to read the contents of a PDF. You will have to add a reference to the Adobe APIs in your project:

Dim objPDFPage As AcroPDPage
Dim objPDFDoc As New AcroPDDoc
Dim objPDFAVDoc As AcroAVDoc
Dim objAcroApp As AcroApp
Dim objPDFRectTemp As Object
Dim objPDFRect As New AcroRect
Dim lngTextRangeCount As Long
Dim objPDFTextSelection As AcroPDTextSelect
Dim temptextcount As Long
Dim strText As String
Dim lngPageCount As Long
Dim Fora As Long
objPDFDoc.Open(tbdocdisplaypath.Text)
lngPageCount = objPDFDoc.GetNumPages
For Fora = 0 To lngPageCount - 1
objPDFPage = objPDFDoc.AcquirePage(Fora)
objPDFRectTemp = objPDFPage.GetSize
objPDFRect.Left = 0
objPDFRect.right = objPDFRectTemp.x
objPDFRect.Top = objPDFRectTemp.y
objPDFRect.bottom = 0
' objPDFTextSelection = objPDFDoc.CreateTextSelect(lngPageCount, objPDFRect)
objPDFTextSelection = objPDFDoc.CreateTextSelect(Fora, objPDFRect)
' Get The Text Of The Range
temptextcount = objPDFTextSelection.GetNumText
For lngTextRangeCount = 1 To objPDFTextSelection.GetNumText
doctextdoctext = doctext & objPDFTextSelection.GetText(lngTextRangeCount - 1)
Next
doctextdoctext = doctext & vbCrLf
Next
doctype = "PDF"
objPDFDoc.Close()

Tuesday, March 17, 2009

How to start a command prompt in a folder in Windows Server 2003, Windows XP, and Windows 2000

Modify the Registry Manually

To add the Command Prompt command to the shortcut menu:
  1. Click Start, click Run, type regedit, and then click OK.
  2. Locate the following registry key:
    HKEY_CLASES_ROOT\Directory\shell
  3. Right-click the shell key, point to New, and then click Key.
  4. Name the new key OpenNew.
  5. Click the OpenNew key, and then double-click the Default value in the right pane.
  6. Change the value to Command Prompt. Click OK.
  7. Right-click the OpenNew key, point to New, and then click Key.
  8. Name the new key Command.
  9. Double-click the Default item in the right pane.
  10. Change the value to cmd.exe /k cd %1.
If you have multiple drives on your computer, you can add a similar command to the shortcut menu that appears when you right-click a drive in Windows Explorer or My Computer. The steps to do this are the same as those for creating the Command Prompt command, except that you use the HKEY_CLASSES_ROOT\Drive\shell registry key as the starting point. Also, change the value of the Default value in the HKEY_CLASSES_ROOT\Drive\shell\OpenNew\Command key to cmd.exe /k.

Modify the Registry with a Script

To add the Command Prompt command to the shortcut menu:
  1. Copy the following text to a file named Cmdhere.reg:
    Windows Registry Editor Version 5.00
    [HKEY_CLASSES_ROOT\Directory\shell\OpenNew]
    @="Command Prompt"
    [HKEY_CLASSES_ROOT\Directory\shell\OpenNew\Command]
    @="cmd.exe /k cd %1"
  2. Save the Cmdhere.reg file.
  3. Double-click the Cmdhere.reg file to automatically add the registry entries.

Play audio files using DirectX

Imports Microsoft.DirectX
Imports Microsoft.DirectX.AudioVideoPlayback
Public Class Form1
Private Sub Play_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Play.Click
Dim a As Audio
a = New Audio("C:\Users\User\Documents\Music_file_1.wma", True)
a.Play()
End Sub
End Class

Friday, March 13, 2009

File Association

1. Easy way is through the Visual Studio Setup & Deployment project.

How to manually set the file association?

Imports System
Imports Microsoft.Win32

1. Determine an arbitrary file type name.

Public Sub SetFileType(ByVal extension As String, ByVal FileType As String)
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.CreateSubKey(extension)
ext.SetValue("", FileType)
End Sub

2. Write this file type name to the Registry, associating it with your extension.

Public Sub SetFileType(ByVal extension As String, ByVal FileType As String)
Dim rk As RegistryKey = Registry.ClassesRoot

Dim ext As RegistryKey = rk.CreateSubKey(extension)
ext.SetValue("", FileType)
End Sub

3. Add a description for your file type.

Public Sub SetFileDescription(ByVal FileType As String, ByVal Description As String)
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.CreateSubKey(FileType)
ext.SetValue("", Description)
End Sub

4. Add actions.

Public Sub AddAction(ByVal FileType As String, ByVal Verb As String, ByVal ActionDescription As String)
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.OpenSubKey(FileType,True).CreateSubKey("Shell").CreateSubKey(Verb)
ext.SetValue("", ActionDescription)
End Sub

5. Setting Action to do something.

Public Sub SetExtensionCommandLine(ByVal Command As String, ByVal FileType As String, ByVal CommandLine As String, Optional ByVal Name As String = "")
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.OpenSubKey(FileType).OpenSubKey("Shell").OpenSubKey(Command, True).CreateSubKey("Command")
ext.SetValue(Name, CommandLine)
End Sub

Make sure you set “CommandLine” exactly as it should be as if you typed in the line from the MS-Dos or from the Command Prompt. Instead of using a File name, however, use “%1”.

6. To set a default action

Public Sub SetDefaultAction(ByVal FileType As String, ByVal Verb As String)
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.OpenSubKey(FileType).OpenSubKey("Shell")
ext.SetValue("", Verb)
End Sub

7. Setting icon

Public Sub SetDefaultIcon(ByVal FileType As String, ByVal Icon As String)
Dim rk As RegistryKey = Registry.ClassesRoot
Dim ext As RegistryKey = rk.OpenSubKey(FileType)
ext.SetValue("DefaultIcon", Icon)
End Sub

Get URL from webbrowser control

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
TextBox1.Text = WebBrowser1.Document.Title
TextBox2.Text = WebBrowser1.Url.ToString
End Sub

Private Sub WebBrowser1_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles WebBrowser1.Navigated
TextBox1.Text = WebBrowser1.Url.AbsoluteUri
End Sub