28 November 2008

C# Textbox Auto Scroll To End ScrollToCaret Scrolling Textbox

Many of my sample C# codes,
I use textbox to write the results.

When textbox is multiline property set to true, and when I insert text into it,
I want it to auto scroll to the last line.

Here is a simple way to auto scrolling textbox.
 textbox1.SelectionStart = textbox1.Text.Length;
textbox1.ScrollToCaret();
textbox1.Refresh();
Textbox SelectionStart will force the textbox control to select the last part of the text,
and ScrollToCaret() function will auto scroll textbox to the end.

C# The process cannot access the file because it is being used by another process

The process cannot access the file because it is being used by another process.
This error message is mostly comes up,
when you try to access a file which is opened by another process.

You may open an image file in one of your form in a picturebox with using ImageFromFile or something.
I mostly use memorystream to open an image.
After read it in byte[] write it into a stream and close it.

You can check whether a file is being used or not with a simple function.
Try to open a file with none share.
 public bool IsFileUsedbyAnotherProcess(string filename)
{
try
{
File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.None);
}
catch (System.IO.IOException exp)
{
return true;
}
return false;

}
This function will return true if
the file because it is being used by another process or not.

27 November 2008

C# Convert Hexadecimal to Binary String Conversion

There is no need to code tons of codes, loops, to convert hex to binary string. Convert.ToInt32 function is very useful for this purpose.
Let's convert the "A" character to binary format.
private string hex2binary(string hexvalue)
{
string binaryval = "";
binaryval = Convert.ToString(Convert.ToInt32(hexvalue, 16), 2);
return binaryval;
}
When we call hex2binary("A"); it will return "1010" similar samples below;

hex2binary("1a"); will return "11010";
hex2bianry("1a2c"); will return "1101000101100"; and so on.

Keep in mind that this hex to binary conversion style uses 32 bit integer number.

25 November 2008

C# System Tray Minimize To Tray With NotifyIcon

Minimize application form to system tray is done
with the NotifyIcon control in Visual Studio.

NotifyIcon is in the System.Windows.Forms namespace.
Drag and drop a NotifyIcon control to your form.
To send your application form into the system tray,
we simple handle the form re-size event.
private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == this.WindowState)
{
mynotifyicon.Visible = true;
mynotifyicon.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
mynotifyicon.Visible = false;
}
}
We can also set BallonTipIcon, BallonTipText, BallonTipTitle and Icon ,
for our NotifyIcon control.
 mynotifyicon.BallonTipText = "My application still working...";
mynotifyicon.BallonTipTitle = "My Sample Application";
mynotifyicon.BallonTipIcon = ToolTipIcon.Info;

Favicon Generator How To Add Favicon to Your Website ico

favicon Favicons are the little images, icons that appears in left of the browser address bar and bookmarks menu.

Favicon
size is 16x16 pixel. Favicons are very important feature, visitors may remember a website from its favicon.
Favicon
is kind a symbol of a website.
How to add a favicon in your website html.
  • Create a favicon online easily visit the link below and create your favicon online.
FavIcon Generator Online
  • Upload your favicon into your hosting site.
  • Add the html tag below into your website, between head tags.
<link href="images/favicon.ico" rel="shortcut icon" />
Done.

Other favicon generator resources:

http://www.favicon.cc/
http://www.degraeve.com/favicon/
http://www.favicon.co.uk/

C# and ASP.NET Create Table Dynamically

In the run-time sometimes we have to create table dynamically.

From the namespace System.Data DataTable DataColumn classes we can easily create table dynamically in C# and also in ASP.NET.
using System.Data;

// Create a DataTable instance
DataTable dTbl = new DataTable("myDynamicTable");

// Create a DataColumn instances

DataColumn dValue = new DataColumn();
DataColumn dMember = new DataColumn();

dValue.ColumnName = "Id";
dValue.DataType = Type.GetType("System.Int32");

dMember.ColumnName = "Name";
dMember.DataType = Type.GetType("System.String");

// Add these DataColumns into the DataTable

dTbl.Columns.Add(dValue);
dTbl.Columns.Add(dMember);
After you create table dynamically, you can add rows into it.
It is a good way to create DataRow from the table we create, with the function NewRow().
// Create a DataRow Instance from the table we create above, with NewRow();

DataRow myrow = dTbl.NewRow();

myrow["Id"] = 1;
myrow["Name"] = "Tux";

// Add the row into the table

dTbl.Rows.Add(myrow);
That's all for creating table dynamically in C# and also ASP.NET.

Meaning of De parvis grandis acervus erit

When you open the Google toolbar about box, you may see this text there.
De parvis grandis acervus erit.


After I googling, I found several possible meanings;
  • Out of small things a great heap will be formed.
  • Little by little there's so much done.
  • Tall oaks from little acorns grow.
  • Small things will make a large pile.
I really love this quote, I think it summarize the Google great services clearly, their passion and simplicity beyond the great work and service. Please let me know if this translations are incorrect or any other suggestions.