コンボボックスを使って簡単なプログラムを書こうとしています。ただし、プログラムの実行時にドロップダウンメニューで選択できるものはありません。さらに、プログラムの最初で整数をテキストに解析しようとすると、問題が発生すると思います。しかし、私はまだこれを修正するのに十分なスキルを持っていません:(。以下は私のコードとビジュアルスタジオからのエラーです:
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 testerv1._01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnBuyEU_Click(object sender, EventArgs e)
{
int n = int.Parse(cbxBuyEU.Text);
int price = 0;
switch (n)
{
case 1:
price += 25;
break;
case 2:
price += 25;
goto case 1;
case 3:
price += 50;
goto case 1;
default:
MessageBox.Show("you made a wrong choice..");
break;
}
if (price != 0)
{
MessageBox.Show("deposit "+ price +"");
}
MessageBox.Show("thank you and good buy");
}
}
}
エラーは次のとおりです。
System.FormatException was unhandled
Message=Input string was not in a correct format.
Source=mscorlib
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at testerv1._01.Form1.btnBuyEU_Click(Object sender, EventArgs e) in C:\Documents and Settings\jjj\my documents\visual studio 2010\Projects\testerv1.01\testerv1.01 \Form1.cs:line 21
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at testerv1._01.Program.Main() in C:\Documents and Settings\jjj\my documents\visual studio 2010\Projects\testerv1.01\testerv1.01\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()