Search This Blog

Monday, January 27, 2014

How To Programmatically Change Printer Settings for Internet Explorer and WebBrowser Control in C#

C# > Forms >  WebBrowser > ShowPrintPreviewDialog

How To Programmatically Change Printer Settings for Internet Explorer and WebBrowser Control in C#

Example:

Change margin right property.





string strKey = "Software\\Microsoft\\Internet Explorer\\PageSetup";
bool boolWritable = true;
string strName = "margin_right";
object oValue = "0";
RegistryKey oKey = Registry.CurrentUser.OpenSubKey(strKey, boolWritable);
oKey.SetValue(strName, oValue);
oKey.Close();

webBrowser1.ShowPrintPreviewDialog();
 
 

ROW_NUMBER SQL Server Example

SQL Server > Built-in Functions >  ROW_NUMBER

Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.

Example:


CREATE TABLE #LocalTempTable(
       ID            int,
       Name   varchar(50),
       Salary int,
       DeptId int)

insert into #LocalTempTable(Id, Name, Salary, DeptId) values (1,'p1',100,1),  (2,'p2',200,1) ,  (3,'p2', 500,2)

SELECT ROW_NUMBER() OVER(ORDER BY Id DESC) AS Row,
    Name, Salary
FROM
       #LocalTempTable;

-- specify number of rows
WITH tbl AS
(
    SELECT Id, Name,
    ROW_NUMBER() OVER (ORDER BY Salary) AS RowNumber
    FROM #LocalTempTable
)

SELECT Id, Name, RowNumber 
FROM tbl
WHERE RowNumber BETWEEN 1 AND 2;

drop table #LocalTempTable










CapsLock pressed C# example

C# > Controls > > IsKeyLocked

IsKeyLocked check if CAPS LOCK, NUM LOCK, or SCROLL LOCK key is are pressed.

Example:

public static bool CapsLockActive()
{
     return Control.IsKeyLocked(Keys.CapsLock);
}




 





Friday, January 24, 2014

What is ASP.NET

ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications.





Get file name C# Example

C# > Files > GetFileName

Returns the file name and extension of the specified path string.

Example:


Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document";
dlg.DefaultExt = ".doc";
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
     string filename = dlg.FileName;
     filename  = System.IO.Path.GetFileName(filename);
}






Autosize Control sized based on its text C# CilentSize

C# > Controls > ClientSize

ClientSize gets or sets the height and width of the client area of the control.

Example:
Autosize TextBox width and height  based on its text.








C# Code:

 private void AutoSizeControl(Control control)
        {
            Graphics g = control.CreateGraphics();
            Size size = g.MeasureString(control.Text, control.Font).ToSize();
            control.ClientSize = new Size(size.Width+10 ,size.Height);
            g.Dispose();
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            AutoSizeControl(textBox1); 
        }





C# Control Class

C# > Control class




Control is the base class for controls. 
Controls are components with visual representation.