开发者

Update Label Without Button

Is there a way to make a label automatically update itself so that I don't have to use a button to send out the command. What I have setup is a subtotal textbox, discount textbox, tax label, shipping textbox, and total label. So, when people fill in the subtotal, discount, and shipping, I want the tax label to be calculated, but only if previously a 开发者_Python百科certain state was selected in another part of the form. So then, with all those filled in, I want the total label to be filled in. All of these I know I can do with a button, but I was wondering if there is a way to automate it using C# in Visual Studio.

Thanks.


I use the TextChanged Event to update such values between pairs of textboxes. Here are some extracts of my code:

private void onLongitudeTextChanged(object sender, EventArgs e) {
           updateDistanceAndBearing();
        }

updateDistanceAndBearing does some error checking - this can be a good idea if the user can put invalid values in and then updates the Text property of the other TextBoxes I have text boxes but update the label.Text property instead.

It gets more messy (at least I found it so) if you have numeric updowns to get values


You can call a method to update the label in the change events for the controls.

For more detail, please supply more detail.


this is off the top of my head but should get you pretty close...

private void taxChanged(object sender, EventArgs e)
        {
             updateTax();
        }


private void updateTax()
        {
            // the rest of your logic, checking state, etc. 
            // 
            this.Tax.Text = aValueCalculatedInYourLogicAbove;
            updateTotal()
        }

private void updateTotal()
        {
            // sum up whatever fields need to be summed 
            // 
            this.Tax.Text = aTotalValueCalculatedAbove;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