www.pudn.com > DealWithScreenOrientation.rar > EditForm.cs


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
 
using Microsoft.WindowsCE.Forms; 
 
namespace DealWithScreenOrientation 
{ 
	public partial class EditForm : Form 
	{ 
		int m_editItem = -1; 
 
		public EditForm(int editItem) 
		{ 
			InitializeComponent(); 
 
			try 
			{ 
				BookInfo bi = BookInfo.Books[editItem]; 
				m_txtISBN.Text = bi.ISBN; 
				m_txtTitle.Text = bi.Title; 
				m_txtAuthor.Text = bi.Author; 
				m_txtPublisher.Text = bi.Publisher; 
				m_txtPrice.Text = bi.Price.ToString("0.00"); 
 
				m_editItem = editItem; 
			} 
			catch 
			{ 
				MessageBox.Show( 
					"Get book information failed!", 
					"Error", 
					MessageBoxButtons.OK, 
					MessageBoxIcon.Hand, 
					MessageBoxDefaultButton.Button1); 
			} 
		} 
 
		private void m_mnuSave_Click(object sender, EventArgs e) 
		{ 
			try 
			{ 
				BookInfo.Books[m_editItem].Price = Decimal.Parse(m_txtPrice.Text); 
				BookInfo.Books[m_editItem].ISBN = m_txtISBN.Text; 
				BookInfo.Books[m_editItem].Title = m_txtTitle.Text; 
				BookInfo.Books[m_editItem].Author = m_txtAuthor.Text; 
				BookInfo.Books[m_editItem].Publisher = m_txtPublisher.Text; 
 
				this.Close(); 
			} 
			catch 
			{ 
				MessageBox.Show( 
					"Save book information failed!", 
					"Error", 
					MessageBoxButtons.OK, 
					MessageBoxIcon.Hand, 
					MessageBoxDefaultButton.Button1); 
			} 
		} 
 
		private void m_mnuCancel_Click(object sender, EventArgs e) 
		{ 
			this.Close(); 
		} 
 
		private void m_btnOpenInputMethod_CheckStateChanged(object sender, EventArgs e) 
		{ 
			m_inputPanel.Enabled = m_btnOpenInputMethod.Checked; 
		} 
 
		private void m_inputPanel_EnabledChanged(object sender, EventArgs e) 
		{ 
			m_btnOpenInputMethod.Checked = m_inputPanel.Enabled; 
 
			m_resizeContainer(); 
		} 
 
		private void EditForm_Resize(object sender, EventArgs e) 
		{ 
			m_layoutControls(); 
		} 
 
		private void m_resizeContainer() 
		{ 
			m_pnlContainer.Size = m_inputPanel.VisibleDesktop.Size; 
		} 
 
		private void m_layoutControls() 
		{ 
			m_resizeContainer(); 
 
			this.SuspendLayout(); 
			if(this.Width < this.Height)  // Portrait 
			{ 
				m_lblISBN.Location = new Point(4, 4); 
				m_lblTitle.Location = new Point(4, 46); 
				m_lblAuthor.Location = new Point(4, 87); 
				m_lblPublisher.Location = new Point(4, 129); 
				m_lblPrice.Location = new Point(4, 172); 
 
				m_txtISBN.Location = new Point(4, 18); 
				m_txtTitle.Location = new Point(4, 59); 
				m_txtAuthor.Location = new Point(4, 101); 
				m_txtPublisher.Location = new Point(4, 144); 
				m_txtPrice.Location = new Point(4, 186); 
 
				m_txtISBN.Size = new Size(210, 21); 
				m_txtTitle.Size = new Size(210, 21); 
				m_txtAuthor.Size = new Size(210, 21); 
				m_txtPublisher.Size = new Size(210, 21); 
				m_txtPrice.Size = new Size(210, 21); 
 
				m_btnOpenInputMethod.Location = new Point(78, 213); 
			} 
			else  // Landscape 
			{ 
				m_lblISBN.Location = new Point(4, 4); 
				m_lblTitle.Location = new Point(4, 31); 
				m_lblAuthor.Location = new Point(4, 58); 
				m_lblPublisher.Location = new Point(4, 85); 
				m_lblPrice.Location = new Point(4, 112); 
 
				m_txtISBN.Location = new Point(68, 3); 
				m_txtTitle.Location = new Point(68, 30); 
				m_txtAuthor.Location = new Point(68, 57); 
				m_txtPublisher.Location = new Point(68, 84); 
				m_txtPrice.Location = new Point(68, 111); 
 
				m_txtISBN.Size = new Size(228, 21); 
				m_txtTitle.Size = new Size(228, 21); 
				m_txtAuthor.Size = new Size(228, 21); 
				m_txtPublisher.Size = new Size(228, 21); 
				m_txtPrice.Size = new Size(228, 21); 
 
				m_btnOpenInputMethod.Location = new Point(164, 138); 
			} 
			this.ResumeLayout(); 
		} 
	} 
}