image1.Source = new BitmapImage(new Uri(@"C:\IMAGE.JPG"));Additional Reading at :
C Sharp Code
Thursday, April 10, 2014
C# WPF Load Image from file
How to load image WPF:
C# Load Image to PictureBox
How to load image to picturebox:
Method 1 :
Method 1 :
PictureBox1.Image = Image.FromFile(@"C:\IMAGE.JPG");Method 2 :
PictureBox1.Image = New Bitmap(@"C:\IMAGE.JPG");Additional Reading at :
C# Convert Image to byte array (byte[]) or C# convert byte array (byte[]) to Image
Convert Image to byte[] method:
public byte[] imageToByteArray(Image imageIn) { using (var ms = new System.IO.MemoryStream()) { System.Drawing.Imaging.ImageFormat format; switch (imageIn.MimeType()) { case "image/png": format = ImageFormat.Png; break; case "image/gif": format = ImageFormat.Gif; break; default: format = ImageFormat.Jpeg; break; } imageIn.Save(ms, format); return ms.ToArray(); } }Convert byte[] to Image method:
public Image byteArrayToImage(byte[] byteArrayIn) { using (var ms = new System.IO.MemoryStream(byteArrayIn)) { Image returnImage = Image.FromStream(ms); return returnImage; } }Additional Reading at :
Labels:
byte array,
byte[],
C#,
Conversion,
convert,
CSharp,
Image,
ImageFormat,
MemoryStream
Tuesday, August 20, 2013
C# Capturing Keys - KeyPress Event, KeyDown Event or KeyUp Event
Differences of the three:
Sample Code below :-
1.Create a Textbox control.
2.Adding event to your control in form1.designer.cs
get list of key code from keys enum.. link below..
Additional Reading at :
- Keydown: happens when the key is pressed.
- KeyPressed: happens when a key is pressed and then released.
- KeyUp: happens when the key is released.
Sample Code below :-
1.Create a Textbox control.
2.Adding event to your control in form1.designer.cs
this.textbox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CaptureKeyPress); this.textbox1.KeyDown += new System.Windows.Forms.KeyEventHandler(CaptureKeyDown); this.textbox1.KeyUp += new System.Windows.Forms.KeyEventHandler(CaptureKeyUp);3.Creating event handler
private void CaptureKeyPress(object sender, KeyPressEventArgs e) { //key press capture key char //you can compare with keycode also if (e.KeyChar == (char)Keys.Enter) { MessageBox.Show("Enter Key Press"); } //or can compare with ascii code if (e.KeyChar == 13) //13 in ascii code for enter { MessageBox.Show("Enter Key Press"); } } private void CaptureKeyDown(object sender, KeyEventArgs e) { //key down capture key code if (e.KeyCode == Keys.Enter) { MessageBox.Show("Enter Key Down"); } } private void CaptureKeyUp(object sender, KeyEventArgs e) { //key up capture key code if (e.KeyCode == Keys.Enter) { MessageBox.Show("Enter Key Up"); } }get list of key char from ascii table.. link below..
get list of key code from keys enum.. link below..
Additional Reading at :
Labels:
Ascii,
C#,
Capture,
Capture Enter Keys,
CSharp,
Event,
Event Handler,
Events,
Keyboard,
Keyboard Key,
KeyChar,
KeyCode,
KeyDown Event,
KeyEventArgs,
KeyPress Event,
KeyPressEventArgs,
Keys,
KeyUp Event
Thursday, May 2, 2013
C# ComboBox using DataTable
Load Combobox Using DataTable.
Make an OleDbConnection.
Create DataTable from OleDbDataReader.
Sample code:
Make an OleDbConnection.
Create DataTable from OleDbDataReader.
Sample code:
//include this using System.Data.OleDb; //declare OleDbConnection OCON = null; OleDbDataReader ODR = null; //create connection OCON = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=192.168.0.1;Initial Catalog=TESTDATABASE;User ID=TESTUSER;Password=TESTPASS;"); try{ //open connection OCON.Open(); //create command OleDbCommand OCMD = null; OCMD.CommandText = "SELECT ID, DESCRIPTION FROM TABLE"; //execute command ODR = OCMD.ExecuteReader(); //load datareader to datatable DataTable DT = new DataTable(); DT.Load(ODR); //attach datatable to combobox comboBox1.DisplayMember = "DESCRIPTION"; comboBox1.ValueMember = "ID"; comboBox1.DataSource = DT; //close connection OCON.Close(); }catch(OleDbException ex){ MessageBox.Show(ex.ToString()); }Additional Reading at :
Subscribe to:
Posts (Atom)