WinceCE system form design structure

Source: Internet
Author: User

Recently developed WINCE System

The following figure shows the structure diagram of the form drawn Using VISIO.

PS: the painting is really ugly :)

A simple explanation of this figure is that all forms are inherited from the FormBase class designer, which design the general structure of the program, full screen, title bar Status Bar, and some common Keyboard Events, for example, the buttons on the left and right sides of the WINCE system are usually left-clicked to exit. ,

DataListFormBase is the base class of all detailed display pages, which are inherited from FormBase.

The designer is as follows:

As you can see, this basic form is relatively simple, only the title bar and the status bar. The title bar is a simple form name, which can be assigned to each subclass. The lower left of the status bar is a lable used to display the system time. The lower right foot is a very bad Button used to operate the keypad switch.

Public partial class FormBase <T>: Form where T: class
{
Public string FormName = "";
Public T _ controller;

Public FormBase ()
{
InitializeComponent ();
}
Int m;
Int h;
Int s; // record the old time
// Record the new time, mainly used to compare whether the previous minute has passed. Of course, my program has processed the second and you can delete the corresponding part.
Int m1;
Int h1;
Int s1;

Public FormBase (T controller)
{
InitializeComponent ();
_ Controller = controller;
M = DateTime. Now. Minute;
H = DateTime. Now. Hour;
S = DateTime. Now. Second;
}

Protected override void OnLoad (EventArgs e)
{
Base. OnLoad (e );
LbName. Text = FormName;
Rectangle rectangle = Screen. PrimaryScreen. Bounds;
SetFullScreen (true, ref rectangle );

DoSetTime (DateTime. Now. Hour, DateTime. Now. Minute, DateTime. Now. Second );
Timer1.Enabled = true;
LbLogin. Text = string. Format ("Logon person: {0}", DeviceInfo. LoginUserId );
LbName. Focus ();
}

Private void FormBase_KeyDown (object sender, KeyEventArgs e)
{
If (e. KeyCode = System. Windows. Forms. Keys. Up ))
{
// Up
}
If (e. KeyCode = System. Windows. Forms. Keys. Down ))
{
// Down
}
If (e. KeyCode = System. Windows. Forms. Keys. Left ))
{
// Left
}
If (e. KeyCode = System. Windows. Forms. Keys. Right ))
{

}
If (e. KeyCode = System. Windows. Forms. Keys. Enter ))
{
// Enter
}
If (e. KeyCode = Keys. F12)
{
CloseForm ();
}
}

Public virtual void CloseForm () // closes the FORM method, which can be expanded in the subclass.
{
This. Close ();
}
Public static bool SetFullScreen (bool fullscreen, ref Rectangle rectOld) // sets the full screen method and applies the WIN32 API call.
{
Int Hwnd = 0;
Hwnd = Win32.FindWindow ("HHTaskBar", null );
If (Hwnd = 0) return false;
If (fullscreen)
{
Win32.ShowWindow (IntPtr) Hwnd, Win32.SW _ HIDE );
Rectangle rectFull = Screen. PrimaryScreen. Bounds;
Win32.SystemParametersInfo (Win32.SPI _ GETWORKAREA, 0, ref rectOld, Win32.SPIF _ UPDATEINIFILE); // get
Win32.SystemParametersInfo (Win32.SPI _ SETWORKAREA, 0, ref rectFull, Win32.SPIF _ UPDATEINIFILE); // set
}
Else
{
Win32.ShowWindow (IntPtr) Hwnd, Win32.SW _ SHOW );
Win32.SystemParametersInfo (Win32.SPI _ SETWORKAREA, 0, ref rectOld, Win32.SPIF _ UPDATEINIFILE );
}
Return true;
}

Private void timereffectick (object sender, EventArgs e)
{
H1 = DateTime. Now. Hour;
M1 = DateTime. Now. Minute;
S1 = DateTime. Now. Second;
If (m1> m | h1> h | s1> s)
{
This. DoSetTime (m1, h1, s1 );

}

}

Public delegate void SetTime (int m, int h, ints); // sets the label time proxy Declaration



Private void DoSetTime (int m1, int h1, ints1) // set the Tag time event and refresh it in thread mode

{
If (this. InvokeRequired)
{
SetTime setpt = new SetTime (DoSetTime );
IAsyncResult isre = this. BeginInvoke (setpt, new object [] {m1, h1, s1 });
Try
{
This. EndInvoke (isre );
}
Catch
{
}
}
Else
{
LableTime. Text = string. Format ("{0 }:{ 1 }:{ 2}", h1 <10? "0" + h1.ToString (): h1.ToString (),
M1 <10? "0" + m1.ToString (): m1.ToString (),
S1 <10? "0" + s1.ToString (): s1.ToString ());
}
}

Public static InputPanel _ softKeyBoard = new InputPanel ();
/// <Summary>
/// Display/hide the keyboard
/// </Summary>
Public static void ShowHideSoftKeyBoard (Boolean isShow) // soft keyboard switch event
{
_ SoftKeyBoard. Enabled = isShow;
}

Private void btnSoft_Click (object sender, EventArgs e)
{
If (_ softKeyBoard. Enabled)
{
BtnSoft. BackColor = SystemColors. ActiveCaption;
ShowHideSoftKeyBoard (false );
}
Else
{
ShowHideSoftKeyBoard (true );
BtnSoft. BackColor = SystemColors. ActiveBorder;
}

}

}

 

All other forms inherit from this BASE, and you can set FormName. All the methods on the status bar below are common to FORM, which greatly facilitates development and makes it easier to maintain common things.

PS: the development process encountered a very disgusting problem, that is, the sub-Form Designer failed to LOAD, return "The designer cocould not be shown for this file because none of the classes within it can be designed. the designer inspected the following classes in the file: MainForm --- The base class 'cp. device. formBase 'could not be loaded. ensure the assembly has been referenced and that all projects have been built. "problem, but the operation is completely normal. At present, no good solutions have been found. I am very frustrated by the way that every time I want to design a form, I will After the basic class is changed to Form, it is changed back... Who has a good plan ~

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.