It is always better to have Line numbers displayed in Visual Studio when you debug your VB or C# Project. It is not turned on by default. you can turn it on as shown below
Visual Studio .NET Tips and Tricks, VB.NET Code Samples, C# Code Snippets, ASP.NET Code Samples, .NET Tips and Tricks, C# Tips & Tricks, Visual Studio 2010, .NET Framework Code Samples, VB.NET Tips & Tricks
Public MustInherit Class ClassAbs
Public Sub ExampleMethod()
MessageBox.Show("This is sample")
End Sub
Public MustOverride Sub ExampleMethod_ShouldBeInherited()
Public Overridable Sub ExampleMethod_CanBeCalledFromBase()
MessageBox.Show("This is sample")
End Sub
End Class
Public Class ClassDerivedFromAbstract
Inherits ClassAbs
Public Sub ExampleAbstract()
MyBase.ExampleMethod_CanBeCalledFromBase()
End Sub
Public Overrides Sub ExampleMethod_ShouldBeInherited()
End Sub
Public Overrides Sub ExampleMethod_CanBeCalledFromBase()
MessageBox.Show("This is sample from Derived")
End Sub
End Class
Dim CAb As New ClassDerivedFromAbstract
CAb.ExampleMethod_CanBeCalledFromBase()
CAb.ExampleMethod_ShouldBeInherited()
Dim iWidth As Integer = Screen.PrimaryScreen.Bounds.Width
Dim iHeight As Integer = Screen.PrimaryScreen.Bounds.Height
Me.Width = iWidth
Me.Height = iHeight
Me.Location = New System.Drawing.Point(0, 0)
int iWindowWidth = Screen.PrimaryScreen.Bounds.Width;
int iWindowHeight = Screen.PrimaryScreen.Bounds.Height;
this.Size = new Size(iWindowWidth, iWindowHeight ) ;
Resources Tab in Visual Studiopublic System.Drawing.Bitmap GetButtonImage(Office.IRibbonControl control)
{
switch(control.Id)
{
case "btnmoscow":
return Properties.Resources.moscow;
.
.
,
default:
return null;
}
}
private void ExcelFilterExample() { String[] FilterList = {"Apple","Orange"}; Excel.Workbook oWB = Globals.ThisAddIn.Application.Workbooks.Open(@"C:\Users\comp\Documents\FreshFruitsnVegetables.xls"); Excel.Worksheet oWS = oWB.Worksheets[1]; oWS.ListObjects.AddEx (Excel.XlListObjectSourceType.xlSrcRange, oWS.UsedRange, System.Type.Missing ,Excel.XlYesNoGuess.xlYes).Name = "FruitList"; oWS.ListObjects["FruitList"].Range.AutoFilter(2, FilterList, Excel.XlAutoFilterOperator.xlFilterValues ); }
private void MathTableExample()
{
Microsoft.Office.Interop.Excel.Range oRng;
oRng = Globals.ThisAddIn.Application.get_Range("A1");
for (int i = 1; i <= 10; i++)
{
// Uses Offset Method of Excel
oRng.get_Offset(i, 0).Value2 = "9 x " + i.ToString() + " = " + (i * 9).ToString();
}
}
Disable Errors while Loading
If Not Range is nothing
FlagDone = Not Failed
Microsoft.Office.Interop.Excel.Range oRng;
oRng = null;
if (object.ReferenceEquals(oRng,null))
{
oRng = null;
}
Globals.Ribbons.RibbonFB.button1.Enabled =(!CusPane.Visible);
Platform Compatibility (32 bit, 64 bit) for .NET application
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
this.Text = webBrowser1.Document.Title;
}
WebBrowser Control and UserformwebBrowser1.Navigate("http://www.bing.com");
| Color Name | RGB Value |
| RGB Value of AliceBlue | #F0F8FF |
| RGB Value of AntiqueWhite | #FAEBD7 |
| RGB Value of Aqua | #00FFFF |
| RGB Value of Aquamarine | #7FFFD4 |
| RGB Value of Azure | #F0FFFF |
| RGB Value of Beige | #F5F5DC |
| RGB Value of Bisque | #FFE4C4 |
| RGB Value of Black | #000000 |
| RGB Value of BlanchedAlmond | #FFEBCD |
| RGB Value of Blue | #0000FF |
| RGB Value of BlueViolet | #8A2BE2 |
| RGB Value of Brown | #A52A2A |
| RGB Value of BurlyWood | #DEB887 |
| RGB Value of CadetBlue | #5F9EA0 |
| RGB Value of Chartreuse | #7FFF00 |
| RGB Value of Chocolate | #D2691E |
| RGB Value of Coral | #FF7F50 |
| RGB Value of CornflowerBlue | #6495ED |
| RGB Value of Cornsilk | #FFF8DC |
| RGB Value of Crimson | #DC143C |
| RGB Value of Cyan | #00FFFF |
| RGB Value of DarkBlue | #00008B |
| RGB Value of DarkCyan | #008B8B |
| RGB Value of DarkGoldenrod | #B8860B |
| RGB Value of DarkGray / DarkGrey | #A9A9A9 |
| RGB Value of DarkGreen | #006400 |
| RGB Value of DarkKhaki | #BDB76B |
| RGB Value of DarkMagenta | #8B008B |
| RGB Value of DarkOliveGreen | #556B2F |
| RGB Value of DarkOrange | #FF8C00 |
| RGB Value of DarkOrchid | #9932CC |
| RGB Value of DarkRed | #8B0000 |
| RGB Value of DarkSalmon | #E9967A |
| RGB Value of DarkSeaGreen | #8FBC8F |
| RGB Value of DarkSlateBlue | #483D8B |
| RGB Value of DarkSlateGray / DarkSlateGrey | #2F4F4F |
| RGB Value of DarkTurquoise | #00CED1 |
| RGB Value of DarkViolet | #9400D3 |
| RGB Value of DeepPink | #FF1493 |
| RGB Value of DeepSkyBlue | #00BFFF |
| RGB Value of DimGray / DimGrey | #696969 |
| RGB Value of DodgerBlue | #1E90FF |
| RGB Value of FireBrick | #B22222 |
| RGB Value of FloralWhite | #FFFAF0 |
| RGB Value of ForestGreen | #228B22 |
| RGB Value of Fuchsia | #FF00FF |
| RGB Value of Gainsboro | #DCDCDC |
| RGB Value of GhostWhite | #F8F8FF |
| RGB Value of Gold | #FFD700 |
| RGB Value of Goldenrod | #DAA520 |
| RGB Value of Gray / Grey | #808080 |
| RGB Value of Green | #008000 |
| RGB Value of GreenYellow | #ADFF2F |
| RGB Value of Honeydew | #F0FFF0 |
| RGB Value of HotPink | #FF69B4 |
| RGB Value of IndianRed | #CD5C5C |
| RGB Value of Indigo | #4B0082 |
| RGB Value of Ivory | #FFFFF0 |
| RGB Value of Khaki | #F0E68C |
| RGB Value of Lavender | #E6E6FA |
| RGB Value of LavenderBlush | #FFF0F5 |
| RGB Value of LawnGreen | #7CFC00 |
| RGB Value of LemonChiffon | #FFFACD |
| RGB Value of LightBlue | #ADD8E6 |
| RGB Value of LightCoral | #F08080 |
| RGB Value of LightCyan | #E0FFFF |
| RGB Value of LightGoldenrodYellow | #FAFAD2 |
| RGB Value of LightGreen | #90EE90 |
| RGB Value of LightGray / LightGrey | #D3D3D3 |
| RGB Value of LightPink | #FFB6C1 |
| RGB Value of LightSalmon | #FFA07A |
| RGB Value of LightSeaGreen | #20B2AA |
| RGB Value of LightSkyBlue | #87CEFA |
| RGB Value of LightSlateGray / LightSlateGrey | #778899 |
| RGB Value of LightSteelBlue | #B0C4DE |
| RGB Value of LightYellow | #FFFFE0 |
| RGB Value of Lime | #00FF00 |
| RGB Value of LimeGreen | #32CD32 |
| RGB Value of Linen | #FAF0E6 |
| RGB Value of Magenta | #FF00FF |
| RGB Value of Maroon | #800000 |
| RGB Value of MediumAquamarine | #66CDAA |
| RGB Value of MediumBlue | #0000CD |
| RGB Value of MediumOrchid | #BA55D3 |
| RGB Value of MediumPurple | #9370DB |
| RGB Value of MediumSeaGreen | #3CB371 |
| RGB Value of MediumSlateBlue | #7B68EE |
| RGB Value of MediumSpringGreen | #00FA9A |
| RGB Value of MediumTurquoise | #48D1CC |
| RGB Value of MediumVioletRed | #C71585 |
| RGB Value of MidnightBlue | #191970 |
| RGB Value of MintCream | #F5FFFA |
| RGB Value of MistyRose | #FFE4E1 |
| RGB Value of Moccasin | #FFE4B5 |
| RGB Value of NavajoWhite | #FFDEAD |
| RGB Value of Navy | #000080 |
| RGB Value of OldLace | #FDF5E6 |
| RGB Value of Olive | #808000 |
| RGB Value of OliveDrab | #6B8E23 |
| RGB Value of Orange | #FFA500 |
| RGB Value of OrangeRed | #FF4500 |
| RGB Value of Orchid | #DA70D6 |
| RGB Value of PaleGoldenrod | #EEE8AA |
| RGB Value of PaleGreen | #98FB98 |
| RGB Value of PaleTurquoise | #AFEEEE |
| RGB Value of PaleVioletRed | #DB7093 |
| RGB Value of PapayaWhip | #FFEFD5 |
| RGB Value of PeachPuff | #FFDAB9 |
| RGB Value of Peru | #CD853F |
| RGB Value of Pink | #FFC0CB |
| RGB Value of Plum | #DDA0DD |
| RGB Value of PowderBlue | #B0E0E6 |
| RGB Value of Purple | #800080 |
| RGB Value of Red | #FF0000 |
| RGB Value of RosyBrown | #BC8F8F |
| RGB Value of RoyalBlue | #4169E1 |
| RGB Value of SaddleBrown | #8B4513 |
| RGB Value of Salmon | #FA8072 |
| RGB Value of SandyBrown | #F4A460 |
| RGB Value of SeaGreen | #2E8B57 |
| RGB Value of Seashell | #FFF5EE |
| RGB Value of Sienna | #A0522D |
| RGB Value of Silver | #C0C0C0 |
| RGB Value of SkyBlue | #87CEEB |
| RGB Value of SlateBlue | #6A5ACD |
| RGB Value of SlateGray / SlateGrey | #708090 |
| RGB Value of Snow | #FFFAFA |
| RGB Value of SpringGreen | #00FF7F |
| RGB Value of SteelBlue | #4682B4 |
| RGB Value of Tan | #D2B48C |
| RGB Value of Teal | #008080 |
| RGB Value of Thistle | #D8BFD8 |
| RGB Value of Tomato | #FF6347 |
| RGB Value of Turquoise | #40E0D0 |
| RGB Value of Violet | #EE82EE |
| RGB Value of Wheat | #F5DEB3 |
| RGB Value of White | #FFFFFF |
| RGB Value of WhiteSmoke | #F5F5F5 |
| RGB Value of Yellow | #FFFF00 |
| RGB Value of YellowGreen | #9ACD32 |
private void btn_Click(object sender, EventArgs e)
{
Button b1;
b1 = (System.Windows.Forms.Button)sender;
MessageBox.Show("Button Clicked := " + b1.Name.ToString());
b1.ForeColor = Color.Red;
}
button1.Click += new EventHandler(btn_Click);
button2.Click += new EventHandler(btn_Click);
Double Incentive = 234.45;
Console.WriteLine("The agreed incentive in local currency is {0:C} ", Incentive);
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
Console.WriteLine("The agreed incentive in USD is {0:C} ", Incentive);
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);
Console.WriteLine("The agreed incentive in GBP is {0:C} ", Incentive);
using System.Threading; using System.Globalization;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-UK", false);
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB", false);
private static void PassByValueExample(double Salary)//
{
Salary = Salary * 1.2;
}
private static void PassByRefExample(ref double Salary)//
{
Salary = Salary * 1.2;
}
Console.WriteLine("Salary before hike is {0:F}", Sal);
PassByValueExample( Sal);
Console.WriteLine("Salary after hike is {0:F}", Sal);
Console.WriteLine("Salary before hike is {0:F}", Sal);
PassByRefExample(ref Sal);
Console.WriteLine("Salary after hike is {0:F}", Sal);
double Sal = 1250.45;
Console.WriteLine("Salary before hike is {0:D}", Sal); //Decimal instead of double
Console.WriteLine("Salary before hike is {F}", Sal); //Index is missing
double Sal = 1250.45;
Console.WriteLine("Salary before hike is {0:F}", Sal);
string sPlayerName = rdr[1].ToString();
sPlayerName = rdr["PlayerFirstName"].ToString();
string sConString = GetConnectionString("TeamDBConnectionString");
SqlConnection Con = new SqlConnection(sConString);
SqlCommand Cmd = new SqlCommand();
Cmd.Connection = Con;
Con.Open();
String sSQLCmdText = "Select * from PlayerDetails where PlayerFirstName = @FirstName";
Cmd.CommandText = sSQLCmdText;
Cmd.Parameters.AddWithValue("@FirstName", "Sachin");
SqlDataReader rdr = Cmd.ExecuteReader();
while (rdr.Read() == true)
{
string sPlayerName = rdr.GetString(1);
}
Con.Close();
public void Load_LB_GenericList()
{
List Team = new List();
ClassTeam CT = new ClassTeam(ClassTeam.playerType.Contract, "Sachin", 23, "33420242");
Team.Add(CT);
CT = new ClassTeam(ClassTeam.playerType.Contract, "Sourav", 23, "33420242");
Team.Add(CT);
CT = new ClassTeam(ClassTeam.playerType.Contract, "Dravid", 23, "33420242");
Team.Add(CT);
listBox1.DataSource = Team;
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "Phone";
}
class ClassTeam
{
#region declarations
public enum playerType { ClassA, ClassB, ClassC, Contract }
private playerType _PlayerType;
string _Name;
int _Age;
string _Phone;
#endregion
#region properties
public playerType PlayerType
{
//accessor
get { return _PlayerType; }
//mutator
set
{
_PlayerType = value;
}
}
public string Name
{
get { return _Name; }
set
{
_Name = value;
}
}
public string Phone
{
get { return _Phone; }
set
{
_Phone = value;
}
}
public int Age
{
get { return _Age; }
set
{
_Age = value;
}
}
#endregion
#region public methods
public string SetPlayer()
{
return null;
}
#endregion
#region ClassTeam Construct
public ClassTeam(playerType PT, string sName, int iAge, string sPhone )
{
PlayerType = PT;
_Name= sName;
_Age = iAge;
_Phone = sPhone;
}
#endregion
}
ArrayList Team = new ArrayList(); ClassTeam CT = new ClassTeam(ClassTeam.playerType.Contract, "Sachin", 23, "33420242"); Team.Add(CT); CT = new ClassTeam(ClassTeam.playerType.Contract, "Sourav", 23, "33420242"); Team.Add(CT); CT = new ClassTeam(ClassTeam.playerType.Contract, "Dravid", 23, "33420242"); Team.Add(CT);
listBox1.DataSource = Team; listBox1.DisplayMember = "Name"; listBox1.ValueMember = "Phone";
for (int i1 = 0; i1 < listBox1.SelectedItems.Count; i1++)
{
DataRowView D1 = listBox1.SelectedItems[i1] as DataRowView;
MessageBox.Show(D1[1].ToString());
}
The above code uses SelectedItems collection to retrieve information
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
MessageBox.Show(listBox1.Text);
MessageBox.Show(listBox1.SelectedValue.ToString());
}
string sConString = GetConnectionString("TeamDBConnectionString");
SqlConnection Con = new SqlConnection(sConString);
Con.Open();
//Command Text
String sSQLCmdText = "Select * from PlayerDetails";
//Create a new SQL Data Adapter
SqlDataAdapter DA = new SqlDataAdapter(sSQLCmdText , Con);
DataSet DS = new DataSet("PlayerDS"); //DataSet
DS.Clear();
DA.Fill(DS, "Player");
listBox1.DisplayMember = "PlayerName";
listBox1.ValueMember = "PlayerID";
listBox1.DataSource = DS.Tables["Player"];
Con.Close();
using System.Configuration;
private static string retsettings(String sConnName)
{
try
{
ConnectionStringSettings sConnection = ConfigurationManager.ConnectionStrings[sConnName];
return sConnection.ConnectionString;
}
catch (Exception ex1)
{
return null;
}
finally
{ }
}
using System.Text.RegularExpressions;
if (sPassword.Length < 8 )
{
throw new Exception("Password should contain mimimum 8 chars");
}
the code below checks for presence of atleast one number sPattern = "\\d";
oReg = new Regex(sPattern, RegexOptions.IgnoreCase);
if (oReg.IsMatch(sPassword) == false)
{
throw new Exception("Password should contain mimimum one numeric character");
}
the code below checks for presence of atleast one alphabet sPattern = "\\w";
oReg = new Regex(sPattern, RegexOptions.IgnoreCase);
if (oReg.IsMatch(sPassword) == false)
{
throw new Exception("Password should contain mimimum one alphabet character");
}
the code below checks for presence of atleast one non-alphanumeric character string sPattern;
sPattern = "[^a-zA-Z0-9\n\r\t ]";
Regex oReg = new Regex(sPattern, RegexOptions.IgnoreCase);
if (oReg.IsMatch(sPassword) == false)
{
throw new Exception("Password should contain mimimum one non-alphanumeric character");
}
Exceptions are raised and handled if the criteria is not matching
try {
if (sPassword.Length < 8 )
{
throw new Exception("Password should contain mimimum 8 chars");
}
}
catch(Exception ex1)
{
sMessage= ex1.Message.ToString();
return false;
}
ListlstIPLTeams = new List (); lstIPLTeams.Add("Mumbai Indians"); lstIPLTeams.Add("Chennai SuperKings"); lstIPLTeams.Add("Kolkatta KnightRiders"); lstIPLTeams.Add("Deccan Chargers"); lstIPLTeams.Add("Rajastan Royals"); lstIPLTeams.Add("Delhi DareDevils"); lstIPLTeams.Add("KingsXI Punjab"); lstIPLTeams.Add("RC Bangalore");
string[] NewIPLTeams = { "Pune", "Kochi" };
lstIPLTeams.AddRange(NewIPLTeams);
Console.WriteLine("\nList After Add Range");
Console.WriteLine("=======================");
foreach (string IPL in lstIPLTeams)
{
Console.WriteLine(IPL.ToString());
}
ListlstIPLTeams = new List (); lstIPLTeams.Add("Mumbai Indians"); lstIPLTeams.Add("Chennai SuperKings"); lstIPLTeams.Add("Kolkatta KnightRiders"); lstIPLTeams.Add("Deccan Chargers"); lstIPLTeams.Add("Rajastan Royals"); lstIPLTeams.Add("Delhi DareDevils"); lstIPLTeams.Add("KingsXI Punjab"); lstIPLTeams.Add("RC Bangalore"); Console.WriteLine("List Before Sorting"); Console.WriteLine("======================="); foreach (string IPL in lstIPLTeams) { Console.WriteLine(IPL.ToString()); } //Sort the Items lstIPLTeams.Sort(); Console.WriteLine("\nList After Sorting"); Console.WriteLine("======================="); foreach (string IPL in lstIPLTeams) { Console.WriteLine(IPL.ToString()); }
public class WicketCounter
{
//Private Constructor
private WicketCounter() { }
// No of Wickets
public static int Wickets;
// Public Method to Return the No of Wickets
public static int WicketCount()
{
return ++Wickets;
}
}
WicketCounter.WicketCount();
MessageBox.Show(WicketCounter.Wickets.ToString());
private bool download_file_from_Net()
{
try
{
WebClient WC = new WebClient();
String sWebLocation = "http://logic.stanford.edu/talks/Web2.0/microsoft-logo.jpg";
String sLocalPath = "C:\\Temp\\New folder (2)\\microsoft-logo.jpg";
WC.DownloadFile(sWebLocation, sLocalPath);
return true;
}
catch (Exception ex1)
{
return false;
}
}
String sLocalPath = "C:\\Temp\\New folder (2)";
String sLocalPath = "C:\\Temp\\New folder (2)\\";





using System.Diagnostics;
int i1 = 0;
while (i1 < 10)
{
Debug.Assert(i1 != 3);
++i1;
}
public enum playerType { ClassA, ClassB, ClassC, Contract }
private playerType _PlayerType;
string Name;
string Age;
string Phone;
#endregion
#region properties
public playerType PlayerType
{
//accessor
get { return _PlayerType; }
//mutator
set
{
_PlayerType = value;
}
}
ClassTeam CT = new ClassTeam();
CT.PlayerType = ClassTeam.playerType.Contract; //Calls the Mutator
MessageBox.Show(CT.PlayerType.ToString()); // Calls the Accessor