标题:当前上下文中不存在名称“btnReg”,,,高手们帮帮忙啊
只看楼主
liao888
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-6-14
结帖率:50%
 问题点数:0 回复次数:0 
当前上下文中不存在名称“btnReg”,,,高手们帮帮忙啊
登录窗体
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using MrCy.BaseClass;

namespace MrCy
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }


        SoftReg softreg = new SoftReg();
        private void Form1_Load(object sender, EventArgs e)
        {
            RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI");
            foreach (string strRNum in retkey.GetSubKeyNames())//判断是否注册
            {
                if (strRNum == softreg.getRNum())
                {
                    this.Text = "本软件(已注册)";
                    btnReg.Enabled = false;
                    main.Show();
                    return;
                }
            }
            this.Text = "本软件(未注册)";
            btnReg.Enabled = true;
            btnSetMonitor.Enabled = btnAutoMonitor.Enabled = false;
            startMonitor();
            MessageBox.Show("您现在使用的是试用版,该软件可以免费试用30次!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Int32 tLong;
            try
            {
                tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0);
                MessageBox.Show("感谢您已使用了" + tLong + "次", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0, RegistryValueKind.DWord);
                MessageBox.Show("欢迎新用户使用本软件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", 0);
            if (tLong < 30)
            {
                int Times = tLong + 1;
                Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\angel", "UseTimes", Times);
            }
            else
            {
                MessageBox.Show("试用次数已到", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Application.Exit();
            }

            ////txtName.Focus();
            //txtName.Focus();
        }


        private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                btnSubmit_Click(sender, e);
            }
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                MessageBox.Show("请输入用户名", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (txtPwd.Text == "")
                {
                    MessageBox.Show("请输入密码", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    SqlConnection conn = BaseClass.DBConn.CyCon();
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("select count(*) from tb_User where UserName='" + txtName.Text + "' and UserPwd='" + txtPwd.Text + "'", conn);
                    int i = Convert.ToInt32(cmd.ExecuteScalar());
                    if (i > 0)
                    {
                        cmd = new SqlCommand("select * from tb_User where UserName='" + txtName.Text + "'", conn);
                        SqlDataReader sdr = cmd.ExecuteReader();
                        sdr.Read();
                        string UserPower = sdr["power"].ToString().Trim();
                        conn.Close();
                        frmMain main = new frmMain();
                        main.power = UserPower;
                        main.Names = txtName.Text;
                        main.Times = DateTime.Now.ToShortDateString();
                        main.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("用户名或密码错误");
                    }
                }
            }
        }

        private void btnConcel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定退出系统吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk) == DialogResult.OK)
            {
                Application.Exit();
            }
        }
    }
}







frmRegister窗休的
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MrCy.BaseClass;
using Microsoft.Win32;

namespace MrCy
{
    public partial class frmRegister : Form
    {
        public frmRegister()
        {
            InitializeComponent();
        }

        SoftReg softreg = new SoftReg();
        private void frmRegister_Load(object sender, EventArgs e)
        {
            txtMNum.Text = softreg.getMNum();
        }

        private void btnReg_Click(object sender, EventArgs e)
        {
            if (txtRNum.Text.Equals(softreg.getRNum()))
            {
                RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI").CreateSubKey(txtRNum.Text);
                retkey.SetValue("UserName", "tsoft");
                MessageBox.Show("注册成功!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                showMain();
            }
            else
            {
                MessageBox.Show("注册码输入错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            showMain();
        }
        //隐藏注册窗体,显示主窗体
        public void showMain()
        {
            this.Hide();
            frmLogin frmLogin = new frmLogin();
            frmLogin.Show();
        }
    }
}
搜索更多相关主题的帖子: class private public 上下文 
2011-06-25 22:29



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-343990-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.436458 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved