Iuvo

How to : get Application Directory

Posted in C# by محمود on May 22, 2009

C#:

string path1 =Path.GetDirectoryName(Application.ExecutablePath);



Resources:

Application.ExecutablePath Property

Gets the path for the executable file that started the application, including the executable name.

Pasted from <http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx>

Clipboard Viewer

Posted in Windows by محمود on April 10, 2009

Microsoft Windows has a utility to work with clipboard:

ClipBook Viewer

you can see the current contents of clipboard and clear it ,or save the contents in a file and use them.

you can access to this utility by typing its name in Start Menu/Run:

Clipbrd

Resources:

How to quickly open the ClipBook Viewer

ClipBook Viewer

Tagged with: ,

How to : Automate a network connection

Posted in API, Command Line, Windows by محمود on April 10, 2009

you can automate connecting and disconnecting by command line tool rasdial .

you can use a batch file to run the command automatically for you.

Example:

rasdial “ConnectionName” “UserName” “Password”

and create a .bat file and put that line in it.whenever you run this batch file your network connection will be established.

you can use rasdial and batch files to customize you network connecting.

if you are a developer and want to do a similar job in your program you can use RasDial API.

Resources:

Rasdial

Using batch files

Windows API:

RasDial Function

Tagged with: , ,

How to : Monitor Clipboard changes

Posted in .NET, API, C#, Windows by محمود on April 9, 2009

As you know(or maybe you don’t know) there is no way to get notified when something is copied to clipboard in .NET.So we should use Windows API to do that.

If you want to know how clipboard is working read it in MSDN:

Clipboard

there is an example in C#:

Create a Windows Clipboard Monitor in C# using SetClipboardViewer

My Sample:

MSDN has many video tutorial that called How Do I?.They are really useful,but if you don’t have proper internet connection it’s a pain to download these videos.I should wait several hours to download just one of these videos (my connection speed is 64K ; in my country Iran , this is like a broadband :D

I have to download and archive these videos before I want to use them.But sometimes I don’t know which videos I have downloaded (the real pain is here) and I have to search my archives.

for example if the video link is :

http://download.microsoft.com/download/7/2/5/725c1541-601a-4e4c-bc2f-9a7205358134/WinVideo-Winforms-MenusToolbarsandStatus.wmv

I should take the file name and search it in my archives.

for the above link the file name is:

WinVideo-Winforms-MenusToolbarsandStatus

So I wrote a simple program to get back the file name.When you copy the download link to clipboard the program detects that there is something new in clipboard and checks if the clipboard content is a URL and if it is,it gets the file name and copies it back to clipboard.

Download : C# Sample

Resources:

Clipboard

SetClipboardViewer Function

ChangeClipboardChain Function

SendMessage Function

WM_CHANGECBCHAIN Notification

WM_DRAWCLIPBOARD Notification

How to: Search Strings Using Regular Expressions (C# Programming Guide)

Tagged with: , ,

How to : Programmatically change Connection String

Posted in .NET, C#, Database, SQLite by محمود on April 1, 2009

I want to change Connection String  programmatically:

the key point is to write some code in Settings.cs file.for example I used a Property:

        public string RuntimeChangeConnectionString
        {
            set { this["DataBaseConnectionString"] = value; }
        }

and then you can use this property in your code.

Here is my sample to do that.

it will create 2 SQLite file in your “My Documents” but it uses one connection string,you can change the connection string to load different databases.

you need SQLite to run the sample.

you may need these resources too:

Connection strings for SQLite

Customizing the connection string for TableAdapters

Properties (C# Programming Guide)

Download Sample: C#

Tagged with: , ,

How to : Convert Image to Byte Array and Byte Array to Image

Posted in .NET, C# by محمود on March 30, 2009

Image to Byte Array:

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
 MemoryStream ms = new MemoryStream();
 imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif);
 return  ms.ToArray();
}

Byte Array to Image:

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

Source : CodeProject

Tagged with:

How to : use the SHGetFileInfo function to get the icons that are associated with files in Visual C# .NET

Posted in .NET, API, C# by محمود on March 29, 2009
Tagged with: ,

Walkthrough: Inheriting from a Windows Forms Control with Visual C#

Posted in .NET, C# by محمود on March 29, 2009

مثلا می خوام بعضی از قابلیت های Button رو تغییر بدم و چیزایی بهش اضافه کنم باید کلاس اون کنترل رو که دارم درست می کنم subclass کنم به کلاس Button .

و یک مثال دیگه : نمی شه فونت یه tooltip رو تغییر داد.خوب اگه خواستیم این کار رو انجام بدیم باید کلاسمون subclass از کلاس tooltip باشه.

Source : MSDN

Tagged with:

How to : create a parameter query in Access

Posted in Access, Database by محمود on March 28, 2009

Example:

SELECT Info.[FName], Info.[LName]
FROM Info
WHERE LName Like "*"+[Last Name]+"*";

Related articles:

Using Parameter Queries

How to create a parameter query in Access 2002

My sample:

How to create a parameter query in Access.zip

Tagged with:

How to : Add open command prompt here to windows explorer

Posted in Registry, Windows by محمود on March 26, 2009

run regedit

go to

HKEY_LOCAL_MACHINE/Software/Classes/Folder/Shell

and create a key called “Command Prompt”.

set the default string to whatever you want to appear in right click.

Create a new key within your newly created command prompt named "command," and set the default string to

cmd.exe /k pushd %1
 

3-26-2009 1-52-26 PM

Tagged with: