Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > .NET для новичков > Обработка событий от кнопки из формы...


Автор: olympico 19.12.2007, 10:06
Люди, вот код:

Код

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 order
{
    public partial class order : Form
    {
        public order()
        {
            InitializeComponent();
        }
        private void button_Click(object sender, EventArgs e)
        {
            if (text_info.Text == "")
            {
                MessageBox.Show("Ошибка в заполнении.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show("Заказ отправлен.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                // Send Mail
                //    MailAddress to = new MailAddress("[email protected]");
                //    MailAddress from = new MailAddress("[email protected]");
                //    MailMessage message = new MailMessage(from, to);
                //    message.Subject = "Новый заказ.";
                //    message.Body = 
                //     "#Дата поездки:" + send_date.Text + "\n" +
                //     "#Время подачи:" + time_hour.Text + ":" + time_minute.Text + "\n" +
                //     "#Дополнительная информация:" + info.Text + "\n" +
                //    SmtpClient client = new SmtpClient("relay.comstar.ru");
                //    client.Send(message);
            }
        }
    }
}


Не понятно почему кнопка не реагирует при нажатии на нее?!?!?!?
C# занялся недавно, поэтому не взыщите...

Автор: QryStaL 19.12.2007, 10:18
Есть такая строчка в файле *.designer.cs

Код

this.button.Click += new EventHandler(this.button_Click);


?

Автор: olympico 19.12.2007, 10:20
вот этот файл, строчки нет?!

Код

namespace order
{
    partial class order
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(order));
            this.date = new System.Windows.Forms.DateTimePicker();
            this.text_info = new System.Windows.Forms.TextBox();
            this.button = new System.Windows.Forms.Button();
            this.logo = new System.Windows.Forms.PictureBox();
            ((System.ComponentModel.ISupportInitialize)(this.logo)).BeginInit();
            this.SuspendLayout();
            // 
            // date
            // 
            this.date.Location = new System.Drawing.Point(12, 70);
            this.date.Name = "date";
            this.date.Size = new System.Drawing.Size(200, 20);
            this.date.TabIndex = 0;
            // 
            // text_info
            // 
            this.text_info.Location = new System.Drawing.Point(12, 96);
            this.text_info.Multiline = true;
            this.text_info.Name = "text_info";
            this.text_info.Size = new System.Drawing.Size(200, 55);
            this.text_info.TabIndex = 1;
            // 
            // button
            // 
            this.button.AutoEllipsis = true;
            this.button.Location = new System.Drawing.Point(12, 155);
            this.button.Name = "button";
            this.button.Size = new System.Drawing.Size(75, 25);
            this.button.TabIndex = 2;
            this.button.Text = "send";
            this.button.UseVisualStyleBackColor = true;
            // 
            // logo
            // 
            this.logo.Image = ((System.Drawing.Image)(resources.GetObject("logo.Image")));
            this.logo.Location = new System.Drawing.Point(12, 12);
            this.logo.Name = "logo";
            this.logo.Size = new System.Drawing.Size(150, 34);
            this.logo.TabIndex = 3;
            this.logo.TabStop = false;
            // 
            // order
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(269, 194);
            this.Controls.Add(this.logo);
            this.Controls.Add(this.button);
            this.Controls.Add(this.text_info);
            this.Controls.Add(this.date);
            this.Name = "order";
            this.Text = "order";
            ((System.ComponentModel.ISupportInitialize)(this.logo)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.DateTimePicker date;
        private System.Windows.Forms.TextBox text_info;
        private System.Windows.Forms.Button button;
        private System.Windows.Forms.PictureBox logo;
    }
}


Автор: QryStaL 19.12.2007, 10:24
Нету
Добавь ее после 62-й.

Автор: olympico 19.12.2007, 10:24
мне добавить эту строку? если да, то как это делается через интерфейс при создании кнопки?
это нужно писать самостоятельно всегда или уже есть предусмотренный вариант на реагирование?*

Автор: QryStaL 19.12.2007, 10:28
Кидаешь кнопку на форму, делаешь по ней дабл-клик, студия создает обработчик события, в котором уже пишешь свой код...

Или в твоем варианте, Properties кнопки -> Events -> Событие Click, в выпадающем списке выбираешь свой метод в качестве обработчика.

Автор: olympico 19.12.2007, 10:32
мда Visual Studio 2008 и Event-а в properties не нашел, хм(
все понял)))

Автор: QryStaL 19.12.2007, 10:38
Символ с изображением молнии...

Автор: olympico 19.12.2007, 10:54
спасибо, впечетляет)

Автор: QryStaL 19.12.2007, 11:10
Что впечатляет-то? )

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)