📄 phonenavigator.cs
字号:
//Filename : PhoneNavigator.cs
//Part of : Phone Navigator C# example
//Description : Main dialog of CSPhoneNavigator.NET example application
//Version : 3.2
//
//This example is only to be used with PC Connectivity API version 3.2.
//Compability ("as is") with future versions is not quaranteed.
//
//Copyright (c) 2005-2007 Nokia Corporation.
//
//This material, including but not limited to documentation and any related
//computer programs, is protected by intellectual property rights of Nokia
//Corporation and/or its licensors.
//All rights are reserved. Reproducing, modifying, translating, or
//distributing any or all of this material requires the prior written consent
//of Nokia Corporation. Nokia Corporation retains the right to make changes
//to this material at any time without notice. A copyright license is hereby
//granted to download and print a copy of this material for personal use only.
//No other license to any other intellectual property rights is granted. The
//material is provided "as is" without warranty of any kind, either express or
//implied, including without limitation, any warranty of non-infringement,
//merchantability and fitness for a particular purpose. In no event shall
//Nokia Corporation be liable for any direct, indirect, special, incidental,
//or consequential loss or damages, including but not limited to, lost profits
//or revenue,loss of use, cost of substitute program, or loss of data or
//equipment arising out of the use or inability to use the material, even if
//Nokia Corporation has been advised of the likelihood of such damages occurring.
using System.Runtime.InteropServices;
namespace CSPhoneNavigator.NET
{
using CONADefinitions;
using PCCSErrors;
using PCCAPIUtils;
using CONADeviceManagement;
using System.Windows.Forms;
public class PhoneNavigator : System.Windows.Forms.Form
{
private bool m_bCancelled;
public bool bRefreshPhoneListBox = false;
internal System.Windows.Forms.Timer Timer1;
private bool m_bDisposed = false;
#region " Windows Form Designer generated code "
public PhoneNavigator()
: base()
{
//This call is required by the Windows Form Designer.
InitializeComponent();
//Add any initialization after the InitializeComponent() call
}
//Form overrides dispose to clean up the component list.
protected override void Dispose(bool disposing)
{
if (!m_bDisposed)
{
base.Dispose(disposing);
}
m_bDisposed = true;
Application.Exit();
}
//Required by the Windows Form Designer
private System.ComponentModel.IContainer components;
//NOTE: The following procedure is required by the Windows Form Designer
//It can be modified using the Windows Form Designer.
//Do not modify it using the code editor.
internal PhoneListBox LBX_PhoneFiles;
internal System.Windows.Forms.Button BTN_Rename;
internal System.Windows.Forms.Label LBL_PhoneFiles;
internal System.Windows.Forms.Button BTN_DeviceInfo;
internal System.Windows.Forms.Button BTN_BluetoothPairing;
[System.Diagnostics.DebuggerStepThrough()]
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PhoneNavigator));
this.BTN_Rename = new System.Windows.Forms.Button();
this.LBL_PhoneFiles = new System.Windows.Forms.Label();
this.BTN_DeviceInfo = new System.Windows.Forms.Button();
this.BTN_BluetoothPairing = new System.Windows.Forms.Button();
this.LBX_PhoneFiles = new CSPhoneNavigator.NET.PhoneListBox();
this.Timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// BTN_Rename
//
this.BTN_Rename.Location = new System.Drawing.Point(118, 275);
this.BTN_Rename.Name = "BTN_Rename";
this.BTN_Rename.Size = new System.Drawing.Size(97, 24);
this.BTN_Rename.TabIndex = 8;
this.BTN_Rename.Text = "Rename";
this.BTN_Rename.Click += new System.EventHandler(this.BTN_Rename_Click);
//
// LBL_PhoneFiles
//
this.LBL_PhoneFiles.Location = new System.Drawing.Point(9, 9);
this.LBL_PhoneFiles.Name = "LBL_PhoneFiles";
this.LBL_PhoneFiles.Size = new System.Drawing.Size(232, 16);
this.LBL_PhoneFiles.TabIndex = 11;
this.LBL_PhoneFiles.Text = "Connected Devices:";
//
// BTN_DeviceInfo
//
this.BTN_DeviceInfo.Location = new System.Drawing.Point(12, 275);
this.BTN_DeviceInfo.Name = "BTN_DeviceInfo";
this.BTN_DeviceInfo.Size = new System.Drawing.Size(97, 24);
this.BTN_DeviceInfo.TabIndex = 17;
this.BTN_DeviceInfo.Text = "Device Info";
this.BTN_DeviceInfo.Click += new System.EventHandler(this.BTN_DeviceInfo_Click);
//
// BTN_BluetoothPairing
//
this.BTN_BluetoothPairing.Location = new System.Drawing.Point(224, 275);
this.BTN_BluetoothPairing.Name = "BTN_BluetoothPairing";
this.BTN_BluetoothPairing.Size = new System.Drawing.Size(109, 24);
this.BTN_BluetoothPairing.TabIndex = 18;
this.BTN_BluetoothPairing.Text = "Bluetooth Pairing";
this.BTN_BluetoothPairing.Click += new System.EventHandler(this.BTN_BluetoothPairing_Click);
//
// LBX_PhoneFiles
//
this.LBX_PhoneFiles.Location = new System.Drawing.Point(12, 28);
this.LBX_PhoneFiles.Name = "LBX_PhoneFiles";
this.LBX_PhoneFiles.Size = new System.Drawing.Size(321, 238);
this.LBX_PhoneFiles.TabIndex = 0;
//
// Timer1
//
this.Timer1.Tick += new System.EventHandler(this.Timer1_Tick);
//
// PhoneNavigator
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(345, 312);
this.Controls.Add(this.BTN_BluetoothPairing);
this.Controls.Add(this.BTN_DeviceInfo);
this.Controls.Add(this.LBL_PhoneFiles);
this.Controls.Add(this.BTN_Rename);
this.Controls.Add(this.LBX_PhoneFiles);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "PhoneNavigator";
this.Text = "Phone Navigator";
this.Load += new System.EventHandler(this.PhoneNavigator_Load);
this.ResumeLayout(false);
}
#endregion
[System.STAThread()]
public static void Main()
{
// Starts the application.
Application.Run(new PhoneNavigator());
}
//===================================================================
// RefreshPhoneListBox
//
// Refresh phone list to list box
//
//===================================================================
public void RefreshPhoneListBox()
{
bRefreshPhoneListBox = true;
}
//===================================================================
// SetCancelled
//
// Sets m_bCancelled value
//
//===================================================================
public void SetCancelled(bool bCancelled)
{
m_bCancelled = bCancelled;
}
//===================================================================
// IsCancelled
//
// Returns true if user has clicked Cancel button
//
//===================================================================
public bool IsCancelled()
{
bool functionReturnValue = false;
Application.DoEvents();
functionReturnValue = m_bCancelled;
m_bCancelled = false;
return functionReturnValue;
}
//===================================================================
// PhoneNavigator_Load
//
// Initialization of PhoneNavigator form
//
//===================================================================
private void PhoneNavigator_Load(object sender, System.EventArgs e)
{
Common.MainForm = this;
// Initializing phone file list:
Timer1.Enabled = true;
Timer1.Start();
//LBX_PhoneFiles.ListAllPhones()
bRefreshPhoneListBox = true;
}
//===================================================================
// BTN_BluetoothPairing_Click
//
// Opens dialog for pairing Bluetooth devices
//===================================================================
private void BTN_BluetoothPairing_Click(object sender, System.EventArgs e)
{
FRM_BTPairing BtPairingDlg = new FRM_BTPairing();
BtPairingDlg.ShowDialog(this);
}
//===================================================================
// BTN_Rename_Click
//
// Renames a folder or file from phone. If the selected item is
// a phone, renames friendly name of phone
//===================================================================
private void BTN_Rename_Click(object sender, System.EventArgs e)
{
if (LBX_PhoneFiles.SelectedIndex != -1)
{
FRM_Rename RenameDlg = new FRM_Rename();
//Rename(phone) 's friendly name
RenameDlg.LBL_OldName.Text = LBX_PhoneFiles.GetCurrentFriendlyName();
if (RenameDlg.LBL_OldName.Text.Length > 0)
{
// Open dialog to get new name
if (RenameDlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
string strNewName = RenameDlg.TXB_NewName.Text;
int iResult = CONADeviceManagement.CONARenameFriendlyName(LBX_PhoneFiles.GetDMHandle(), LBX_PhoneFiles.GetCurrentSN(), strNewName);
if (iResult != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("PhoneNavigator::BTN_Rename_Click(): RenameFriendlyName failed!", iResult);
}
else
{
bRefreshPhoneListBox = true;
}
}
}
}
else
{
MessageBox.Show("Please select phone to be renamed.");
}
}
//===================================================================
// BTN_DeviceInfo_Click
//
// Show device info
//===================================================================
private void BTN_DeviceInfo_Click(object sender, System.EventArgs e)
{
// currently selected device
string strSerial = LBX_PhoneFiles.GetCurrentSN();
if (strSerial == null || strSerial == "")
{
MessageBox.Show("Please select a phone");
return;
}
FRM_DeviceInfo infoDlg = new FRM_DeviceInfo();
infoDlg.ShowDialog();
}
private void Timer1_Tick(object sender, System.EventArgs e)
{
if (bRefreshPhoneListBox)
{
LBX_PhoneFiles.ListAllPhones();
bRefreshPhoneListBox = false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -