Hi! i'v got problem in visual c#... i want that when i enter a position in my form in a text field then the button that is in the same position get activated... how can i do that?
i'm beginner in Visual C# so is there any method for doing this?!
Thanks. . . !

Your description is kind of vague. Perhaps uploading the code you're using will make it clearer.

I Don't have any idea about piece of code! Any suggestions?!

Your button control will have a Left and Top property along with a Width and Height property. When you type in your co-ordinates, ensure that the X position is inside the leftmost position plus the width and that the Y position is inside the topmost position plus its height.

You should iterate a loop that checks each control on the form. foreach will help here. When you find the control in that position, you can check if it is a button. If it is, you can perform a click to run the code the button would execute.

commented: Most help you will get, short of us writing the code for you. +6

Do you want the button to show when you put the cursor over a particular text box or when a particular textbox is clicked?

Do you mean by "activated" that a button gets clicked?

no...when i send position to a button then button gets activated,how can i do that?

You're not making much sence.

Are you trying to say that you want to type into a textbox, the postion that you want the button appear, and then you want the button to appear in the position you have typed into the textbox?

You need to make your question a lot more clear.

when i enter a position in my form in a text field then the button that is in the same position get activated

        private PointConverter pc = new PointConverter();
        private void button2_Click(object sender, EventArgs e)
        {
            Point pt ;
            Button b = null;
            try
            {
                if(!String.IsNullOrEmpty(textBox1.Text))
                {
                    pt = (Point) pc.ConvertFromString(textBox1.Text);
                    Control c = this.GetChildAtPoint(pt);

                    if (c != null && c is Button)
                    {
                        b = (Button)c;
                    }
                }


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            if (b != null)
            {
                // not sure if you mean focus the button
                b.Focus();
                // or click it
                b.PerformClick();
            }
        }

what this code really do?!
there isn't any performclick() method in c#

ChrisHunter that's right that is my question....

what this code really do?!
there isn't any performclick() method in c#

It does what I I interpreted your question to be. It locates a button control at a give location and if it is a button, it executes the Button.PerformClick method of the button. I assumed that you are working on a WinForm project.

How Can i Get An Element Postion and Save it to An integer?!

Why are your questions always so vague?
In fact you should have started it in a new thread. And if this thread has answered your question you could mark it as solved.
I'm just inferring you want to stuff two ints X and Y, into one.
So let's say the domain or range of your positions is 0 . . 127 (just guessing what your intentions are you know) You could stuff your int positions into one int, with this formula: 128*X + Y.
Extract the X and Y with div and mod operations. Hope this helps. :)

@Peymankop. The best thing to do it to have two text boxes two allow the user enter to numbers, on for the X axis and 1 for the y axis. Then, once both values have been entered you want to get the size of the form the the button will be displayed and check that the numbers the user has entered for the X and Y axis of the button DO NOT exceed the size of the form that the button will be displayed on. If the values entered for the X and Y of the button do not exceed the size of the form then set the X and Y values of the buttons Location property with the X and Y values entered by the user and set the Visibility property of the button to true (set Visibilty to false in design mode so that it isn't shown as soon as the application is run).

Hope this helps. Please understand we can't give you the complete code as it would be doing your work for you. However we can give you as much guidence as we can to help you achieve what you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.