/// <summary>ShowDialog</summary> /// <param name="owner">Any object that implements an IWin32Window interface that represents a top-level window /// that will own the modal dialog box.</param> /// <remarks>Whether by design or flaw, when a dialog box is run from outside the main application window's thread /// it will not block the main window. That is, non-modally. To force a dialog box created outside the main thread /// to block user commands from reaching the main window, we need to ask the main window to run the dialog box. /// This function provides the extra steps necessary to make the dialog boxes run properly.</remarks> public new DialogResult ShowDialog() { // Invoking a dialog box from outside the main window's thread requires a little jury-rigging. We need to ask // the main window of the application to run the dialog for us, otherwise it runs modally (if that's an // real adverb). Details are: create a delegate that matches the parameters we want to pass in and out of the // dialog box's 'ShowDialog' method. Then, ask the main window (that we extract from the process information) // to run the dialog box on our behalf (we're in a different thread here). Return the thread-safe results // back to the caller. Note that I did try to use the 'Forms.ActiveForm', but found it to be too unreliable // to get the main window for the application when accessed from a DLL. ShowDialogDelegate showDialogDelegate = new ShowDialogDelegate(ShowDialogHandler); Form mainForm = (Form)Form.FromHandle(Process.GetCurrentProcess().MainWindowHandle); DialogResult dialogResult = (mainForm == null) ? base.ShowDialog() : (DialogResult)mainForm.Invoke(showDialogDelegate, new object[] { mainForm }); // If one of the URL strings was selected, then remember it in the user preferences. if (dialogResult == DialogResult.OK) { // When writing out the most recently used list, don't write too many URLs. The number of elements is limited by // the 'mruListLength' parameter. The first item in the list will be the one selected in the text field. int minCount = FormUrl.mruListLength < this.comboBoxUrl.Items.Count ? FormUrl.mruListLength : this.comboBoxUrl.Items.Count; for (int counter = 0; counter < minCount; counter++) { UserPreferences.LocalSettings[string.Format("{0}{1}", mruKeyName, counter)] = this.comboBoxUrl.Items[counter]; } } // The caller uses this value to determine how the user exited the dialog. return(dialogResult); }
public ShowWord(Dispatcher context) { _locker = new object(); var intervalInMinutes = WordsSettings.WordsAsapSettings.WordDialogShowInterval; var interval = GetMiliseconds(intervalInMinutes); if (interval < MinimumShowInterval) { interval = GetMiliseconds(MinimumShowInterval); } _context = context; _showDialog = ShowDialog; _timer = new Timer { Enabled = false, Interval = interval }; _timer.Elapsed += OnElapsed; _random = new Random(); //TODO: refactor, handle correctly try { _wordsCollectionService = WordsCollectionService.CreateWordsCollectionService(WordsSettings.WordsAsapSettings); } catch (Exception e) { DefaultMessageService.MessageService.ShowErrorMessage("WordsAsap Error", e.ToString()); //TODO: add log } WordsSettings.SettingsChanged += WordsSettings_SettingsChanged; }
/// <summary>ShowDialog</summary> /// <param name="owner">Any object that implements an IWin32Window interface that represents a top-level window /// that will own the modal dialog box.</param> /// <remarks>Whether by design or flaw, when a dialog box is run from outside the main application window's thread /// it will not block the main window. That is, non-modally. To force a dialog box created outside the main thread /// to block user commands from reaching the main window, we need to ask the main window to run the dialog box. /// This function provides the extra steps necessary to make the dialog boxes run properly.</remarks> public new DialogResult ShowDialog() { // Invoking a dialog box from outside the main window's thread requires a little jury-rigging. We need to ask // the main window of the application to run the dialog for us, otherwise it runs modally (if that's an // real adverb). Details are: create a delegate that matches the parameters we want to pass in and out of the // dialog box's 'ShowDialog' method. Then, ask the main window (that we extract from the process information) // to run the dialog box on our behalf (we're in a different thread here). Return the thread-safe results // back to the caller. Note that I did try to use the 'Forms.ActiveForm', but found it to be too unreliable // to get the main window for the application when accessed from a DLL. ShowDialogDelegate showDialogDelegate = new ShowDialogDelegate(ShowDialogHandler); Form mainForm = (Form)Form.FromHandle(Process.GetCurrentProcess().MainWindowHandle); DialogResult dialogResult = (mainForm == null) ? base.ShowDialog() : (DialogResult)mainForm.Invoke(showDialogDelegate, new object[] { mainForm }); // If one of the URL strings was selected, then remember it in the user preferences. if (dialogResult == DialogResult.OK) { // update the credential info see if the password changed this.NetworkCredential.UserName = this.textBoxUserName.Text; this.NetworkCredential.Password = this.textBoxPassword.Text; this.NetworkCredential.Domain = this.textBoxDomain.Text; // Save the Credential Info (Note that the password is not saved for security reasons). UserPreferences.LocalSettings[usernameKey] = this.NetworkCredential.UserName; UserPreferences.LocalSettings[domainKey] = this.NetworkCredential.Domain; } // The caller uses this value to determine how the user exited the dialog. return(dialogResult); }
public MessageBox(string message, string title, bool info) { InitializeComponent(); if (title == TextError) title = Program.language.getMessage(MsgList.MsgBoxTitle_Error); else title = Program.language.getMessage(MsgList.MsgBoxTitle_Information); this.Text = String.Format(MessageBox.TitleFormat, title); this.text.Text = String.Format(MessageBox.MessageFormat, message); if (info) this.picture.Image = Properties.Resources.Information; if (MessageBox.parentForm != null) { if (MessageBox.parentForm.InvokeRequired) { ShowDialogDelegate d = new ShowDialogDelegate(this.ShowDialog); MessageBox.parentForm.Invoke(d, MessageBox.parentForm); } else { this.ShowDialog(MessageBox.parentForm); } } else this.ShowDialog(); }
private void ShowDialog(bool type) { if (InvokeRequired) { ShowDialogDelegate method = new ShowDialogDelegate(ShowDialog); Invoke(method, type); return; } using (DialogForm1 di = new DialogForm1(type)) { di.ShowDialog(this); } }
public MessageBox(string message, string title, bool info) { InitializeComponent(); if (title == TextError) { title = Localizate.getMessage(Word.ERROR); } else { title = Localizate.getMessage(Word.INFO); } Text = String.Format(TitleFormat, title); text.Text = String.Format(MessageFormat, message); if (info) { picture.Image = Resources.Information; } if (parentForm != null) { if (parentForm.InvokeRequired) { ShowDialogDelegate d = ShowDialog; parentForm.Invoke(d, parentForm); } else { ShowDialog(parentForm); } } else { ShowDialog(); } }
public MessageBox(string message, string title, bool info) { InitializeComponent(); if (title == TextError) { title = Program.language.getMessage(MsgList.MsgBoxTitle_Error); } else { title = Program.language.getMessage(MsgList.MsgBoxTitle_Information); } this.Text = String.Format(MessageBox.TitleFormat, title); this.text.Text = String.Format(MessageBox.MessageFormat, message); if (info) { this.picture.Image = Properties.Resources.Information; } if (MessageBox.parentForm != null) { if (MessageBox.parentForm.InvokeRequired) { ShowDialogDelegate d = new ShowDialogDelegate(this.ShowDialog); MessageBox.parentForm.Invoke(d, MessageBox.parentForm); } else { this.ShowDialog(MessageBox.parentForm); } } else { this.ShowDialog(); } }
private void WaitingBluetooth() { try { connectDatabase(); string stm = "SELECT * FROM folderlock.folder"; MySqlCommand cmd = new MySqlCommand(stm, conn); MySqlDataReader rdr = null; rdr = cmd.ExecuteReader(); for (i_strArray = 0; rdr.Read(); i_strArray++) { strArray[i_strArray] = new string[4]; for (int j = 0; j <= 3; j++) { strArray[i_strArray][j] = rdr.GetString(j); } } bc = new BluetoothClient(); BluetoothDeviceInfo[] array = bc.DiscoverDevicesInRange(); getMacDevice(); bool flag = false; BluetoothDeviceInfo bd; ChangeScanDeviceBtnDelegate changeScanbtn = new ChangeScanDeviceBtnDelegate(ChangeEnabledScanDeviceBtn); UpdateDataGridViewDelegate updateDataGrid = new UpdateDataGridViewDelegate(UpdateDataGridView); chay: foreach (BluetoothDeviceInfo bdi in array) { try { if (bdi.DeviceAddress.ToString().Equals(deviceMac)) { bd = bdi; if (bc.Connected == false) { bc.Connect(new BluetoothEndPoint(bd.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.Handsfree)); //.BluetoothService.SerialPort bd.SetServiceState(InTheHand.Net.Bluetooth.BluetoothService.Handsfree, true); //.BluetoothService.SerialPort } bd.Refresh(); if (bd.Connected) { flag = true; flag_connect = true; di = new ShowDialogDelegate(ShowDialog); di.Invoke(true); ObjectDelegate del = new ObjectDelegate(UpdateForm); del.Invoke(bd.DeviceName.ToString(), bd.ClassOfDevice.MajorDevice.ToString(), bd.Authenticated.ToString()); ChangeSizeMainFormDelegate csd = new ChangeSizeMainFormDelegate(ChangeSizeForm); csd.Invoke(463, 383); string bd_DeviceMac = bd.DeviceAddress.ToString(); if (connectDatabase()) { try { bool flagunlock = true; string patherr = ""; int i = 0; while (i < i_strArray) { if (strArray[i][2].Equals("True") && strArray[i][3].Equals("True")) //strArray[i][2]: Thuộc tính Auto Lock, strArray[i][3]: Thuộc tính Locked { if (!unlockFolder(strArray[i][0], strArray[i][1])) { flagunlock = false; patherr += strArray[i][1] + "\n"; } } i++; } if (!flagunlock) { MessageBox.Show("Không thể mở khóa thành công các thư mục sau: \n" + patherr, "Không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } updateDataGrid(); SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero); //refresh Desktop and Windows Explorer } catch (Exception ex) { MessageBox.Show("Không thể kết nối với Database4", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } changeScanbtn.Invoke(true, "Stop..."); while (true) { //if (flag_connect == true) //flag_connect: kiểm tra nếu là true thì refesh, false thì không refresh bd.Refresh(); bool bd_Connected = bd.Connected; if (flag_connect == true && bd_Connected == false) //flag_connect: { //không tìm thấy thiết bị, khóa tất cả các thư mục //update Form status-name-type //del.Invoke(bd.DeviceName.ToString(), bd.ClassOfDevice.MajorDevice.ToString(), bd.Authenticated.ToString()); del.Invoke("None", "None", "False"); di = new ShowDialogDelegate(ShowDialog); di.Invoke(false); try { csd = new ChangeSizeMainFormDelegate(ChangeSizeForm); csd.Invoke(232, 187); UpdateDatabase(); bool flag_success = true; string pathError = ""; int i = 0; while (i < i_strArray) { if (strArray[i][2].Equals("True") && strArray[i][3].Equals("False"))//True { if (!lockFolder(strArray[i][0], strArray[i][1])) { flag_success = false; pathError += strArray[i][1] + "\n"; } } i++; } if (!flag_success) { MessageBox.Show("Không thể khóa thành công tất cả các thư mục sau:\n" + pathError, "Không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } updateDataGrid(); SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero); //refresh Desktop and Windows Explorer flag_connect = false; } catch (Exception ex) { MessageBox.Show("Không thể kết nối với Database3", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (flag_connect == false && bd_Connected == true && bd_DeviceMac.Equals(deviceMac)) { //tìm thấy thiết bị, mở khóa tất cả các thư mục //update Form status-name-type del.Invoke(bd.DeviceName.ToString(), bd.ClassOfDevice.MajorDevice.ToString(), bd.Authenticated.ToString()); di = new ShowDialogDelegate(ShowDialog); di.Invoke(true); try { csd = new ChangeSizeMainFormDelegate(ChangeSizeForm); csd.Invoke(463, 383); UpdateDatabase(); bool flag_success = true; string pathError = ""; int i = 0; while (i < i_strArray) { if (strArray[i][2].Equals("True") && strArray[i][3].Equals("True")) { if (!unlockFolder(strArray[i][0], strArray[i][1])) { flag_success = false; pathError += strArray[i][1] + "\n"; } } i++; } if (!flag_success) { MessageBox.Show("Không thể khóa thành công tất cả các thư mục sau:\n" + pathError, "Không thành công", MessageBoxButtons.OK, MessageBoxIcon.Error); } updateDataGrid(); SHChangeNotify(0x8000000, 0x1000, IntPtr.Zero, IntPtr.Zero); //Refresh Desktop and Windows Explorer flag_connect = true; } catch (Exception ex) { MessageBox.Show("Không thể kết nối với Database2", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (flag_connect == false && bd_Connected == false) { bc = null; bc = new BluetoothClient(); array = bc.DiscoverDevicesInRange(); foreach (BluetoothDeviceInfo bd_t in array) { if (bd_t.DeviceAddress.ToString().Equals(deviceMac)) { bd = bd_t; bc.Connect(new BluetoothEndPoint(bd.DeviceAddress, InTheHand.Net.Bluetooth.BluetoothService.Handsfree)); //.BluetoothService.SerialPort bd.SetServiceState(InTheHand.Net.Bluetooth.BluetoothService.Handsfree, true); //.BluetoothService.SerialPort } } } } } else { MessageBox.Show("Không thể kết nối với Database1", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Thiết bị chưa được kết nối", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); bc = null; flag = false; } flag = true; break; } } catch (Exception) { } } if (!flag) { //MessageBox.Show("Không tìm thấy đúng thiết bị cần kết nối", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); //changeScanbtn(true, "Scan Device..."); //StopThreadDelegate sthread = new StopThreadDelegate(stopThread); //sthread.Invoke(); //return; goto chay; } //else { changeScanbtn.Invoke(true, "stop"); StopThreadDelegate stpth = new StopThreadDelegate(stopThread); stpth.Invoke(); //} } catch (Exception ex) { int i = 0; while (i < i_strArray) { if (strArray[i][2].Equals("True") && strArray[i][3].Equals("False"))//True { lockFolder(strArray[i][0], strArray[i][1]); } i++; } } }
public bool?ShowDialog(ShowDialogDelegate showDialogDelegate) { return(showDialogDelegate(Window)); }
public bool?ShowDialog(object viewModel, ShowDialogDelegate showDialogDelegate) { var window = GetViewModelWindowOrCurrent(viewModel); return(showDialogDelegate(window)); }
public bool?ShowDialog(ShowDialogDelegate showDialogDelegate) { return(ShowDialog(null, showDialogDelegate)); }