0

i need help... i want to create a window (a form) in c# that creates an hidden grid with a picturebox, let me explain: you can use the picturebox as a button, i want that if the highest point has value 2.0f (i want it in float for making it more accurate) and the lowest point has value 0.0f, if i click the center i will get 1.0f, i want to store that float in another float (let's call it "GridFloat") and if if i click the "half of the half" (the one more than 1.0f) i will get 1.5f

tried to make some logic and mathematic and tried with like / as chatgpt tought

piruz
  • 1
  • Not sure about what you are asking. Check some Q&A for some ideas. https://stackoverflow.com/a/66523013/14171304 -- https://stackoverflow.com/a/62206805/14171304 -- https://stackoverflow.com/a/52044619/14171304. – dr.null Jul 04 '23 at 16:44
  • Please edit your question to show code of what you've already tried. – Hayden Jul 04 '23 at 22:03

1 Answers1

0

I think you're looking for click event like this

        private void gridPictureBox_Click(object sender, EventArgs e)
    {
        Point mousePosition = gridPictureBox.PointToClient(MousePosition);
        float gridFloat = gridPictureBox.Height - mousePosition.Y;
        lbl_clickValueDisplayer.Text = $"{(gridFloat / 100):F2}";
    }

I went ahead and made an example here.

  • hi, the program is working well, now just another thing: what i need to do if i want to make that clicking the center, the value of Y it's 0, if i click the top the Y has value 1 (so the bottom is -1); if i click on the maximum left then happens the same thing – piruz Jul 09 '23 at 14:35
  • I would just change the Y value programmatically with math (Y++) so my Y value would always have a range from 0 to 2. I am having a hard time understanding your question here though, are you trying to get an X and Y value? – Robert Green Jul 13 '23 at 15:32