private void ReadPortSetup(SharedPreferences sp) { //读取选中的端口 if (_hasPorts) { //判断当前端口的数量,小于则表示是OK。 if (sp.GetInt32("selectedPort", 0) < comboBox_port.Items.Count) { comboBox_port.SelectedIndex = sp.GetInt32("selectedPort", 0); } else { comboBox_port.SelectedIndex = 0; } } //读取设置的波特率 comboBox_baudrate.SelectedIndex = sp.GetInt32("baudRate", 0); //读取设置的校验方式 comboBox_parity.SelectedIndex = sp.GetInt32("parity", 0); //读取设置的数据位 comboBox_databit.SelectedIndex = sp.GetInt32("dataBits", 0); //读取设置的停止位 comboBox_stopbit.SelectedIndex = sp.GetInt32("stopBits", 0); //读取自动发送数据时间间隔 textBox_sendPeriod.Text = sp.GetInt32("intervalTime", 500).ToString(); //读取接收方式 checkBox_receiveHex.Checked = sp.GetBoolean("acceptChar", true); //读取标志变量,即是否在接收框中显示信息。 showInfo = sp.GetBoolean("showInfo", true); button_receivepause.Text = showInfo ? "暂停接收显示" : "继续接收显示"; }
/// <summary> /// 加载保存的歌曲列表。 /// </summary> private void LoadSongListPath() { SharedPreferences mySharedPreferences = new SharedPreferences(@"配置文件夹\songlist.xml", true); int count = mySharedPreferences.GetInt32("songCount", 0); if (count > 0) { List <string> fileNames = new List <string>(); for (int i = 0; i < count; i++) { string item = "song_index" + i.ToString(); fileNames.Add(mySharedPreferences.GetString(item, "")); } AddSong(false, fileNames.ToArray()); } }
private void GetCustomOldNames(List<bool> state, List<string> names, List<string> value) { SharedPreferences sp = new SharedPreferences(SavefileName); int oldNumber = 0; if(sp.ConfigFileExists) oldNumber = sp.GetInt32("DIY_Number", 1); for (var i = 0; i < oldNumber; i++) { var checkboxSelect = (CheckBox)panel_add_DIYControls.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true)[0]; state.Add(checkboxSelect.Checked); var txtBoxValue = (TextBox) panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true)[0]; value.Add(txtBoxValue.Text); var txtBoxName = (TextBox)panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0]; names.Add(txtBoxName.Text); } }
/// <summary> /// 载入应用程序保存的配置信息。并设置相关控件的属性等。 /// </summary> private void LoadApplicationSettings() { if (File.Exists(@"配置文件夹\Application.config")) { try { //读取应用程序配置信息。 SharedPreferences sp = new SharedPreferences(@"配置文件夹\Application.config", true); //读取并设置是否保存配置 saveConfig = sp.GetBoolean("saveConfig", true); saveSongList = sp.GetBoolean("saveSongList", true); isFirstTimeRunning = sp.GetBoolean("isFirstTimeRunning", true); userName = sp.GetString("userName", ""); if (File.Exists(@"配置文件夹\songlist.xml") && saveSongList) { LoadSongListPath(); } if (saveConfig) { //读取并设置窗口透明度 BorderImage.Opacity = sp.GetDouble("windowOpacity", 1d); borderOpacity = BorderImage.Opacity; //读取并设置是否显示频谱图 showSpectrum = sp.GetBoolean("showSpectrum", true); //读取并设置是否自动加载歌词文件 autoLoadLyricFile = sp.GetBoolean("autoLoadLyricFile", true); //读取并设置歌词文件的编码方式 string str = sp.GetString("lyricFileEncoding", "null"); if (str != "null") { encoding = Encoding.GetEncoding(Int32.Parse(str)); } //读取并设置桌面歌词字体大小 dskLrcFontSize = sp.GetInt32("dskLyricFontSize", 40); string tempStr = string.Empty; //读取并设置桌面歌词字体 tempStr = sp.GetString("dskLyricFontFamily", "null"); if (tempStr != "null" && tempStr != "") { dskLrcFontFamily = tempStr; } // tempStr = sp.GetString("dskLyricFontStyle", "null"); if (tempStr != "null" && tempStr != "") { dskLrcFontStyle = tempStr; } //读取并设置已播放歌词颜色 tempStr = sp.GetString("playedLyricForeColor", "null"); if (tempStr != "null") { playedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置未播放歌词的颜色 tempStr = sp.GetString("unplayedLyricForeColor", "null"); if (tempStr != "null") { unplayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置歌名前景色 tempStr = sp.GetString("songNameForeColor", "null"); if (tempStr != "null") { nowPlayingSong.Foreground = GetBrushFromString(tempStr); } //读取并设置标题前景色 tempStr = sp.GetString("windowTitleForeColor", "null"); if (tempStr != "null") { WindowTitle.Foreground = GetBrushFromString(tempStr); } //读取并设置桌面歌词未播放颜色 tempStr = sp.GetString("dskLrcUnplayedForeColor", "null"); if (tempStr != "null") { dskLrcUnplayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置桌面歌词已播放的 tempStr = sp.GetString("dskLrcPlayedForeColor", "null"); if (tempStr != "null") { dskLrcPlayedForecolor = (Color)(ColorConverter.ConvertFromString(tempStr)); } //读取并设置标题颜色 tempStr = sp.GetString("titleForeColor", "null"); if (tempStr != "null") { titleTB.Foreground = GetBrushFromString(tempStr); } //读取并设置列表项目颜色 tempStr = sp.GetString("unselectedItemForeColor", "null"); if (tempStr != "null") { songListLB.Foreground = GetBrushFromString(tempStr); } //读取并更换背景图片。 borderImagePath = sp.GetString("borderBackImagePath", "null"); if (borderImagePath != "null") { ChangeBorderBackImage(borderImagePath); } //读取并设置为上次关闭时的音量。 this.volumeValuePrb.Value = sp.GetDouble("volume", 50); //读取并设置是否显示桌面歌词 showDesktopLyricItem.IsChecked = sp.GetBoolean("showDskLyric", true); //读取并设置为上次关闭时设置的播放模式 playmodeIndex = sp.GetInt32("playmodeIndex", -1) - 1; PlayerButtonClickDown(playmodeBt); #region 播放器状态还原代码。有点烦。。。 rememberExitPosition = sp.GetBoolean("remeberExitPosition", true); if (songListLB.Items.Count != 0) { if (rememberExitPosition) { if (saveSongList && saveConfig) { if (sp.GetInt32("nowplayingIndex", -2) != -2) { //读取并设置为上次关闭时播放器状态 songListLB.SelectedIndex = sp.GetInt32("nowplayingIndex", -1); //进行播放 PlayerButtonClickDown(mediaControlBt); bassPlayer.ChannelPosition = TimeSpan.FromMilliseconds(sp.GetDouble("pausePosition", 0)); GetLyricIndex(bassPlayer.ChannelPosition.TotalMilliseconds); //再暂停,等待用户操作。 PlayerButtonClickDown(mediaControlBt); } } } } #endregion } } catch (Exception) { try { File.Delete(@"配置文件夹\Application.config"); MessageBox.Show("Sorry, 检测到配置文件损坏,因为格式有误,无法读取。已强制删除配置文件。"); } catch (Exception) { } } } if (isFirstTimeRunning) { //表示是第一次运行程序。 //WelcomeToUse(string.Format("", userName)); isFirstTimeRunning = false; //TestFunc(); } }
private void ReadOthers(SharedPreferences sp) { comboBoxCCDPath.SelectedIndex = sp.GetInt32("comboboxCCDPath", 0); }
private void ReadDIYNumberSetup(SharedPreferences sp) { textBox_DIY_Number.Text = sp.GetInt32("DIY_Number", 1).ToString(); }
private void ReadPortSetup(SharedPreferences sp) { //读取选中的端口 if (_hasPorts) { //判断当前端口的数量,小于则表示是OK。 if (sp.GetInt32("selectedPort", 0) < comboBox_port.Items.Count) comboBox_port.SelectedIndex = sp.GetInt32("selectedPort", 0); else { comboBox_port.SelectedIndex = 0; } } //读取设置的波特率 comboBox_baudrate.SelectedIndex = sp.GetInt32("baudRate", 0); //读取设置的校验方式 comboBox_parity.SelectedIndex = sp.GetInt32("parity", 0); //读取设置的数据位 comboBox_databit.SelectedIndex = sp.GetInt32("dataBits", 0); //读取设置的停止位 comboBox_stopbit.SelectedIndex = sp.GetInt32("stopBits", 0); //读取自动发送数据时间间隔 textBox_sendPeriod.Text = sp.GetInt32("intervalTime", 500).ToString(); //读取接收方式 checkBox_receiveHex.Checked = sp.GetBoolean("acceptChar", true); //读取标志变量,即是否在接收框中显示信息。 showInfo = sp.GetBoolean("showInfo", true); button_receivepause.Text = showInfo ? "暂停接收显示" : "继续接收显示"; }
private void ReadOthers(SharedPreferences sp) { comboBoxCCDPath.SelectedIndex = sp.GetInt32("comboboxCCDPath", 0); }
private void ReadDIYNumberSetup(SharedPreferences sp) { textBox_DIY_Number.Text = sp.GetInt32("DIY_Number", 1).ToString(); }