public PonyIcon(Pony pone) { string path; this.Pony = pone; // check that the icon we want exists. path = PonyImage.SelectImagePath(pone.Name, "MarkSmall.png").LocalPath; if (!File.Exists(path)) { return; } // create the tray icon. this.Icon = new NotifyIcon(); // load the image and convert it to an icon resource. this.Icon.Icon = System.Drawing.Icon.FromHandle((new Bitmap(path)).GetHicon()); // connect some signals. this.Icon.MouseClick += this.OnMouseClick; this.Show(); return; }
private void OnWindowLoaded(object sender, RoutedEventArgs e) { System.Windows.Controls.Image icon; Uri iconpath; // pony name menu item. iconpath = PonyImage.SelectImagePath(this.Pony.Name, "MarkSmall.png"); if (File.Exists(iconpath.LocalPath)) { icon = new System.Windows.Controls.Image(); icon.Source = new BitmapImage(iconpath); this.Menu_PonyName.Icon = icon; } this.Menu_PonyName.Header = this.Pony.Name; // hide/show the time of day sleep option. if (!this.Pony.CanDo(PonyAction.Sleep)) { this.SleepTOD.Visibility = System.Windows.Visibility.Collapsed; } else { this.SleepTOD.Visibility = System.Windows.Visibility.Visible; } // update the menu system with the ponies. PonyConfig.List.ForEach(delegate(PonyConfig pony) { MenuItem item; // add pony menu item item = new MenuItem(); item.Header = pony.Name; item.Click += delegate(object del_s, RoutedEventArgs del_e) { this.OnAddPony(pony.Name); }; this.AddPonyMenu.Items.Add(item); // change pony menu item item = new MenuItem(); item.Header = pony.Name; item.Click += delegate(object del_s, RoutedEventArgs del_e) { this.OnChangePony(pony.Name); }; this.ChangePonyMenu.Items.Add(item); }); // update the menu system with actions this pony can do. this.Pony.AvailableActions.ForEach(delegate(PonyAction a){ MenuItem item; item = new MenuItem(); item.Header = String.Format("{0} {1}", a.ToString(), PonyDirection.Left.ToString()); item.Click += delegate(object del_s, RoutedEventArgs del_e) { this.Pony.TellWhatDo(a, PonyDirection.Left, false); }; this.OtherActions.Items.Add(item); item = new MenuItem(); item.Header = String.Format("{0} {1}", a.ToString(), PonyDirection.Right.ToString()); item.Click += delegate(object del_s, RoutedEventArgs del_e) { this.Pony.TellWhatDo(a, PonyDirection.Right, false); }; this.OtherActions.Items.Add(item); }); }
/////////////////////////////////////////////////////////////////////// // instance work ////////////////////////////////////////////////////// public PonyImage(string name, PonyAction action, PonyDirection direction) { this.Action = action; this.Direction = direction; this.Load(PonyImage.SelectImagePath(name, action, direction)); }