protected override void OnStart(AppHost host) { var box_beh = new UIMouseBehaviour <Box>(); { box_beh.GuestMsg += (s, e) => { }; box_beh.MouseDown += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Pointer; }; box_beh.MouseUp += (s, e) => { e.MouseCursorStyle = MouseCursorStyle.Default; //box.BackColor = Color.LightGray; s.Source.BackColor = Color.FromArgb(50, KnownColors.FromKnownColor(KnownColor.DeepSkyBlue)); }; box_beh.MouseDrag += (s, e) => { Box box = s.Source; box.BackColor = Color.FromArgb(180, KnownColors.FromKnownColor(KnownColor.GreenYellow)); Point pos = box.Position; box.SetLocation(pos.X + e.XDiff, pos.Y + e.YDiff); e.MouseCursorStyle = MouseCursorStyle.Pointer; e.CancelBubbling = true; }; } //------------- { var box1 = new LayoutFarm.CustomWidgets.Box(50, 50); box1.BackColor = Color.Red; box1.SetLocation(10, 10); box_beh.AttachSharedBehaviorTo(box1); host.AddChild(box1); } //-------------------------------- { var box2 = new LayoutFarm.CustomWidgets.Box(30, 30); box2.SetLocation(50, 50); //box2.dbugTag = 2; box_beh.AttachSharedBehaviorTo(box2); host.AddChild(box2); } }
protected override void OnStart(AppHost host) { int x_pos = 0; //create behaviour for specific host, => LayoutFarm.CustomWidgets.Box var beh = new UIMouseBehaviour <LayoutFarm.CustomWidgets.Box, object>(); beh.MouseEnter += (s, e) => { LayoutFarm.CustomWidgets.Box box = s.Source; box.BackColor = _mouseEnterState; #if DEBUG System.Diagnostics.Debug.WriteLine("mouse_enter:" + box.dbugId); #endif }; beh.MouseLeave += (s, e) => { LayoutFarm.CustomWidgets.Box box = s.Source; box.BackColor = _normalState; #if DEBUG System.Diagnostics.Debug.WriteLine("mouse_leave:" + box.dbugId); #endif }; beh.MouseHover += (s, e) => { LayoutFarm.CustomWidgets.Box box = s.Source; box.BackColor = _hoverState; #if DEBUG System.Diagnostics.Debug.WriteLine("mouse_hover:" + box.dbugId); #endif }; beh.MousePress += (s, e) => { LayoutFarm.CustomWidgets.Box box = s.Source; Color back_color = box.BackColor; box.BackColor = new Color((byte)System.Math.Min(back_color.A + 10, 255), back_color.R, back_color.G, back_color.B); #if DEBUG System.Diagnostics.Debug.WriteLine("mouse_press:" + box.dbugId); #endif }; for (int i = 0; i < 10; ++i) { var sampleButton = new LayoutFarm.CustomWidgets.Box(30, 30); sampleButton.BackColor = _normalState; sampleButton.SetLocation(x_pos, 10); beh.AttachSharedBehaviorTo(sampleButton); host.AddChild(sampleButton); x_pos += 30 + 5; } }