Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Properties does not change in custom MouseEnter event incomplete implementation.

Properties does not change in custom MouseEnter event incomplete implementation.

Scheduled Pinned Locked Moved C#
graphicscsharplinqquestion
27 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ _Q12_

    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.

    _ Offline
    _ Offline
    _Q12_
    wrote on last edited by
    #18

    Imgur: The magic of the Internet[^]

    OriginalGriffO 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      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!

      _ Offline
      _ Offline
      _Q12_
      wrote on last edited by
      #19

      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.

      _ 1 Reply Last reply
      0
      • _ _Q12_

        Imgur: The magic of the Internet[^]

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #20

        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!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        _ 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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!

          _ Offline
          _ Offline
          _Q12_
          wrote on last edited by
          #21

          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...

          OriginalGriffO 1 Reply Last reply
          0
          • _ _Q12_

            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...

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #22

            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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            _ 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              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!

              _ Offline
              _ Offline
              _Q12_
              wrote on last edited by
              #23

              yes, it makes sense...because I was thinking in the same direction too. I will go with your idea. I am building it now.

              _ 1 Reply Last reply
              0
              • _ _Q12_

                yes, it makes sense...because I was thinking in the same direction too. I will go with your idea. I am building it now.

                _ Offline
                _ Offline
                _Q12_
                wrote on last edited by
                #24

                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();
                    }
                
                }
                
                _ 1 Reply Last reply
                0
                • _ _Q12_

                  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();
                      }
                  
                  }
                  
                  _ Offline
                  _ Offline
                  _Q12_
                  wrote on last edited by
                  #25

                  Thank you so far, mister OriginalGriff !

                  OriginalGriffO 1 Reply Last reply
                  0
                  • _ _Q12_

                    Thank you so far, mister OriginalGriff !

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #26

                    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!

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    _ 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      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!

                      _ Offline
                      _ Offline
                      _Q12_
                      wrote on last edited by
                      #27

                      I am not 100% sure my code is the most efficient. I have the feeling i overdo something. I cant put my finger on it yet. But i feel it. I hope it will not bite my ass after some usage. Or maybe i am too careful. Eh... We'll see.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups