|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
11.08.2015, 09:43 | #1 |
Новичок
Джуниор
Регистрация: 11.08.2015
Сообщений: 2
|
Ошибка в C# Windows forms
Требуется написать простенький валютный калькулятор. Застопорился на моменте получения значения из TextBox. Пишет Ошибка 1 Элемент "Kurs" не существует в текущем контексте. c:\users\misha_000\documents\visual studio 2013\projects\consoleapplication1\c onsoleapplication1\program.cs 102 40 ConsoleApplication1
Может кто подсказать в чем ошибка? Листинг ниже: using System; using System.Drawing; using System.Windows.Forms; namespace ConsoleApplication1 { public partial class VCal: Form { [STAThread] public static void Main() { Application.EnableVisualStyles(); Application.Run(new VCal()); } public VCal() { Text = "Валютный калькулятор"; Width *= 3; Height *= 2; TextBox USD = new TextBox(); USD.Parent = this; USD.Size = new Size(60, 20); USD.Location = new Point(10, 50); Label USDLab = new Label(); USDLab.Parent = this; USDLab.Size = new Size(40, 30); USDLab.Text = "USD"; USDLab.Font = new Font("TimesNewRoman", 10); USDLab.Location = new Point(10, 20); Button USDbut = new Button(); USDbut.Parent = this; USDbut.Text = "Click"; USDbut.Font = new Font("TimesNewRoman", 6); USDbut.Size = new Size(30, 20); USDbut.Location = new Point(75, 50); TextBox UAH = new TextBox(); UAH.Parent = this; UAH.Size = new Size(60, 20); UAH.Location = new Point(10, 100); Label UAHLab = new Label(); UAHLab.Parent = this; UAHLab.Size = new Size(40, 30); UAHLab.Text = "UAH"; UAHLab.Font = new Font("TimesNewRoman", 10); UAHLab.Location = new Point(10, 80); Button UAHbut = new Button(); UAHbut.Parent = this; UAHbut.Text = "Click"; UAHbut.Font = new Font("TimesNewRoman", 6); UAHbut.Size = new Size(30, 20); UAHbut.Location = new Point(75, 100); TextBox Kurs = new TextBox(); Kurs.Parent = this; Kurs.Size = new Size(60, 20); Kurs.Location = new Point(10, 150); Label KursLab = new Label(); KursLab.Parent = this; KursLab.Size = new Size(40, 30); KursLab.Text = "Kurs"; KursLab.Font = new Font("TimesNewRoman", 10); KursLab.Location = new Point(10, 130); Button Kursbut = new Button(); Kursbut.Parent = this; Kursbut.Text = "Click"; Kursbut.Font = new Font("TimesNewRoman", 6); Kursbut.Size = new Size(30, 20); Kursbut.Location = new Point(75, 150); } private void InitializeComponent() { this.SuspendLayout(); // // VCal // this.ClientSize = new System.Drawing.Size(284, 261); this.Name = "VCal"; this.Load += new System.EventHandler(this.VCal_Load) ; this.ResumeLayout(false); } private void VCal_Load(object sender, EventArgs e) { } private void Kursbut_Clicl(object sender, EventArgs e) { int kurs = Convert.ToInt32(Kurs.Text); } } } |
11.08.2015, 21:17 | #2 |
Новичок
Джуниор
Регистрация: 11.08.2015
Сообщений: 2
|
Разобрался
Протупил, не передал ссылку на объект, так работает, может кому поможет:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ConsoleApplication1 { public partial class VCal: Form { [STAThread] public static void Main() { Application.EnableVisualStyles(); Application.Run(new VCal()); } public TextBox Q = new TextBox(); public VCal() { Text = "Валютный калькулятор"; Width *= 3; Height *= 2; TextBox USD = new TextBox(); USD.Parent = this; USD.Size = new Size(60, 20); USD.Location = new Point(10, 50); Label USDLab = new Label(); USDLab.Parent = this; USDLab.Size = new Size(40, 30); USDLab.Text = "USD"; USDLab.Font = new Font("TimesNewRoman", 10); USDLab.Location = new Point(10, 20); Button USDbut = new Button(); USDbut.Parent = this; USDbut.Text = "Click"; USDbut.Font = new Font("TimesNewRoman", 6); USDbut.Size = new Size(30, 20); USDbut.Location = new Point(75, 50); TextBox UAH = new TextBox(); UAH.Parent = this; UAH.Size = new Size(60, 20); UAH.Location = new Point(10, 100); Label UAHLab = new Label(); UAHLab.Parent = this; UAHLab.Size = new Size(40, 30); UAHLab.Text = "UAH"; UAHLab.Font = new Font("TimesNewRoman", 10); UAHLab.Location = new Point(10, 80); Button UAHbut = new Button(); UAHbut.Parent = this; UAHbut.Text = "Click"; UAHbut.Font = new Font("TimesNewRoman", 6); UAHbut.Size = new Size(30, 20); UAHbut.Location = new Point(75, 100); TextBox Kurs = new TextBox(); Kurs.Parent = this; Kurs.Size = new Size(60, 20); Kurs.Location = new Point(10, 150); Q = Kurs; Label KursLab = new Label(); KursLab.Parent = this; KursLab.Size = new Size(40, 30); KursLab.Text = "Kurs"; KursLab.Font = new Font("TimesNewRoman", 10); KursLab.Location = new Point(10, 130); Button Kursbut = new Button(); Kursbut.Parent = this; Kursbut.Text = "Click"; Kursbut.Font = new Font("TimesNewRoman", 6); Kursbut.Size = new Size(30, 20); Kursbut.Location = new Point(75, 150); } private void InitializeComponent() { this.SuspendLayout(); // // VCal // this.ClientSize = new System.Drawing.Size(284, 261); this.Name = "VCal"; this.Load += new System.EventHandler(this.VCal_Load) ; this.ResumeLayout(false); } private void VCal_Load(object sender, EventArgs e) { } private void Kursbut_Clicl(object sender, EventArgs e) { int kurs = Convert.ToInt32(Q.Text); } } } |
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
C++ и windows forms | mad_ded | Windows Forms | 3 | 05.02.2015 17:01 |
Windows forms | qwot | C# (си шарп) | 3 | 05.12.2014 22:08 |
с# windows forms | Илья2014 | Windows Forms | 2 | 15.02.2014 22:38 |
Потоки в windows forms. Непонятная ошибка | hunter03 | Windows Forms | 6 | 27.08.2013 15:12 |
windows.forms | *stRong* | Помощь студентам | 0 | 04.06.2010 04:39 |