2010-12-28 4 views
0

나는 3 개의 다른 btns에있는 winForms에서 아래 코드를 가지고있다.winForms, 가능한 경우 txtbox의 텍스트를 두 배로 변환하는 데 도움이됩니까?

저는 콘솔 애플리케이션을 주로 사용하기 때문에 winForms에 대한 지식이 매우 부족합니다. 그러나 제품의 가격 변동을 계산하는 프로그램을 만들기 위해 텍스트 상자와 버튼 및 사용자 입력을 사용하려고합니다.

기본적으로 나는 내가 뭘에 계산을 수행하고 다음 텍스트 상자 등

수로 추가하는 데 사용할 주어진 이름에 텍스트 상자 (일반적으로 두 배)에 무엇이든 변환되어 고민하고 아무도 나 좀 도와 줘? 대단히 감사하겠습니다!

감사합니다. 당신이 값으로 완료

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     public Form1 salePrice { get; private set; } 
     public Form1 discountPrice { get; private set; } 
     public Form1 vat { get; private set; } 
     public Form1 onlyVat { get; private set; } 
     public Form1 totalPrice { get; private set; } 
     public Form1 changeGiven { get; private set; } 
     public Form1 payment { get; private set; } 

     private void calcPriceAndDiscount_Click(object sender, EventArgs e) 
     { 
      salePrice = PriceBox; 
      discountPrice = DiscountBox; 

      salePrice = (salePrice - discountPrice); 

      SubtotalBox.AppendText(String.Format("{0:c}", salePrice));    
     } 

     private void calcWithVat_Click(object sender, EventArgs e) 
     { 
      onlyVat = (salePrice/100.00 * vat); 
      totalPrice = (onlyVat + salePrice); 

      totalPrice = FinalPriceBox; 
      vat = VATBox; 

      FinalPriceBox.AppendText(String.Format("{0:c}", totalPrice)); 
     } 

     private void calcPaymentMinPrice_Click(object sender, EventArgs e) 
     { 
      changeGiven = (payment - totalPrice); 

      payment = PaymentBox; 

      ChangeGivenBox.AppendText(String.Format("{0:c}", changeGiven)); 
     } 
    } 
} 

답변

2
double dbl; 
if (double.TryParse(TextBox1.Text, out dbl)) 
{ 
    // dbl contains the value of the text 
} 
else 
{ 
    // The text could not be converted to a double 
} 

:

TextBox1.Text = dbl.ToString(); 
+0

오 대단히 감사합니다! 나는 이것을 지금 시도 할 것이다. 고맙다. – Simagen

+0

네,이 답변은 완벽합니다. 다른 지역에서 저를 도울 수 있습니까? 무엇이 필요합니까? 첫 번째 버튼에있는 첫 번째 하위 텍스트 상자에 사용 된 변수를 사용하고 두 번째 버튼과 같이 다른 곳에서 사용하는 방법을 배우고 싶습니다. ur 도움에 감사드립니다. – Simagen

+0

어떤 부분입니까? 관련없는 질문이있는 경우 새로운 질문을 올리면 더 많은 눈을 느낄 수 있습니다. –

관련 문제