Handling Events |
Top Previous Next |
Tn events are specially important in asynchronous programming. A typical case is a custom terminal emulator, where the screens and state info must be reflected in the user interface.
The Tn events are:
OnConnect : Fires after a successfully connection to the mainframe is established. OnConnectFail : Fires after the connection to the mainframe fails. OnDisconnect : Fires after a disconnection with the mainframe. OnSessionState : Fires when a session-state change takes place. OnSystemLock : Fires when a terminal changes to a system locked state. OnSystemUnLock : Fires when a terminal changes to a system unlocked state. OnScreenChange : Fires after a new data screen has arrived. OnSendAid : Fires when an AID key is about to be sent (before is sent).
Some code examples:
VB.NET: Private Sub tn3270_OnConnect(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("Connected to the Host!"); End Sub
Private Sub tn3270_OnConnectionFail(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("Connection Failed!"); End Sub
Private Sub tn3270_OnDisconnect(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("Disconnected from the Host!"); End Sub
C#: private void tn3270_OnConnect(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("Connected to the Host!"); }
private void tn3270_OnConnectionFail(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("Connection Failed!"); }
private void tn3270_OnDisconnect(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("Disconnected from the Host!"); }
VB.NET: Private Sub tn3270_OnScreenChange(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("A new screen has been received"); End Sub
Private Sub tn3270_OnSystemUnLock(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("The latest screen has arrived"); End Sub
C#: private void tn3270_OnScreenChange(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("A new screen has been received"); }
private void tn3270_OnSystemUnLock(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("The latest screen has arrived"); }
VB.NET: Private Sub tn3270_OnSystemUnLock(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("We can send data to the host now"); End Sub
Private Sub tn3270_OnSystemLock(eventSender As System.Object, eventArgs As System.EventArgs) MessageBox.Show("We can''t send data at this moment!"); End Sub
C#: private void tn3270_OnSystemUnLock(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("We can send data to the host now"); }
private void tn3270_OnSystemLock(object eventSender, System.EventArgs eventArgs) { MessageBox.Show("We can''t send data at this moment!"); }
VB.NET: Private Sub tn3270_OnSystemUnLock(eventSender As System.Object, eventArgs As System.EventArgs) 'At this time we can send data to the host 'First we check if we are in the log-on screen
If (tn3270.GetText(15,1,tn3270.Cols).Substring(10,8) = "UserId:") Then 'Now we fill in the input fields tn3270.EditFields[0].Data = "MyUserId" tn3270.EditFields[1].Data = "MyPasword" 'and send them to the host with the Enter Key! tn3270.Press(Enter) Else If ... End If End Sub
C#: private void tnb3270_OnSystemUnLock(object sender, System.EventArgs e) { // At this time we can send data to the host // First we check if we are in the log-on screen
if (tn3270.GetText(15,1,tn3270.Cols).Substring(10,8) = "UserId:") { // Now we fill in the input fields tn3270.EditFields[0].Data = "MyUserId"; tn3270.EditFields[1].Data = "MyPasword"; // and send them to the host with the Enter Key! tn3270.Press(Enter); } else { ... } }
|