"Reference". Net CF component programming (3) -- use components in mobile device Projects

Source: Internet
Author: User

Preface:

The first twoArticleWe learned how to add attributes, events, and descriptions of these attributes and events to the component. Today, let's test this component, if you forget the content of the first two articles, you can review them here:

"Reference". Net CF component programming (1) -- after Basics

"Reference". Net CF component programming (2) -- add events for components

Of course, TCP testing is involved, so we need to have a LAN environment. We need to configure the simulator to interact with the LAN desktop, so you also need to refer to the following article:

"Original" + "reprinted" configure the simulator network environment (Access LAN) Step by step!

When you're ready, let's get started.

Body:

Open the previously created tcpcomponent project and add a new mobile device application in its solution.ProgramProject: componentwm, using the. NET cf2.0 framework, wm5 PPC platform, OK, the entire solution is as follows:

Then, design the main. CS form as follows:

Obviously, a statusbar shows the connection status and a menuitem button triggers the connection event. At the same time, we drag the tcphelper gear component from the left-side toolbox to the design interface and set its properties as follows. Of course, the specific IP address and port should correspond to the environment you test:

And then set properties

The preparation is complete. Next, double-click the connectedstatu event of the tcphelper component, and thenCodeThe Section automatically generates a code similar to double-click button. We fill in the following code:

 

Connectedstatu code

   Private VoidTcphelper1_connectedstatu (StringMSG)
{
Safewinformsthreaddelegate d= NewSafewinformsthreaddelegate (showmessage );
Invoke (D,New Object[] {MSG });
}

As you can see, there is a delegate. The code for this delegate is as follows:

 

  Private Delegate VoidSafewinformsthreaddelegate (StringMSG );
Private VoidShowmessage (StringMSG)
{
Statusbar. Text=MSG;
}

Very simple. It's clear. These are the processing code after the event is triggered. Let's try the main function code of tcphelper: TCP connection.

Here, our remote host is 192.168.1.29, listening through port 3000 (the server side is a simple command line tcpserver Program), and then double-click the "test connection" button, add the following code:

 

Code

  
Try
{
Statusbar. Text= "Connecting ......";
Tcphelper1.connectasync ();
}
Catch(Exception ex)
{
Statusbar. Text=Ex. message;
}

 

 

It's really easy, so I don't have to say much. Let's take a look at the actual running effect:

1. Start the client and server

2. After you click test connection on the client, the status bar shows connecting...

3. If the server is not enabled, an exception prompt is returned in the status bar.

4. If the connection is normal, the status bar displays a successful connection, and the connection is quickly disconnected (this is because I did not perform sleep processing. If you do something, as you can see)

The specifics are temporarily unavailable. Of course,Source codeOf course there will be, but I want to put it in the last article. Why? In fact, our components are not complete here, Because, you find no, it is too ugly to use gear in the toolbar, and then look at other components or controls in the toolbox, they all have their own icons. How do I add icons to this component? Let's discuss it in the next article.

 

PS: the "Default attribute value" was mentioned in the previous article. Even if the default attribute value is defined in the property document during design, this default value cannot be obtained at runtime, for more information, see the following link: Description of defavaluvalueattribute in msdn: "The default value can be used by the visualization designer to reset the value of a member. The code generator can also use the default value to determine whether to generate code for members"

Reference:

Http://www.cnblogs.com/mapserver/category/65343.html thanks to mapserver

Http://www.cnblogs.com/OSCAR_NJU/archive/2008/04/02/1134231.html thanks to friends of death penalty (Khan)

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.