codemorphis.com Forum Index codemorphis.com
Software development: pure and simple.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Thank you.

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    codemorphis.com Forum Index -> Visual Programming Forum
View previous topic :: View next topic  
Author Message
gavin



Joined: 08 Sep 2004
Posts: 28

PostPosted: Wed Sep 08, 2004 2:58 am    Post subject: Thank you. Reply with quote

Thank you for a great product and support. I requested help a few days ago on a math problem and you responded promptly with the answer.

I do have a few more questions. I don't yet fully understand how the windows event interacts with UI components. If I set up two windows, one has a button which leads it to the second window, it makes no difference where I click even on the window itself, the second window opens.

My next question is how does the key pressed event work? I have tried everything, but cannot get it to work. Crying or Very sad

I have a text box in my math program that the user completes the answer. I cannot figure out how to set the Ibeam ready for the user to complete the problem without clicking a button first.

I am new to this Smile and would appreciate your assistance.

Thanks
Gavin
Back to top
View user's profile Send private message Send e-mail
CodeMorphis



Joined: 02 Dec 2003
Posts: 252

PostPosted: Wed Sep 08, 2004 1:24 pm    Post subject: Reply with quote

Thank you for your feedback and welcome to the user group forums. As always, this is a great place to post your programming questions and get help.

Your questions are very good ones. We’ll take a look at each one and illustrate the answer with a short sample program.


The Windows Event Component

