📄 frmmain.cs
字号:
using System;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;
using System.Drawing;
namespace CodeForChapter2
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
#region Orientation and size
private void frmMain_Resize(object sender, EventArgs e)
{
// use the info for repositioning controls
label1.Text = "Orientation is " + SystemSettings.ScreenOrientation.ToString();
label2.Text = "Screen size is " + Screen.PrimaryScreen.Bounds.Width +
" x " + Screen.PrimaryScreen.Bounds.Height;
}
private void menuItem5_Click(object sender, EventArgs e)
{
SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
}
private void menuItem6_Click(object sender, EventArgs e)
{
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
}
private void menuItem8_Click(object sender, EventArgs e)
{
SystemSettings.ScreenOrientation = ScreenOrientation.Angle180;
}
private void menuItem7_Click(object sender, EventArgs e)
{
SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
}
#endregion
#region Cursor
private void menuItem2_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
}
private void menuItem3_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.Default;
}
#endregion
#region mouse_event
// Button1 event handler. Simulates button click OR opening a main menu.
// Same principle applies for ToolBarButton
private void button1_Click(object sender, EventArgs e)
{
PerformMouseClick(this.Left + 5, this.Height + 5, this);
}
// Wrapper for mouse_event, performing click action on coordinates given
public static void PerformMouseClick(Int32 x, Int32 y, Control f)
{
Point p = f.PointToScreen(new Point(x, y));
Int32 m1 = (65535 / Screen.PrimaryScreen.Bounds.Width);
Int32 m2 = (65535 / Screen.PrimaryScreen.Bounds.Height);
Int32 x2 = m1 * p.X;
Int32 y2 = m2 * p.Y;
mouse_event(2 | 0x8000, x2, y2, 0, 0);
mouse_event(4 | 0x8000, x2, y2, 0, 0);
}
[System.Runtime.InteropServices.DllImport("coredll.dll")]
public static extern void mouse_event(Int32 dwFlags, Int32 dx, Int32 dy,
Int32 dwData, Int32 dwExtraInfo);
#endregion
private void SomeMethod()
{
#if PocketPC
// do soemthing PocketPC-specific
#elif Smartphone
// do something Smartphone-specific
#else
// do something desktop-specific
#endif
}
// Show form ensuring that:
// 1. only one entry appears in the running list
// 2. the single entry has the same caption regardless of form shown
private void button3_Click(object sender, EventArgs e)
{
frmShown f = new frmShown();
if (checkBox1.Checked) // show modal
{
f.Owner = this;
f.ShowDialog();
}
else
{
f.MinimizeBox = false;
f.Text = this.Text;
caption = this.Text;
this.Text = ""; //hides the form from the list
f.Closed += new EventHandler(f_Closed);
f.Show();
// code in this form still runs (i.e. it is not modal)
// but the user cannot navigate to it until they close the one shown
}
}
private string caption;
void f_Closed(object sender, EventArgs e)
{
this.Text = caption;
this.BringToFront();
}
private void button2_Click(object sender, EventArgs e)
{
frmShown f = new frmShown();
if (checkBox1.Checked) // show modal
{
f.ShowDialog();
}
else
{
f.Show();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -