DialogResult的用法

在程序中一旦设置DialogResult的值,接下来就会自动执行close()的方法,所以没有必要写this.close(),并且也没有必要设定closing和closed事件,其执行顺序为DialogResult=true/false->closing事件->closed事件而在调用对话框的主程序中建议如下写法:

           Win_Filter win = new Win_Filter();
            win.ShowDialog();
            result = (bool)win.DialogResult;
            if (result==false)
            {
                Shared_Data.Sub_Info_VM.bDel_Open = bDel_Open;
                Shared_Data.Sub_Info_VM.bDel_Limit = bDel_Limit;
            }

 

//dialog

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace JPT_Tester
{
    /// <summary>
    /// Interaction logic for Win_Filter.xaml
    /// </summary>
    public partial class Win_Filter : Window
    {
        public Win_Filter()
        {
            InitializeComponent();
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            this.DataContext = Shared_Data.Sub_Info_VM;
        }

    }
}
 

展开阅读全文

DialogResult的问题

08-05

private void 新增ToolStripButton_Click(object sender, EventArgs e)rn //新增水电气费rn string MyAddInfo = "现在将新增指定月份的水电气费数据,是否继续?";rn if (MessageBox.Show(MyAddInfo, "信息提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)==DialogResult .No )([color=#FF0000]这里是我的问题为什么是DialogResult .No 而不是DialogResult .Yes)[/color]rn rn return;rn rn String MySQLConnectionString = global::MyCommunity.Properties.Settings.Default.DBCommunityConnectionString;rn SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);rn MyConnection.Open();rn string MySQL = "Select Count(*) From 水电气费 WHERE 计费年份=" + this.计费年份ToolStripComboBox.Text + " AND 计费月份=" + this.计费月份ToolStripComboBox.Text + " AND 费用类型='" + this.费用类型ToolStripComboBox.Text + "' AND 楼栋名称='" + this.楼栋名称ToolStripComboBox.Text+ "'";rn SqlCommand MyCommand = MyConnection.CreateCommand();rn MyCommand.CommandText = MySQL;rn string MyCount = MyCommand.ExecuteScalar().ToString();rn if (Convert.ToInt16(MyCount) == 0)rn //插入新月份费用的业主基本信息rn MySQL = "INSERT INTO 水电气费 (楼栋名称,业主编号,业主姓名) SELECT 楼栋名称,业主编号,业主姓名 FROM 业主信息 WHERE (业主编号 NOT IN (SELECT 业主编号 FROM dbo.迁出信息)) AND (楼栋名称='" + this.楼栋名称ToolStripComboBox.Text + "')";rn MyCommand.CommandText = MySQL;rn MyCommand.ExecuteNonQuery();rn MySQL = "UPDATE 水电气费 SET 登记标志='正在登记',费用类型='" + this.费用类型ToolStripComboBox.Text + "',计费年份=" + this.计费年份ToolStripComboBox.Text + ",计费月份=" + this.计费月份ToolStripComboBox.Text+ " WHERE 登记标志 IS NULL";rn MyCommand.CommandText = MySQL;rn MyCommand.ExecuteNonQuery();rn int MyLastMonth = Convert.ToInt16(this.计费月份ToolStripComboBox.Text) - 1;rn int MyLastYear = Convert.ToInt16(this.计费年份ToolStripComboBox.Text);rn if (MyLastMonth == 0)rn rn MyLastMonth = 12;rn MyLastYear = Convert.ToInt16(this.计费年份ToolStripComboBox.Text) - 1;rn rn //将上月止数作为新月份底数rn MySQL = "Select 楼栋名称,业主编号,业主姓名,计费年份,计费月份,费用类型,表编号,表底数,表止数,计费单价 FROM 水电气费 WHERE 计费年份=" + MyLastYear.ToString() + " AND 计费月份=" + MyLastMonth.ToString() + " AND 费用类型='" + this.费用类型ToolStripComboBox.Text + "' AND 楼栋名称='" + this.楼栋名称ToolStripComboBox.Text+ "' AND 登记标志='完成登记'";rn DataTable MyComputeTable = new DataTable();rn SqlDataAdapter MyAdatper = new SqlDataAdapter(MySQL, MyConnection);rn MyAdatper.Fill(MyComputeTable);rn foreach (DataRow MyRow in MyComputeTable.Rows)rn rn string My楼栋名称 = MyRow[0].ToString();rn string My业主编号 = MyRow[1].ToString();rn string My业主姓名 = MyRow[2].ToString();rn string My计费年份 = MyRow[3].ToString();rn string My计费月份 = MyRow[4].ToString();rn string My费用类型 = MyRow[5].ToString();rn string My表编号 = MyRow[6].ToString();rn string My表底数 = MyRow[7].ToString();rn string My表止数 = MyRow[8].ToString();rn string My计费单价 = MyRow[9].ToString();rn MySQL = "UPDATE 水电气费 SET 表编号='" + My表编号 + "',表底数=" + My表止数 + ",计费单价=" + My计费单价 + " WHERE 计费年份=" + this.计费年份ToolStripComboBox.Text + " AND 计费月份=" + this.计费月份ToolStripComboBox.Text + " AND 费用类型='" + this.费用类型ToolStripComboBox.Text + "' AND 楼栋名称='" + this.楼栋名称ToolStripComboBox.Text + "' AND 业主编号='" + My业主编号 + "'";rn MyCommand.CommandText = MySQL;rn MyCommand.ExecuteNonQuery();rn rn rn if (MyConnection.State == ConnectionState.Open)rn rn MyConnection.Close();rn rn tryrn rn this.水电气费TableAdapter.Fill(this.dBCommunityDataSet.水电气费, 楼栋名称ToolStripComboBox.Text, new System.Nullable(((int)(System.Convert.ChangeType(计费年份ToolStripComboBox.Text, typeof(int))))), new System.Nullable(((int)(System.Convert.ChangeType(计费月份ToolStripComboBox.Text, typeof(int))))), 费用类型ToolStripComboBox.Text, "正在登记");rn rn catch (System.Exception ex)rn rn System.Windows.Forms.MessageBox.Show(ex.Message);rn rn rn他弹出的对话框是 点击是的时候就新增了rn我感觉应该是点击否啊rn哪位高手指点一下谢谢! 论坛

MessageBox和DialogResult程序报错

04-26

VC++6.0网上找的点击“是”进入下一步的代码,然后我用main函数执行下面的代码n string message = "You did not enter a server name. Cancel this operation?";n string caption = "No Server Name Specified";n MessageBoxButtons buttons = MessageBoxButtons.YesNo;n DialogResult result;nn //显示MessageBox.n result = MessageBox.Show(this, message, caption, buttons);nn //如果点击的是"YES"按钮,将form关闭.n if(result == DialogResult.Yes)n n // Closes the parent form.n this.Close();n n然后报了错,请问是什么问题,最好能给一份完整的代码,本人新手nC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'DialogResult' : undeclared identifiernC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Yes' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Show' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxButtons' : undeclared identifiernC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.YesNo' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxIcon' : undeclared identifiernC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Information' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2065: 'MessageBoxDefaultButton' : undeclared identifiernC:\Desktop\ceshi1\ceshi1.cpp(13) : error C2228: left of '.Button1' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(15) : error C2228: left of '.Show' must have class/struct/union typenC:\Desktop\ceshi1\ceshi1.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed 问答

没有更多推荐了,返回首页