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. C# TableLayoutPanel MouseLeave

C# TableLayoutPanel MouseLeave

Scheduled Pinned Locked Moved C#
csharpgame-devhelpquestion
3 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.
  • I Offline
    I Offline
    ikurtz
    wrote on last edited by
    #1

    greetings, i am developing a battleships clone game and i have an issue with TableLayoutPanel MouseLeave event. first MouseMove:

    private PictureBox HomeLastPicBox = new PictureBox();

    private TableLayoutPanelCellPosition homeLastPosition = new TableLayoutPanelCellPosition(0, 0); 
    
    private void HomeTableLayoutPanel\_MouseMove(object sender, MouseEventArgs e) 
    { 
    
        PictureBox NowPicControl = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location)); 
    
        if ((NowPicControl != null) && (NowPicControl != HomeLastPicBox)) 
        { 
    
            HomeLastPicBox = (PictureBox)(HomeTableLayoutPanel.GetControlFromPosition(homeLastPosition.Column, homeLastPosition.Row)); 
    
            if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER) 
            { 
                HomeLastPicBox.Image = Properties.Resources.water; 
            } 
    
            TableLayoutPanelCellPosition homeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(NowPicControl); 
    
            if (GameModel.HomeCellStatus(homeCurrentPosition.Column, homeCurrentPosition.Row) == Cell.cellState.WATER) 
            { 
                NowPicControl.Image = Properties.Resources.scan; 
            } 
            homeLastPosition = homeCurrentPosition; 
        } 
    } 
    

    this appears to function properly. now the MouseLeave event:

     private void HomeTableLayoutPanel\_MouseLeave(object sender, EventArgs e) 
    { 
        MessageBox.Show("col " + homeLastPosition.Column.ToString() + " row " + homeLastPosition.Row.ToString()); 
        if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER) 
        { 
            HomeLastPicBox.Image = Properties.Resources.water; 
            MessageBox.Show("hi"); 
        } 
        HomeLastPicBox = new PictureBox(); 
    } 
    

    this is acting strange. it goes through the code and even a "HI" is displayed but the PictureBox image is not changed to water. any ideas as to why? this does not happen all the time, only from time to time. what the above code is doing is basically scanning through the table cells and if the cell content is WATER then it updates the table cell image to SCAN and as the user moves onwards it is switching the cell image back to WATER. hope this is enough information. please ask if more is needed. thank you in advance.

    A 1 Reply Last reply
    0
    • I ikurtz

      greetings, i am developing a battleships clone game and i have an issue with TableLayoutPanel MouseLeave event. first MouseMove:

      private PictureBox HomeLastPicBox = new PictureBox();

      private TableLayoutPanelCellPosition homeLastPosition = new TableLayoutPanelCellPosition(0, 0); 
      
      private void HomeTableLayoutPanel\_MouseMove(object sender, MouseEventArgs e) 
      { 
      
          PictureBox NowPicControl = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location)); 
      
          if ((NowPicControl != null) && (NowPicControl != HomeLastPicBox)) 
          { 
      
              HomeLastPicBox = (PictureBox)(HomeTableLayoutPanel.GetControlFromPosition(homeLastPosition.Column, homeLastPosition.Row)); 
      
              if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER) 
              { 
                  HomeLastPicBox.Image = Properties.Resources.water; 
              } 
      
              TableLayoutPanelCellPosition homeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(NowPicControl); 
      
              if (GameModel.HomeCellStatus(homeCurrentPosition.Column, homeCurrentPosition.Row) == Cell.cellState.WATER) 
              { 
                  NowPicControl.Image = Properties.Resources.scan; 
              } 
              homeLastPosition = homeCurrentPosition; 
          } 
      } 
      

      this appears to function properly. now the MouseLeave event:

       private void HomeTableLayoutPanel\_MouseLeave(object sender, EventArgs e) 
      { 
          MessageBox.Show("col " + homeLastPosition.Column.ToString() + " row " + homeLastPosition.Row.ToString()); 
          if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER) 
          { 
              HomeLastPicBox.Image = Properties.Resources.water; 
              MessageBox.Show("hi"); 
          } 
          HomeLastPicBox = new PictureBox(); 
      } 
      

      this is acting strange. it goes through the code and even a "HI" is displayed but the PictureBox image is not changed to water. any ideas as to why? this does not happen all the time, only from time to time. what the above code is doing is basically scanning through the table cells and if the cell content is WATER then it updates the table cell image to SCAN and as the user moves onwards it is switching the cell image back to WATER. hope this is enough information. please ask if more is needed. thank you in advance.

      A Offline
      A Offline
      AhsanS
      wrote on last edited by
      #2

      if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
      {
      HomeLastPicBox.Image = Properties.Resources.water;
      MessageBox.Show("hi");
      }

      i wonder why are you using this

      HomeLastPicBox = new PictureBox();

      when you have already assigned the picture to this picture box in the if block. after displaying the message box you need to return. do it like this.

      if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
      {
      HomeLastPicBox.Image = Properties.Resources.water;
      MessageBox.Show("hi");
      return;
      }

      hope it helps.

      Ahsan Ullah Senior Software Engineer MCTS 2.0

      I 1 Reply Last reply
      0
      • A AhsanS

        if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
        {
        HomeLastPicBox.Image = Properties.Resources.water;
        MessageBox.Show("hi");
        }

        i wonder why are you using this

        HomeLastPicBox = new PictureBox();

        when you have already assigned the picture to this picture box in the if block. after displaying the message box you need to return. do it like this.

        if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
        {
        HomeLastPicBox.Image = Properties.Resources.water;
        MessageBox.Show("hi");
        return;
        }

        hope it helps.

        Ahsan Ullah Senior Software Engineer MCTS 2.0

        I Offline
        I Offline
        ikurtz
        wrote on last edited by
        #3

        no thats not going to work. i have made some progress. the reason im experiencing this behaviour is because mousemove is being called after the call of mouseleave.

        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