Tuesday, June 30, 2009

Grinnall Scorpionfor Sale

Custome Controls, Delegates and Events

This post comes from a few queries about a subject that can be confusing as the mechanism for communication of events between the controls and their respective consumers. Here we see an example of how to build a custom control in c # with visual studio 2005 and how to add events to study in detail the mechanism of communication between the controls that publish events and subscribers who use such tests.
events model C # has its roots in the programming model event that is popular in asynchronous programming. The basic founding principle of this model is one in which we have publisher and subscriber, in this model have a certain logic elements by publishing an event. They then send the event fired only to subscribers who are subscribed to the event.
In C # any object can publish a set of events that applications can subscribe. When the object fires the event which publishes all applications must be notified subscribers. In the picture you can see an outline of this operation:

EVENTS AND DELEGATES
In the heart of events in C # are the delegates. When an object generates an event this must be sent "out." These events are shipped out through the use of delegates.
the event declaration in C # is performed as follows:

[attributes] [modifiers] event type member-name;

type in this Declaration may be a delegate. Strictly speaking the delegate can be any delegate declared legally to the language. But there is a convention that is often followed and is the same as that used in Windows Form. By convention, the delegate accepts two parameters:
  • The object generating the event
  • Parameters for the specific event
Here we see some examples of this:

public delegate void SubmitClickedHandler (object sender, EventArgs e);
public event
SubmitClickedHandler SubmitClicked ;

Now an example of how the whole mechanism in conjugated nt, for that we first create a simple user control as follows:

Here we see the commented code that implements the event with their respective control



 

// Declare delegate for OK button clicked.

//

// Most action events (like the Click event) in Windows Forms

// use the EventHandler delegate and the EventArgs arguments.

// We will define our own delegate that does not specify parameters.

// Mostly, we really don't care what the conditions of the

// click event for the OK button were, we just care that

// the Submit button was clicked.



public delegate void SubmitfullNameClickedHandler ();



private string _fullName ;



public string fullName

{

get { return textBox1 . Text + " " + textBox2 . Text . ToUpper (); }

}



// Declare the event, which is associated with our

// delegate SubmitClickedHandler().

public event SubmitfullNameClickedHandler SubmitfullNameClicked ;



// Add a protected method called OnSubmitClicked().

// You may use this in child classes instead of adding

// event handlers.

public virtual void OnSubmitfullNameClicked ()

