y//C#
//Save datetime in dd/MM/yyy formate into DataBase
//While Insert statement
e.g
Insert into ....purchaseDate="'+ DateTime.ParseExact(dateTimeField.Value.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture.DateTimeFormat)+"' .....;
//While Select statement
e.g
Select
convert(datetime,purchaseDate,103) =convert(datetime,'" + DateTime.ParseExact(dateTimeField.Value.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture.DateTimeFormat) + "',103) ,.........from tablename
http://www.prpraveen.blogspot.com
Monday, September 21, 2009
Datetime Null insertion to DataBase By Praveen P.R
//C#
//Datetime Null insertion to DB
using System.Data.SqlTypes;
//Any Datetime variable
//e.g dtToday
dtToday= SqlDateTime.Null;
http://www.prpraveen.blogspot.com
//Datetime Null insertion to DB
using System.Data.SqlTypes;
//Any Datetime variable
//e.g dtToday
dtToday= SqlDateTime.Null;
http://www.prpraveen.blogspot.com
Posted by
Praveen P.R
Sunday, September 20, 2009
DataGridView ComboBox Single click DropDown By Praveen P.R
// C#//It is also possible to drop down the comboboxlist using the DataGridViewComboBoxEditingControl when catching a mouse event:
private void dgvCompanyList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if(dgvCompanyList[e.ColumnIndex, e.RowIndex].EditType.ToString() == "System.Windows.Forms.DataGridViewComboBoxEditingControl")
{
DataGridViewColumn column = dgvCompanyList.Columns[e.ColumnIndex];
if (column is DataGridViewComboBoxColumn)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvCompanyList[e.ColumnIndex, e.RowIndex];
dgvCompanyList.CurrentCell = cell;
dgvCompanyList.BeginEdit(true);
DataGridViewComboBoxEditingControl editingControl = (DataGridViewComboBoxEditingControl)dgvCompanyList.EditingControl;
editingControl.DroppedDown = true;
}
}
}
http://www.prpraveen.blogspot.com
private void dgvCompanyList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if(dgvCompanyList[e.ColumnIndex, e.RowIndex].EditType.ToString() == "System.Windows.Forms.DataGridViewComboBoxEditingControl")
{
DataGridViewColumn column = dgvCompanyList.Columns[e.ColumnIndex];
if (column is DataGridViewComboBoxColumn)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvCompanyList[e.ColumnIndex, e.RowIndex];
dgvCompanyList.CurrentCell = cell;
dgvCompanyList.BeginEdit(true);
DataGridViewComboBoxEditingControl editingControl = (DataGridViewComboBoxEditingControl)dgvCompanyList.EditingControl;
editingControl.DroppedDown = true;
}
}
}
http://www.prpraveen.blogspot.com
Posted by
Praveen P.R
Monday, September 14, 2009
GlassButton / Custom button C# By Praveen P.R
http://www.prpraveen.blogspot.com
Codeproject
* GlassButton - How to create an animating glass button using only GDI+ (and not using WPF). *
* *
* Original developed by Łukasz Świątkowski - lukasz.swiatkowski@gmail.com *
* Form-/Perfomance-/Behavior-Improvements by Fink Christoph - fink.christoph@gmail.com *
* *
* Perfomance-Timer stoped for slow systems
* Feel free to use this control in your application or to improve it in any way! *
***********************************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using PushButtonState = System.Windows.Forms.VisualStyles.PushButtonState;
namespace EnhancedGlassButton
{
///
/// Represents a glass button control.
///
[ToolboxBitmap(typeof(System.Windows.Forms.Button)), ToolboxItem(true), ToolboxItemFilter("System.Windows.Forms"), Description("Raises an event when the user clicks it.")]
public partial class GlassButton : Button
{
# region " Global Vareables "
# region " Vareables for Drawing "
Codeproject
* GlassButton - How to create an animating glass button using only GDI+ (and not using WPF). *
* *
* Original developed by Łukasz Świątkowski - lukasz.swiatkowski@gmail.com *
* Form-/Perfomance-/Behavior-Improvements by Fink Christoph - fink.christoph@gmail.com *
* *
* Perfomance-Timer stoped for slow systems
* Feel free to use this control in your application or to improve it in any way! *
***********************************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using PushButtonState = System.Windows.Forms.VisualStyles.PushButtonState;
namespace EnhancedGlassButton
{
///
/// Represents a glass button control.
///
[ToolboxBitmap(typeof(System.Windows.Forms.Button)), ToolboxItem(true), ToolboxItemFilter("System.Windows.Forms"), Description("Raises an event when the user clicks it.")]
public partial class GlassButton : Button
{
# region " Global Vareables "
# region " Vareables for Drawing "
Posted by
Praveen P.R
Sunday, September 6, 2009
Set Focus to a control on Form Load C# by Praveen P.R
// On form Load as required
this.ActiveControl = controlName;
this.ActiveControl = controlName;
Posted by
Praveen P.R
Clear all controls on a Form / Panel / GroupBox etc c# by Praveen P.R
//Clear All values in the Form / Panel / GroupBox etc
public static void clearControls(Control crl)
{
foreach (Control c in crl.Controls)
{
if (c.GetType().Name == "GroupBox" || c.GetType().Name == "CustomGroupBox")
{
clearControls(c);
}
else if (c.GetType().Name == "TextBox")
{
((TextBox)c).Text = "";
}
else if (c.GetType().Name == "CustomTextBox")
{
((CustomControls.CustomTextBox)c).Text = "";
}
else if (c.GetType().Name == "ComboBox")
{
if (((ComboBox)c).Items.Count > 0)
{
((ComboBox)c).SelectedIndex = 0;
}
}
}
}
//To call the above funtion
clearControls(this);
or
clearControls(panel); // pass panel Object
or
clearControls(Groupbax); // pass groupbax Object
public static void clearControls(Control crl)
{
foreach (Control c in crl.Controls)
{
if (c.GetType().Name == "GroupBox" || c.GetType().Name == "CustomGroupBox")
{
clearControls(c);
}
else if (c.GetType().Name == "TextBox")
{
((TextBox)c).Text = "";
}
else if (c.GetType().Name == "CustomTextBox")
{
((CustomControls.CustomTextBox)c).Text = "";
}
else if (c.GetType().Name == "ComboBox")
{
if (((ComboBox)c).Items.Count > 0)
{
((ComboBox)c).SelectedIndex = 0;
}
}
}
}
//To call the above funtion
clearControls(this);
or
clearControls(panel); // pass panel Object
or
clearControls(Groupbax); // pass groupbax Object
Posted by
Praveen P.R
Monday, August 31, 2009
Runtime Change control Position / location C# by Praveen P.R
// Code in C#
Using Button btnSave
//Change position / location in the form
btnSave.Location = new System.Drawing.Point(300,272);//300= X,272= Y
Using Button btnSave
//Change position / location in the form
btnSave.Location = new System.Drawing.Point(300,272);//300= X,272= Y
Posted by
Praveen P.R
C# Add | Fill ComboBox with Enum values C# By Praveen P.R
// Code in C# Add | Fill ComboBox with Enum values
//Declair Enum
public enum UserLevel { Admin = 0, Client = 1, Other = 2, Agent = 3, Supplier = 4, Accounts = 5, CheckPost = 6, Manager = 7 };
//Filling combobox with Enun Values
cmbUserLevel.DataSource = Enum.GetValues(typeof(classEnum.UserLevel));
//Set initial Value
cmbUserType.SelectedItem = classEnum.UserLevel.Other;
//Getting Selected Values
classEnum.UserTypeAtGoodsRecpt usr = (classEnum.UserTypeAtGoodsRecpt)Enum.Parse(typeof(classEnum.UserTypeAtGoodsRecpt), cmbUserType.SelectedItem.ToString());
// To get the value
int userVal=(int)usr;
//Declair Enum
public enum UserLevel { Admin = 0, Client = 1, Other = 2, Agent = 3, Supplier = 4, Accounts = 5, CheckPost = 6, Manager = 7 };
//Filling combobox with Enun Values
cmbUserLevel.DataSource = Enum.GetValues(typeof(classEnum.UserLevel));
//Set initial Value
cmbUserType.SelectedItem = classEnum.UserLevel.Other;
//Getting Selected Values
classEnum.UserTypeAtGoodsRecpt usr = (classEnum.UserTypeAtGoodsRecpt)Enum.Parse(typeof(classEnum.UserTypeAtGoodsRecpt), cmbUserType.SelectedItem.ToString());
// To get the value
int userVal=(int)usr;
Posted by
Praveen P.R
Friday, August 28, 2009
Change First Letter to Capital letter C# by Praveen P.R
// Code in C#
//Change First Letter to Capital letter
public static string titleCase(string text)
{
string returnTiltle;
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Convert to title case
TextInfo textInfo = cultureInfo.TextInfo; //Convert to title case
return returnTiltle = textInfo.ToTitleCase(text.Trim());
}
//Change First Letter to Capital letter
public static string titleCase(string text)
{
string returnTiltle;
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Convert to title case
TextInfo textInfo = cultureInfo.TextInfo; //Convert to title case
return returnTiltle = textInfo.ToTitleCase(text.Trim());
}
Posted by
Praveen P.R
Get System Drives C# by Praveen P.R
// Code in C#
//Get System Drives
public static void getSystemDrives(ComboBox cmbBox)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady)
{
cmbBox.Items.Add((object)d.Name);
}
}
if (cmbBox.Items.Count > 0)
{
cmbBox.SelectedIndex = 0;
}
}
//Get System Drives
public static void getSystemDrives(ComboBox cmbBox)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady)
{
cmbBox.Items.Add((object)d.Name);
}
}
if (cmbBox.Items.Count > 0)
{
cmbBox.SelectedIndex = 0;
}
}
Posted by
Praveen P.R
Close a Form Slowly C# by Praveen P.R
// Code in C#
//Close a form Slowly C#
public static void closeWindowSlowly(Form currentForm)
{
lock (currentForm)
{
for (double x = 1.0d; x > 0d; x = x - 0.1d)
{
System.Threading.Thread.Sleep(50);
currentForm.Opacity = x;
currentForm.Refresh();
}
}
}
//Close a form Slowly C#
public static void closeWindowSlowly(Form currentForm)
{
lock (currentForm)
{
for (double x = 1.0d; x > 0d; x = x - 0.1d)
{
System.Threading.Thread.Sleep(50);
currentForm.Opacity = x;
currentForm.Refresh();
}
}
}
Posted by
Praveen P.R
Thursday, August 27, 2009
Gradient Effect to Controls C# by Praveen P.R
// Code in C#
Give gradient effect to control at Paint Event
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.LinearGradientBrush gradBrush;
Point start = new Point(-100,-100);
Point end = new Point(Form1.Width-1000, Form1.Height+1300);
gradBrush = new
System.Drawing.Drawing2D.LinearGradientBrush(start, end, Color.Black, Color.Honeydew );
Graphics g = Form1.CreateGraphics();
g.FillRectangle(gradBrush, new Rectangle(0,0,Form1.Width, Form1.Height));
}
Give gradient effect to control at Paint Event
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Drawing2D.LinearGradientBrush gradBrush;
Point start = new Point(-100,-100);
Point end = new Point(Form1.Width-1000, Form1.Height+1300);
gradBrush = new
System.Drawing.Drawing2D.LinearGradientBrush(start, end, Color.Black, Color.Honeydew );
Graphics g = Form1.CreateGraphics();
g.FillRectangle(gradBrush, new Rectangle(0,0,Form1.Width, Form1.Height));
}
Posted by
Praveen P.R
Saturday, July 11, 2009
About me
Hello it's me P.R.Praveen from Kerala.
Currently working as Software Engineer.
Posted by
Praveen P.R
Subscribe to:
Posts (Atom)
