How to : get Application Directory
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
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 : Automate a network connection
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:
Windows API:
How to : Monitor Clipboard changes
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:
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:
How to: Search Strings Using Regular Expressions (C# Programming Guide)
How to : Programmatically change Connection String
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:
Customizing the connection string for TableAdapters
Properties (C# Programming Guide)
Download Sample: C#
How to : Convert Image to Byte Array and Byte Array to Image
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
How to : use the SHGetFileInfo function to get the icons that are associated with files in Visual C# .NET
we should use SHGetFileInfo Function (Win32 API)
Walkthrough: Inheriting from a Windows Forms Control with Visual C#
مثلا می خوام بعضی از قابلیت های Button رو تغییر بدم و چیزایی بهش اضافه کنم باید کلاس اون کنترل رو که دارم درست می کنم subclass کنم به کلاس Button .
و یک مثال دیگه : نمی شه فونت یه tooltip رو تغییر داد.خوب اگه خواستیم این کار رو انجام بدیم باید کلاسمون subclass از کلاس tooltip باشه.
Source : MSDN
How to : create a parameter query in Access
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
How to : Add open command prompt here to windows explorer
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
leave a comment