First, you might like to check out a previous article dedicated to the Windows Event component (see http://www.codemorphis.com/forums/viewtopic.php?t=6).

Since the Windows Event component is one of the most important components it merits taking another look at it in the context of your problem.

A Windows program is user event driven. What this means is that every time a user event such as a mouse click or a keyboard press occurs, we have the opportunity to react and do something in our program. We could also choose to ignore certain user events.

It helps to think of Windows events as messages from the computer to you, much like a voice message. With this analogy, the Windows Event component acts much like an answering machine. It collects Windows messages and allows us to check and see what things the user did and then take appropriate action for each user event.

So suppose the user clicks on a button in our window and then presses a keyboard button. Each of these two events creates a separate message that contains information about the event. The first message would contain information about the type of mouse click (either left or right), the UI component clicked and where the mouse was when the click occurred. The second message would tell us which keyboard key was pressed.

In your program you are likely checking for mouse clicks but you need to examine the source of the mouse click so that you open the second window only when the user clicks on the required button. Here is a simple program with two windows.



What we want is for the second window (Win Form 2) to open in response to a user click on the button in the first window (Win Form 1).

You can download this program here: http://www.codemorphis.com/articles/ans_090804/WinEvent1.vpd

If you run this program you will see that it does not matter where you click in the first window – the second window will open in response to any mouse click. This happens because the Windows Event component receives the message for the user’s mouse click but we need to filter the event for the information that we require, namely that we should proceed only if the button is clicked. Let’s see how this works.

Run the program and then click anywhere in the window but not on the button. Right click the Windows Event component and select “Output Argument(s)”. The following dialog opens:



Note the entry with the name “UI component name”. It has a corresponding value of “Win Form 1”. This part of the event message tells us that the windows form was clicked. This entry has a port number 2. Each port in the dialog corresponds to the same-labeled blue data output port at the bottom of the Windows Event component.

You can close this dialog and try double clicking on the blue output data port labeled 2. This will show you the single entry for the data port.

Now with the program still running, click on the button in our program window. Open the output arguments dialog for the Windows Event component again. Here is what the dialog now looks like:



Note that this time, because we clicked on the button, the value for data output port 2 is the name of our button in the window. We will need to check for this value to know when we should open the second window.

In the Component Tray click on the Logic tab and drag and drop the “If Equal” component onto the workspace area. The “If Equal” component allows us to compare two values and execute two different paths of logic depending on the value comparison. We will test the output data port 2 value of the Windows Event component for the button name.

Right click the “If Equal” component and select “Input Argument(s)”. In the dialog that opens change the data type of the “Value 1” argument to “String”:



For string values several helpful browsers are available. Click on the “…” button that appears in the browser column and select the “UI Component Browser” option:



In the browser that opens select the name of the button in the first window (Button1). Click Ok to accept and close all dialogs. Now make the blue and red connections as below:



Now when the mouse click is trapped by the Windows Event component we immediately check to see what was clicked. If the button was clicked then the two input values in the “If Equal” component will be the same and process control will pass through the component’s red output port number 1. If not, then control moves through red output port 0. (Note: The convention for logic components is that output port 0 means false and output port 1 means true).

Now if you run the program you will see that the second window is opened only in response to mouse clicks on the button and that mouse clicks anywhere else are ignored.

You can download the finished program here: http://www.codemorphis.com/articles/ans_090804/WinEvent2.vpd



The Key Pressed Event

Suppose we have the following program where we want to trap keyboard events:



This program can be downloaded here:
http://www.codemorphis.com/articles/ans_090804/KeyPress1.vpd

If you run the program you will see that it does not respond to any key presses. In fact if you click on the window the program responds with the incorrect message that a key was pressed.

By default, the Windows Event component is set to trap only left mouse clicks. The reason for this is that this is the most common event of interest in a typical windows program. We need to enable the trapping of key presses. To do this double click the Windows Event component to open its properties dialog:



Look for the “KeyPressedEvent” property and enable it. At the same time we can disable the “LeftMouseButtonUpEvent” if we want to ignore left mouse clicks.

Now when we run the program it responds correctly to keyboard presses.

There is one thing we note here, however. The message window that appears displays a numeric code and not the actual key value as we know it, for example the readable alphabet characters. The code displayed is in fact correct but it is an ASCII value. ASCII stands for American Standard Code for Information Interchange. Every key on your keyboard has a unique code assigned to it. The Windows Event component supplies the ASCII code and not the typical character that you see on your keyboard because not all keys have a printable character. For instance, the backspace or enter keys do not have an associated printable character. If we know that a key is printable, however, we can convert it to its printable form.

Open the Component Tray and click on the Data tab. Drag and drop the “Data Converter” component and connect it as in the diagram below:



Now when we run the program and click on keys such as ‘a’ or ‘5’ we get the correct message that indicates what was pressed, in a printable format.

You can download the finished program here:
http://www.codemorphis.com/articles/ans_090804/KeyPress2.vpd



Changing the Cursor Shape

Let’s suppose we have the following program with a TextBox UI component in our window.



We can control the cursor type displayed. Open the Component Tray and click on the Windows tab. Drag and drop the “Cursor Interface” component. Double click the component to open its property dialog:



In the “Active Cursor Interface service”, select the “Set cursor” option. Click Ok. Now the component is setup to select whatever cursor shape you want. To set the arguments, right click the “Cursor Interface” component and select “Input Argument(s)”:



Click the “…” browser button for the “Windows Form” argument to select the Windows Form. This tells Synopsis which Windows Form should receive the set cursor command. For the “Cursor type” argument, select the “IBeam” type. Click Ok in the dialog.

Connect the components as below:



Now when you run the program the cursor is set to the IBeam type. Try changing the cursor type and see what the result is. In the “Sample Programs” directory of the Synopsis installation there is a demo program for the cursor called “Cursor.vpd” that demonstrates how to interactively select the various cursor types.

You can download the finished program here:
http://www.codemorphis.com/articles/ans_090804/Cursor.vpd


Hope that these examples shed some light on these important topics. If you have any other questions feel free to post or ask.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gavin



Joined: 08 Sep 2004
Posts: 28

PostPosted: Thu Sep 09, 2004 12:55 am    Post subject: Reply with quote

That makes sense now. My third question was misunderstood. I was able to change the cursor type but that is not what my question was. I need the cursor to active ready for typing without having to request it to be ready. In the math example you sent me, the text box cursor only becomes ready when you click on the text box. I need it to be set ready when the question is displayed.

Your support is fantastic.

Thanks again

Gavin
Back to top
View user's profile Send private message Send e-mail
CodeMorphis



Joined: 02 Dec 2003
Posts: 252

PostPosted: Thu Sep 09, 2004 2:29 pm    Post subject: Reply with quote

By your explanation, it sounds like what you want is for the edit cursor to appear automatically once the user has clicked on a question button and the question text is generated? This would be so that once the question appears the user can just type in the answer? If this is what you need, the solution is to give the textbox focus. Unfortunately, this service didn't make it into version 1.1 although it is a very trivial thing to add. We will enter it in our development list for the next update. If you have a license for Synopsis 1.1 this sort of thing can be updated sooner if it is an issue.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
gavin



Joined: 08 Sep 2004
Posts: 28

PostPosted: Thu Sep 09, 2004 3:34 pm    Post subject: Reply with quote

I have not yet a lisence but will obtain it soon. You have an unbelievable program and I would without a doubt purchase it. We can add this feature a little later on but would like to have it included.

Thanks
Gavin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    codemorphis.com Forum Index -> Visual Programming Forum All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group