Search This Blog

Friday, January 24, 2014

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.

Tuesday, January 21, 2014

Int, bigint, smallint, and tinyint SQL Server

SQL Server > Data Types > Int, bigint, smallint, and tinyint

These type are exact number data types and use integer data.
The bigint data type is used when integer values exceed the range.



bigint
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
int
-2,147,483,648 to 2,147,483,647
smallint
-32,768 to 32,767
tinyint
0 to 255
Example:

Use int type for primary key in a table

CREATE TABLE [dbo].[Table]
(
       [Id] INT NOT NULL PRIMARY KEY
)




Decimal and numeric types SQL Server example

SQL Server > Data Types > decimal and numeric

Numeric is functionally equivalent to decimal.
They have fixed precision and scale.

precision: maximum total number of decimal digits (for both left and right)

scale: number of decimal digits that will be stored to the right of the decimal point.
Example:

declare @num numeric(20,5)
set @num = 1333.2
print @num

declare @num1 numeric(20,0)
set @num1 = 1333.2
print @num1

Result:
1333.20000
1333
 





RadGrid for ASP.NET AJAX

Telerik > RadGrid

RadGrid for ASP.NET AJAX is a control for data, paging, sorting, filtering and data editing to grouping and displaying hierarchical data.




RadPivotGrid ASP.NET example

Telerik > ASP.NET > RadPivotGrid

RadPivotGrid is a control used to aggregate records in a concise tabular format.

Example:

<telerik:RadPivotGrid ID="RadPivotGrid1" runat="server" DataSourceID="LinqDataSource1" AllowPaging="true" AllowFiltering="false" ShowFilterHeaderZone="false">
  <ClientSettings Scrolling-AllowVerticalScroll="true">
  </ClientSettings>
  <Fields>
         <telerik:PivotGridColumnField DataField="City">
     </telerik:PivotGridColumnField>
      <telerik:PivotGridColumnField DataField="Month">
      </telerik:PivotGridColumnField>
       <telerik:PivotGridRowField DataField="ProductName">
       </telerik:PivotGridRowField>
      <telerik:PivotGridAggregateField DataField="Quantity" Aggregate="Sum">
    </telerik:PivotGridAggregateField>
    </Fields>
</telerik:RadPivotGrid>







Creates directory C# example

C# > Files > Directory > CreateDirectory

Creates directory  in the specified path.

Example:

 

string dir = @"c:\dir1";
try
{
            if (!Directory.Exists(dir))
      {
              DirectoryInfo di = Directory.CreateDirectory(dir);
      }
}
catch (Exception ex)
{
       MessageBox.Show(ex.ToString());
}
finally {}