{

// If an event has no subscribers registerd, it will

// evaluate to null. The test checks that the value is not
/ / null, Ensuring That There Are subsribers Before
/ / calling the event itself.
if ( SubmitfullNameClicked ! = null) {

SubmitfullNameClicked ();}


code below the button click event OK that fired the event

 

private void button1_Click ( object sender , EventArgs e )

{

if ( textBox1 . Text == string . Empty && textBox2 . Text == string. Empty ) {

this . _fullName = string. Empty ;

} else
OnSubmitfullNameClicked ();}

Thus we see how they relate to events from user controls and delegates.
In the following example we see the implementation other user control, in this case we have the same elements as the previous control ie 2 textbox and a button, but in this case we will take each of the textbox the user name and password and then make a some validation of these types of user credentials which triggers one of the two events is my new control, or logInFailed logInSuccess see how it implements the code of this control

 

private string _userName ;

private string _passWord ;



private string userName

{

get { return textBox1 . Text ; }

}

private string passWord

{

get { return textBox2 . Text ; }

}



public delegate void EventHandler ( Object sender , EventArgs e );



public event EventHandler logInSuccess ;

public event EventHandler logInFailed ;



private bool check ( string UserName , string PassWord )

{

//Add here all validation logic

//I made a trivial logic to validate password=1234

if ( passWord == "1234" )
return true ;
return false;}

First we see a couple of properties where you store your user name and password you put into the TextBox control. Then look at the declaration of our delegate that will allow us to use our events, in this case the delegate's statement coincides with the traditional convention used in windows forms.
Then we declare as the two events named above. For the final we have a method that is the logic that implements (in this case trivial) validation user credentials. Below we see the code for the OK button click event:
 
private void button1_Click ( object sender , EventArgs e )

{

if ( check ( textBox1 . Text , textBox2 . Text ))

{

if ( logInSuccess != null )

logInSuccess ( this , new EventArgs ());

} else {

if ( logInFailed ! = Null )
logInFailed ( this , new EventArgs ());
}}

Here we see the moment when events are triggered in the control, click the OK button. Below is the code of an application that consumes our control.

 

public partial class Form2TexstLogInCustomControl : Form

{

public Form2TexstLogInCustomControl ()

{

InitializeComponent ();

}



private void Form2TexstLogInCustomControl_Load ( object sender , EventArgs e )

{

label1 . Text = string . Empty ;

}



private void logInBox1_logInFailed ( object sender , EventArgs e )

{

label1 . Text = string . Empty ;

label1 . Text = "LOG IN FAILED" ;

}



private void logInBox1_logInSuccess ( object sender , EventArgs e )

{

Label1 . Text = string. Empty ;
label1. Text = "LOG IN SUCCESS" ;
}}

I hope these two examples will have been useful to better understand how the events in C #. Greetings and till the next.


Saturday, June 27, 2009

How To Customize Bmx Bikes

Validate cells of a DataGridView

punctual any doubts of a partner, write this very simple and timely post dedicated to showing the way in which to validate a cell in a DataGridView (in this case is VisualStudio2005) of course the code is very trivial and is written in C #. To show how to solve this situation we have a DataGridView (DataGridView1), which has two columns Name and ID cells are editable and we want to validate is that only you can enter an integer value of TIMP in the cells corresponding to the ID column. Here we see the form with the DataGridView control:


And here's the code that performs the validation, the event used as we see the CellValidating the DataGridView: private
 
dataGridView1_CellValidating void ( object sender , DataGridViewCellValidatingEventArgs e )
{
int testInt ;
if ( e . ColumnIndex == 1 )
{
if ( e . FormattedValue . ToString (). Length != 0 )
{
if (! int . TryParse ( and . FormattedValue . ToString (), October testInt )) {

DataGridView1 . Rows [ and . RowIndex ]. ErrorText = "identity card must be a number" ;
e . Cancel = true ;
}
else
{
dataGridView1 . Rows [ e . RowIndex ]. ErrorText = string . Empty ;
e . Cancel = false ;
}}


}}}

Solved the problem, I hope to publish my post and to serve those who read it. Good weekend to all!

Wednesday, June 3, 2009

Mound And Blade Manuel Aktivasyon

split water molecules

An endless source of renewable energy could be used by plants. The plants perform photosynthesis to capture energy directly from the sun, which humans have managed to simulate the solar cells. One hour of sunlight on earth is equal to what humans need in an average year.

But so far solar cells have not been as efficient, more effective market making only 6% of sunlight into usable energy.

English biochemist James Barber has suggested in a recent article published in Philosophical Transactions of the Royal Society A: Mathematical, Physical and Engineering Sciences, the ideal would be to mimic the chemical reaction that occurs in plant photosynthesis. Specifically, a step known as water splitting.



The division of water is a complex chemical reaction that takes place in leaves, algae, phytoplankton and other greens. Plants use solar energy to split water into its separate components: oxygen and hydrogen. The oxygen thus produced is then released into the atmosphere, while hydrogen is used to convert carbon dioxide taken from the air in organic carbon molecules that form the plant tissue.

Barber identified the key enzyme in this work performed by plants, called photosystem II. He believes that understanding the structure could replicate it artificially. Barber and a group of scientists are trying to fully understand the structure of the system in order to do artificially.

whole process would be great for the environment. Is performed by trees to provide oxygen and consume carbon dioxide, which produces plenty of global warming we are experiencing. If we can create an artificial process, then not only get an endless source of renewable energy, but it would solve all problems. Since it would be releasing oxygen, consume carbon dioxide and hydrogen released could also be used as fuel.

Source: Erenovable