8. diel - Bitové operátory, odpočúvanie klávesov, kreslenie - isim
ChatForm.cs
Taj sa pošéfí Odpočúvanie klávesov (zmena tabu, zatvorenie tabu).
Zaujímavé je tu totok ->
if (keyData == (Keys.Control | Keys.Shift | Keys.Tab))
-> | (OR)
je tzv. Bitový operátor logického súčtu. Funguje to tak, že spočíta
jednotlivé bity a porovná ich. Najlepšie je si to vyskúšať napríklad
Console.WriteLine(3 | 2)
čo vypíše?
Logický súčet | OR
3 -> 0101 2 -> 0011 1000 -> 8
Je potom ešte logický súčin &
(AND) a non ekvivalencie
^
(XOR) a známa negácia !
(NOT)
Logický súčin & AND
3 -> 0101 2 -> 0011 0001 -> 1
Non ekvivalencie ^
3 -> 0101 2 -> 0011 0110 -> 6
A negácia je jasná! 1 = 0,! 0 = 1
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Control | Keys.Shift | Keys.Tab)) { if (chatTabs.SelectedIndex > 0) chatTabs.SelectedIndex--; else chatTabs.SelectedIndex = chatTabs.TabPages.Count - 1; return true; } else if (keyData == (Keys.Control | Keys.Tab)) { if (chatTabs.SelectedIndex < chatTabs.TabPages.Count - 1) chatTabs.SelectedIndex++; else chatTabs.SelectedIndex = 0; return true; } if ((keyData == Keys.Escape) || (keyData == (Keys.Control | Keys.W))) { chatTabs.RemoveTab(chatTabs.SelectedTab); if (chatTabs.TabCount == 0) this.Close(); } return base.ProcessCmdKey(ref msg, keyData); }
U TabControl komponenty je Vlastnosť DrawMode
keď tam
nastavíme OwnerDrawFixed
môžeme v udalosti DrawItem
a ostatných Draw udalostiach kresliť čo chceme. Ja som si urobil takýto
krásny kresleníčko.
private void chatTabs_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) return; using (Brush textBrush = new SolidBrush(Color.White)) { ChatTabPage tab = (ChatTabPage)chatTabs.TabPages[e.Index]; // Rámečky if ((e.State == DrawItemState.Selected) && ((tab.contact != null) || (tab.contact == null))) e.Graphics.FillRectangle(Brushes.White, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); else if ((tab.contact != null) && (tab.contact.unreadedMessage == true)) e.Graphics.FillRectangle(Brushes.Orange, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); else e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); // Ikonka dostupnosti, případně psaní nepřečtené zprávy Bitmap image; if ((tab.contact != null) && (tab.contact.unreadedMessage == true)) image = new Bitmap(Global.appRunPath + "graphics" + Path.DirectorySeparatorChar + "messageIcon.png"); else { if (Global.OpenForms.mainForm.contactListView.Items.ContainsKey(tab.Name)) image = Global.Converter.GetContactAvailabilityImage(tab.contact.availability); else image = new Bitmap(Global.appRunPath + "graphics" + Path.DirectorySeparatorChar + "conferenceIcon.png"); } e.Graphics.DrawImage(image, e.Bounds.Left + 5, e.Bounds.Top + 5, 12, 12); e.Graphics.DrawString(tab.contact.name.SortText(20), e.Font, Brushes.Black, e.Bounds.Left + 17, e.Bounds.Top + 3); } }