private void BTN_Searching_Click(object sender, EventArgs e) //Searching for Publish Year Button { Book[] books; books = BooksFunctions.Search(yearsearch, 1); //to call searching function of the book by the Publish Year if (books == null) { MessageBox.Show("This Book is not found"); TXT_Searching.Text = ""; } else { string[] Lines = new string[(books.Length * 5) - 1]; //Array of strings to Put each field in a line with a seperator between each record int index = 0; for (int i = 0; i < books.Length; i++) //Loop to put each field in the string array inorder to display them { Lines[index++] = "Serial Number: " + books[i].serialNo; Lines[index++] = "Book Name: " + books[i].bookName; Lines[index++] = "Publish Year: " + books[i].publishYear; Lines[index++] = "Author Number: " + books[i].authorNo; if (i != books.Length - 1) //to handle the last record inorder not to display seperator line after the last record { Lines[index++] = "----------------------------------------"; } } TXT_Searching.Lines = Lines; //function Searching.Lines is to put each single element in the array in a single line SearchingTextBox.Focus(); //To Handle a problem occurred when Displaying The Books inorder to change the mouse focus after displaying } }
protected override void WndProc(ref Message m) { if (m.Msg == (int)WM.KeyDown || m.Msg == (int)WM.KeyUp) { if (!_searchBox.Focused) { _searchBox.Visible = true; _searchBox.Focus(); } return; } else if (m.Msg == (int)WM.Char || m.Msg == (int)WM.SysChar) { NativeMethods.SendMessage(_searchBox.Handle, (WM)m.Msg, m.WParam, m.LParam); } try { base.WndProc(ref m); } catch (NullReferenceException) { } }
private void SearchingHintTextBlock_OnPreviewMouseDown(object sender, MouseButtonEventArgs e) { SearchingTextBox.Focus(); }