Search This Blog

Thursday, October 17, 2013

Class and object C#

C# > OOP > Class and object


A class is an abstraction of the characteristics and behavior of an object type. Classes can inherit from one other class, but can implement multiple interfaces.
A class is a template for defining objects.
A class should not be confused with an object.
An object is an instance of a class.




Difference between class and object

Class is like a template or blueprint of the object and resides on hard disk.
Object is real world implementation of a class and resides on RAM.

Example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class Person // define Person class
    {
        public string Name { get; set; } // Name property
    }

    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, EventArgs e)
        {
            Person p1 = new Person(); // create new Person object
            p1.Name = "Dan";
        }
        public Form1()
        {
            InitializeComponent();
        }
     }
}

 





Wednesday, October 16, 2013

Determine control ToolStripItem was clicked on

C# > Controls > ContextMenuStrip


Scenario:
We have many labels on forms and one ContextMenuStrip. How can we find the control which was clicked?

Solution:

private void copyToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ToolStripItem menuItem = sender as ToolStripItem;
            if (menuItem != null)
            {
                ContextMenuStrip owner = menuItem.Owner as ContextMenuStrip;
                if (owner != null)
                {
                    Control sourceControl = owner.SourceControl;
                    Label lbl = sourceControl as Label;
                }
            }
        }





Monday, October 14, 2013

Print preview dialog full screen C#

C# > PrintPreviewDialog > Full Screen



PrintPreviewDialog dlg = new PrintPreviewDialog();
((Form)dlg).WindowState = FormWindowState.Maximized;
dlg.ShowDialog();





Center DIV

CSS margin property sets all the margin properties (top, right, bottom, left).

<div style="border: thin solid #C0C0C0; width: 800px;margin:0 auto;">
        centered content
</div>





Sunday, October 6, 2013

Remove Qone8 browser hijacker malicious software

Qone8 is a browser hijacker, which is installed via other free downloads, and once installed it will change your browser homepage to start.qone8.com and default search engine to search.qone8.com.
It is considered malicious because it will append the argument http://start.qone8.com/ to random Windows shortcuts on your desktop and your Windows Start Menu.






Remove instructions:

1. Go to your software browser shortcut. Right click and then click on Properties

2. Goto to Shortcut Tab and than delete the text appears rights to name of the executable (argument value)


3. Goto to Internet options and change the home page

4. Close and restart your browser

Saturday, September 21, 2013

Read Connection String From Web.Config VB.Net

VB.NET > Data > SqlConnection > ConnectionString
 
Dim con As SqlConnection
Dim conString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString
con = New SqlConnection(conString)
con.Open()




Wednesday, September 18, 2013

Modifier Protected Internal C#

C# > Keywords > internal

Protected Internal variables/methods are accessible within the same assembly and also from the classes that are derived from this parent class.

Example

public class MyClass 
{
    // Only accessible within the same assembly
    internal static string name = "MyClass";
}