Search This Blog

Friday, December 28, 2012

Key events not fired Windows Forms

C# > Form > KeyPreview 

KeyPreview gets or sets a value indicating whether the form will receive key events before the event is passed to the control that has focus.






Example

Key events not fired Windows Forms

Solution:

Set KeyPreview property to True


Thursday, December 27, 2012

double (C#)

C# > Types > Double






Double type stores 64-bit floating-point values.

range: ±5.0 × 10−324 to ±1.7 × 10308
precision: 15-16 digits

By default, a real numeric literal on the right side of the assignment operator is treated as double, but if you want an integer number to be treated as double, use the suffix d or D.

double x = 10D;


Integral types and floating-point types can be mixed in an expression:

  • If one type is double the expression evaluates to double
  • If no double type in the expression it evaluates to float
Example: the sum is double type


int x = 1;
float y = 2.5f;
double w = 1.2E+1;
MessageBox.Show ("The sum is: " + (x + y +  w).ToString());
 


 
 


Common Language Specification (CLS)

Common Language Specification is a set of base rules to which any language targeting the CLI should conform in order to interoperate with other CLS-compliant languages.

Common Language Specification (CLS) is a set of basic language features needed by many applications.

To fully interact with other objects regardless of the language they were implemented in, objects must expose to callers only those features that are common to all the languages they must interoperate with.

UInt32 Structure

UInt32 Structure represents a 32-bit unsigned integer.

The UInt32 type is not CLS-compliant.
The CLS-compliant alternative type is Int64.

HttpContext.Session ASP.NET

ASP.NET > HttpContext > Session

Gets the HttpSessionState object for the current HTTP request.

ASP.NET pages contain a default reference to the System.Web namespace you can reference the members of HttpContext on an .aspx page without the fully qualified class reference to HttpContext. For example, you can use just Session("USER").

Note: If you want to use the members of HttpResponse from an ASP.NET code-behind module, you must include a reference to the System.Web and also fully qualify the reference.

For example, in a code-behind page you must specify the full name:
 
HttpContext.Current.Session("USER").







Friday, December 21, 2012

Class with events VB NET

VB.NET > Class > WithEvents

WithEvents specifies that one or more declared member variables refer to an instance of a class that can raise events.

Example: class with events

 Public Class Export
        Public Event TimesUp()
        Public Sub New()
            Dim worker As New BackgroundWorker()
            AddHandler worker.DoWork, AddressOf DoWork
            AddHandler worker.RunWorkerCompleted, AddressOf bg_RunWorkerCompleted
            worker.RunWorkerAsync()
        End Sub
        Private Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
            ' export stuff
            Thread.Sleep(5000)
        End Sub
        Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
            MsgBox("Background worker completed", vbInformation, "Background worker")
            RaiseEvent TimesUp() 'Triggers an event declared at module level within a class, form, or document.
        End Sub
    End Class

    Dim WithEvents _Export As New Export
    Private Sub handleTimesUp() Handles _Export.TimesUp
        MsgBox("TimesUp Event Raised and Handled")
    End Sub

 





BackgroundWorker VB.NET

VB.NET > BackgroundWorker

Executes an operation on a separate thread.

DoWork event occurs when RunWorkerAsync is called.
RunWorkerCompleted event occurs when the background operation has completed, has been canceled, or has raised an exception.

Example:

Imports System.ComponentModel
Imports System.Threading
Module Module1

  Public Sub backWork()
    Dim worker As New BackgroundWorker()
    AddHandler worker.DoWork, AddressOf DoWork
    AddHandler worker.RunWorkerCompleted, AddressOf bg_RunWorkerCompleted
    worker.RunWorkerAsync()
  End Sub

  Private Sub DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    ' some work
    Thread.Sleep(5000)
  End Sub

  Private Sub bg_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
    MsgBox("Background worker completed", vbInformation, "Background worker")
  End Sub

End Module