Byte Array Strings

String Direct To Byte Array String sTemp; Byte[] TxData; sTemp = "Hello"; TxData = System.Text.Encoding.UTF8.GetBytes(sTemp); Byte Array To String System.Diagnostics.Debug.WriteLine("CommsByteArray: " + Encoding.UTF8.GetString(CommsByteArray));   string sTemp = Encoding.ASCII.GetString(new byte[]{ 41 }); Remove Nulls From The String sTemp = sTemp.Replace("\0", "");  

Read More

.Using List

Unlike arrays, the List collection type resizes dynamically.  If you are working with data where you would need to be resizing an array a lot then use a list instead.  It is ideal for linear collections that you don’t need to adjust using an index. Good resources http://www.dotnetperls.com/list You need this namespace Declaring Adding Objects […]

Read More

Write New File

using System.IO; Save As Dialog Box String SaveAsFilename; //If last directory is not valid then default to My Documents if (!Directory.Exists(Path.GetDirectoryName(LastFileDirectory))) LastFileDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //—– SAVE FILE DIALOG BOX —– SaveFileDialog SelectFileDialog = new SaveFileDialog(); SelectFileDialog.Filter = "Comma Separated Values (*." + MY_FILE_EXTENSION + ")|*." + MY_FILE_EXTENSION; //"txt files (*.txt)|*.txt|All files (*.*)|*.*" SelectFileDialog.FilterIndex = 1; […]

Read More

.General Form Usage

Opening a form frmConfiguration ConfigForm = new frmConfiguration(); ConfigForm.PassedValue1 = "This is a string I'm passing"; //TO OPEN AS A DIALOG FORM: ConfigForm.ShowDialog(); //or if (ConfigForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) else if (ConfigForm.DialogResult == System.Windows.Forms.DialogResult.Cancel) //TO OPEN NOT AS A DIALOG FORM: ConfigForm.Show(); Closing a form Close(); //or this.Close(); Closing a form from the Form Load Event […]

Read More

Using Checked List Box

General Setup To cause the items in the CheckedListBox to be checked when you click them the first time, set the control's CheckOnClick property to True. Clear All Items clbMyCheckedList.Items.Clear(); Clear Individual Items clbMyCheckedList.Items.RemoveAt(0); //Specify index position Add New Items clbMyCheckedList.BeginUpdate(); //Stop painting of the ListBox as items are added clbMyCheckedList.Items.Add("Entry 1", true); clbMyCheckedList.EndUpdate(); How […]

Read More

Playing Audio With WMPLib.WindowsMediaPlayer

You need to use WMPLib.WindowsMediaPlayer if yuo want to play non .wav files otehrwise you'll have to resort to a third party library. Play File Example //Play the file WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer(); wplayer.URL= TemporaryFilename; wplayer.controls.play(); Play From Stream You can't! Play Using Same Temporary File Example Global object WMPLib.WindowsMediaPlayer wplayer; Play the file //WindowsMediaPlayer […]

Read More

INSERT OR REPLACE

INSERT new record or REPLACE existing record if the primary key already exists Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @"INSERT OR REPLACE INTO tblBookCards (CardId, CardPicture) VALUES (@CardId, @CardPicture)"; Command1.Parameters.AddWithValue("@CardId", CardId); if (BookCardImage.Length > 0) Command1.Parameters.AddWithValue("@CardPicture", BookCardImage); else Command1.Parameters.AddWithValue("@CardPicture", DBNull.Value);    

Read More

Using ListBox

List Box With More Options Need columns, colouring, icons etc? Use a List View Creating a List Box SelectionMode – Decide how many lines may be selected at a time by the user MultiColumn – Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling […]

Read More

DELETE queries

DELETE Example //—– DO DELETE —– Command1 = new System.Data.SQLite.SQLiteCommand(Connection1); Command1.CommandText = @"DELETE FROM tblBookLanguages WHERE LanguageId = @LanguageId"; Command1.Parameters.AddWithValue("@LanguageId", LanguageId); Command1.ExecuteNonQuery();  

Read More

.PictureBox General

SizeMode Normal – image is positioned in the upper-left corner of the PictureBox, and any part of the image that is too big for the PictureBox is clipped. StretchImage – image will stretch or shrink to fit the PictureBox. Zoom – the image will be stretched or shrunk to fit the PictureBox but the aspect ratio in […]

Read More