Properties does not change in custom MouseEnter event incomplete implementation.
-
i know what z-order is - its not that. I intersect the 2 squares, not putting one on top of the other. Both are z-order dependent but with diferent meanings... you will get my point very easy from my screenshot.
-
And did you google "Z-order"?
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Right - you can't do that with controls at all; you have to use Paint and draw yyour rectancgles your self. Which means that you have to do the "entry" and "exit" code yourself, by handling MouseMove in your Parent container, and manually checking which of your rectangles the mouse is currently in:you cannot use MouseEnter and MouseLeave on your own rectangles because - unless they are Controls and in which case transparent backgrounds don't work - only Controls can react to mouse events. Remove UserControl, and go back to drawing them yourself - but you will have to work out where the mouse is yourself, the system will not help you!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Right - you can't do that with controls at all; you have to use Paint and draw yyour rectancgles your self. Which means that you have to do the "entry" and "exit" code yourself, by handling MouseMove in your Parent container, and manually checking which of your rectangles the mouse is currently in:you cannot use MouseEnter and MouseLeave on your own rectangles because - unless they are Controls and in which case transparent backgrounds don't work - only Controls can react to mouse events. Remove UserControl, and go back to drawing them yourself - but you will have to work out where the mouse is yourself, the system will not help you!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
Excellent answer so far, mister OriginalGriff: "you will have to work out where the mouse is yourself, the system will not help you". Can you help me making such "manual" class? I am aware I am asking a lot...
I'd do two things: Add a Paint method to the class which takes a single parameter: the Graphics context from the Containing classes Paint event. And I'd add a Contains method returning a bool, which again takes a single parameter: a Point which it checks is inside it's "boundaries" (using the Location and Size information it contains). This could change the Name to be drawn, or that could be done externally, it depends what - exactly - you are trying to do, and how it all fits together as a complete system. The containers MouseMove calls each Human instance's Contains method so they "know" if the mouse in over them or not. (The containers MouseExit event handler can reset them all) This can call Invalidate to force a redraw as needed. The Containers Paint event also calls each Human instance's Paint method so it draws itself. Make sense?
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
I'd do two things: Add a Paint method to the class which takes a single parameter: the Graphics context from the Containing classes Paint event. And I'd add a Contains method returning a bool, which again takes a single parameter: a Point which it checks is inside it's "boundaries" (using the Location and Size information it contains). This could change the Name to be drawn, or that could be done externally, it depends what - exactly - you are trying to do, and how it all fits together as a complete system. The containers MouseMove calls each Human instance's Contains method so they "know" if the mouse in over them or not. (The containers MouseExit event handler can reset them all) This can call Invalidate to force a redraw as needed. The Containers Paint event also calls each Human instance's Paint method so it draws itself. Make sense?
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
yes, it makes sense...because I was thinking in the same direction too. I will go with your idea. I am building it now.
This is the working code so far. I will experiment with it further and I will update with new problems on the way. Also, you update it too if you feel you can help it more. I was thinking on using refractor and actually look inside original mouse move event to see how they did it there, and copy it into my class... but is planned for the future. Now, i am happy. It's some work to do but i get the transparency of the objects !
//Class
public class Human
{
private string _Name = "none";
public string Name { get { return _Name; } set { _Name = value; } }
public Point Location { get; set; }
public Size Size { get; set; }public void Paint(Graphics g) { g.DrawString(Name, new Font("Arial", 9), new SolidBrush(Color.Black), Location.X, Location.Y - 15); g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(Location.X, Location.Y, Size.Width, Size.Height)); } public bool Contains(Point point) { if (point.X >= Location.X & point.X <= Location.X + Size.Width & point.Y >= Location.Y & point.Y <= Location.Y + Size.Height) { return true; } else { return false; } } } public partial class Form1 : Form { public Form1() { InitializeComponent(); DoubleBuffered = true; //from the Invalidate() in MouseMove
//i wish i didnt use DoubleBuffered, but it does its job for the moment.
female.Name = "Alina";
female.Location = new Point(20, 20);
female.Size = new Size(30, 30);//female.MouseEnter += new EventHandler(female\_MouseEnter); } Human female = new Human(); private void Form1\_Paint(object sender, PaintEventArgs e) { female.Paint(e.Graphics); } private void Form1\_MouseMove(object sender, MouseEventArgs e) { if (female.Contains(e.Location)) { female.Name = "Gaga"; } else { female.Name = "Alina"; } Invalidate(); } }
-
This is the working code so far. I will experiment with it further and I will update with new problems on the way. Also, you update it too if you feel you can help it more. I was thinking on using refractor and actually look inside original mouse move event to see how they did it there, and copy it into my class... but is planned for the future. Now, i am happy. It's some work to do but i get the transparency of the objects !
//Class
public class Human
{
private string _Name = "none";
public string Name { get { return _Name; } set { _Name = value; } }
public Point Location { get; set; }
public Size Size { get; set; }public void Paint(Graphics g) { g.DrawString(Name, new Font("Arial", 9), new SolidBrush(Color.Black), Location.X, Location.Y - 15); g.FillRectangle(new SolidBrush(Color.Red), new Rectangle(Location.X, Location.Y, Size.Width, Size.Height)); } public bool Contains(Point point) { if (point.X >= Location.X & point.X <= Location.X + Size.Width & point.Y >= Location.Y & point.Y <= Location.Y + Size.Height) { return true; } else { return false; } } } public partial class Form1 : Form { public Form1() { InitializeComponent(); DoubleBuffered = true; //from the Invalidate() in MouseMove
//i wish i didnt use DoubleBuffered, but it does its job for the moment.
female.Name = "Alina";
female.Location = new Point(20, 20);
female.Size = new Size(30, 30);//female.MouseEnter += new EventHandler(female\_MouseEnter); } Human female = new Human(); private void Form1\_Paint(object sender, PaintEventArgs e) { female.Paint(e.Graphics); } private void Form1\_MouseMove(object sender, MouseEventArgs e) { if (female.Contains(e.Location)) { female.Name = "Gaga"; } else { female.Name = "Alina"; } Invalidate(); } }
-
You're welcome!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!
-
You're welcome!
Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!