Chernarussian
Chernarussian

Reputation: 45

C# - Creating X and Y axis with customizable rectangles

I'm working on a school project.

The goal is to create X and Y axis with numbers, that part I can handle.

Problem is, I have to create numericUpDowns that will allow me to create rectangles on specific X and Y axis with specific size. The size and position is to be controlled by the numericUpDowns. I could use some help as I do not know any command that could connect the two.

Also if there is a way for the numbers on the axis to repeat itself without me having to write it individualy then I could use that as well.

How it should look

        public void tvary(float x, float y, float polomer, Graphics gr)
        {

        gr.DrawEllipse(Pens.Black, x, y, polomer, polomer);
        gr.DrawEllipse(Pens.Black, x - 15, y - 15, polomer * 2, polomer * 2);
        gr.DrawEllipse(Pens.Black, x - 30, y - 30, polomer * 3, polomer * 3);

        gr.DrawRectangle(Pens.Red, x-30, y-30, polomer * 3, polomer * 3);
        }

Right now the X and Y position of the rectangles are written in the code itself. I would like to move the rectangles by using the numericUpDows that are shown on Pic 3. The thing is that I do not know how to do that.

Unfortunately I cannot post more than 1 picture at the moment.

Upvotes: 2

Views: 368

Answers (1)

MiOnIs
MiOnIs

Reputation: 125

NumericUpDownhave ValueChanged ActionEvent. So every time when you change the value in NumericUpDown method for that action will be execute. You just need in method for ActionEvent to call your method for drawing rectangle. So you need to send parameters for x and y. First you need to take it from NumericUpDown

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
    int x = Convert.ToInt16(numericUpDown1.Value);
    int x = Convert.ToInt16(numericUpDown2.Value);
    tvary(x, y, polomer, gr);
}

code is the same for second numericUpDown.

PS: You can put start Value for numericUpDown control.

Upvotes: 1

Related Questions