Computing Form Location with Button
        Posted  
        
            by 
                user2934515
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user2934515
        
        
        
        Published on 2013-10-30T02:35:22Z
        Indexed on 
            2013/10/30
            3:54 UTC
        
        
        Read the original article
        Hit count: 144
        
I'm working on a programming assignment, and I'm trying to make this button take the values from two textboxes, and calculate the new location for the form window. I'm having trouble converting the textbox values to type int, and being made usable by the btnCompute_click method.
    private void btnCompute_Click(object sender, EventArgs e)
    {
        int x = Convert.ToInt32(txtXvalue);
        int y = Convert.ToInt32(txtYvalue);
        Location = new Point(x,y);
    }
    private void xValue_TextChanged(object sender, EventArgs e)
    {
        int xValue =
            Convert.ToInt32(txtXvalue);
    }
    private void yValue_TextChanged(object sender, EventArgs e)
    {
        int y =
            Convert.ToInt32(txtYvalue);
    }
I forgot to add some additional info, the acceptable values for x and y must be positive. Would I use an if...else statement to control the acceptable values?
© Stack Overflow or respective owner