开始自学C#,一天争取帮人解决一个C#问题来提高。有问题尽管提!

解决方案 »

  1.   

    有问题
    http://community.csdn.net/Expert/TopicView1.asp?id=5321699
    谢谢
      

  2.   

    看看我的问题帖,谢谢
    http://community.csdn.net/Expert/topic/5316/5316117.xml?temp=.6501734
      

  3.   

    To : cs9201. 根据我学到材料,WH_CBT:在处理大多数窗口管理、鼠标和键盘消息前会调用的挂钩。是一个全局挂钩。网上有这么一段话“在 .NET 框架中不支持全局挂钩
    您无法在 Microsoft .NET 框架中实现全局挂钩。若要安装全局挂钩,挂钩必须有一个本机动态链接库 (DLL) 导出以便将其本身插入到另一个需要调入一个有效而且一致的函数的进程中。这需要一个 DLL 导出,而 .NET 框架不支持这一点。托管代码没有让函数指针具有统一的值这一概念,因为这些函数是动态构建的代理。”2.网上还有另外一段话"使用如下代码即可实现全局钩子:
    IntPtr pInstance = Marshal.GetHINSTANCE( Assembly.GetExecutingAssembly().ManifestModule );
    Win32API.SetWindowsHookEx( WH_MOUSE_LL,m_MouseHookProcedure, pInstance, 0 );"3.可以看出后者是把挂钩函数放在同一个程序集了。而不是一个DLL里。所以你的代码不成功是可能的。4.补充一点,标准的C# HOOK里都是采取委托的方式,而你的代码却是标准的WIN32方式。有些不妥。
      

  4.   

    To: free_wang(?) 呵,是我帮人解答问题,不是让人解答我的问题。还要给分?
      

  5.   

    To:yumanqing(E神) 你的问题不是C#的问题。对于一个不知道多长的过程,一般采取一个动态的表示,比如一个循环变化的确标志啥的。或是预估一个值,然后到99%的时候,就停住等待整个过程结束再到100%。
      

  6.   

    TO: liujia_0421(SnowLover) 俺是C#初学者。有问题多讨论。一起进步。
      

  7.   

    http://community.csdn.net/Expert/topic/5293/5293961.xml?temp=.8111994
    http://community.csdn.net/Expert/topic/5308/5308479.xml?temp=.5267755
    http://community.csdn.net/Expert/topic/5289/5289995.xml?temp=.2119562帮我解决这三个问题!1
      

  8.   

    To pfworld(胡剑):
    一个人最好一次提一个问题,而且你的三个问题有两个跟C#没什么关系。所以我只回答你其中一个跟C#有关的问题:即进度条的问题。
    其实你参考的例子已经写的很清楚了,既然还不明白,我就照着你参考的例子把它完整的写出来,你自己看一看。
    创建两个FORM: Form1, Form2:Form1的代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;namespace WindowsApplication8
    {    public partial class Form1 : Form
        {
            private Form2 myProgressBar = null;        private delegate bool IncreaseHandle(int nValue);        private IncreaseHandle myIncrease = null;        private void ShowProcessBar()
            {
                myProgressBar = new Form2();            myIncrease = new IncreaseHandle(myProgressBar.Increase);
                myProgressBar.ShowDialog();
                myProgressBar = null;
            }        private void ThreadFunc()
            {
                MethodInvoker mi = new MethodInvoker(ShowProcessBar);
                this.BeginInvoke(mi);
                Thread.Sleep(1000);
                bool blnIncreased = false;
                object objReturn = null;
                do
                {
                    Thread.Sleep(50);
                    objReturn = this.Invoke(this.myIncrease, new object[] { 2 });
                    blnIncreased = (bool)objReturn;
                }
                while (blnIncreased);
            }
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void button1_Click(object sender, EventArgs e)
            {
                Thread thdSub = new Thread(new ThreadStart(ThreadFunc));
                thdSub.Start();        }
        }
    }Form2的代码:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication8
    {
        public partial class Form2 : Form
        {
            public bool Increase(int nValue)
            {
                if (nValue > 0)
                {
                    if (prcBar.Value + nValue < prcBar.Maximum)
                    {
                        prcBar.Value += nValue;
                        return true;
                    }
                    else
                    {
                        prcBar.Value = prcBar.Maximum;
                        this.Close();
                        return false;
                    }
                }
                return false;
            }        public Form2()
            {
                InitializeComponent();
            }
        }
    }如果你还不明白,那我就没则了。
      

  9.   

    楼主帮我看看!!
    http://community.csdn.net/Expert/topic/5322/5322237.xml?temp=.7222254
      

  10.   

    TO femalelover(楼主, 用不着的可用分分给我1/3吧 :() :呵,主要看了一个多星期的书。感觉还是不能迅速熟悉这们语言。所以就想出这个法子。也许能速成。:)
      

  11.   

    请问:“DataTable”是“System.Data.DataTable”和“Excel.DataTable”之间的不明确的引用是怎么一回事啊。是datagridview导出数据时产生的错误。谢谢!
      

  12.   

    TO flyskylf(天高云淡): 这要看具体什么效果。如果仅仅是把Panel里的控件显示或隐藏起来。把AutoScroll = false; 然后改变Height就可以。但是如果要跟整个界面结合起来达到某些目的,则的看具体情况。你的帖子好象没说清楚。
      

  13.   

    TO lwg140811() :请把摘句的上下文贴上来,或是给出来源。目前还没学到C#的数据库这一块。不知道它跟其他语言的有什么区别。不过,如果你把全文都贴上,我可以试着看看能不能解答。
      

  14.   

    那个导出按钮的代码如下:也许有错误,麻烦看一下,谢谢啦!
      private void toolStripButton4_Click(object sender, EventArgs e)   //导出
            {
                DataSet ds = new DataSet();
                this.ds = this.link.SelectDataBase("SELECT IndexID,CodeName, LongName,Memo FROM branchinfo WHERE ParentIndexID = '1'", "yhb");
                ds.Tables["yhb"].AcceptChanges();
                this.Cursor = Cursors.WaitCursor;
                Excel.Application myExcel = new Excel.Application();
                myExcel.Application.Workbooks.Add(true);
                myExcel.Visible = true;
                myExcel.Cells[1, 1] = this.dataGrid1.CaptionText;
                //Object   Date[ds.Tables["yhb"].Rows.Count][ds.Tables["yhb"].Columns.Count];   
                //生成标题   
                for (int i = 0; i < ds.Tables["yhb"].Columns.Count; i++)
                {
                    myExcel.Cells[2, i + 1] = ds.Tables["yhb"].Columns[i].Caption;
                }
                //填充数据   
                for (int i = 0; i < ds.Tables["yhb"].Rows.Count; i++)
                {
                    for (int j = 0; j < ds.Tables["yhb"].Columns.Count; j++)
                    {
                        if (ds.Tables["yhb"].Rows[i][j].GetType() == typeof(System.String))
                        {                        myExcel.Cells[i + 3, j + 1] = "'" + ds.Tables["yhb"].Rows[i][j].ToString();
                        }
                        else
                        {
                            myExcel.Cells[i + 3, j + 1] = ds.Tables["yhb"].Rows[i][j].ToString();
                        }
                    }
                }            this.Cursor = Cursors.Default;
                MessageBox.Show("导出成功!    ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);   
            }
      

  15.   

    来捧场了看看我的问题
    http://community.csdn.net/Expert/TopicView3.asp?id=5322307
      

  16.   

    楼主在吗?
    帮我看看这个怎么解决
    怎样在 Winform 导入导出access数据库为execl和txt文本啊.
      

  17.   

    TO lwg140811() :你就是想把数据库导入到EXCEL里。因为我没有你的数据库,我就用MSSQL的数据库NorthWind写了一个例子。你可以参考一下。using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.Data.OleDb;
    using Excel;
    namespace WindowsApplication10
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                
            }        private void button1_Click(object sender, EventArgs e)
            {
                string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=CSharp; Password=csharp";
                string select = "select * from Customers";
                try
                {
                    using (OleDbConnection conn = new OleDbConnection(source))
                    {
                        conn.Open();
                        OleDbDataAdapter da = new OleDbDataAdapter(select, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds, "Customers");
                        this.Cursor = Cursors.WaitCursor;
                        try
                        {                        Excel.Application myExcel = new Excel.Application();
                            myExcel.Application.Workbooks.Add(true);
                            myExcel.Visible = true;
                            myExcel.Cells[1, 1] = "导入数据";
                            int aRow = 2;
                            int aCol = 1;
                            foreach (DataColumn col in ds.Tables["Customers"].Columns)
                            {
                                myExcel.Cells[aRow, aCol] = col.Caption;
                                aCol++;
                            }                        aRow = 3;                        foreach (DataRow row in ds.Tables["Customers"].Rows)
                            {
                                aCol = 1;
                                foreach (DataColumn col in ds.Tables["Customers"].Columns)
                                {
                                    myExcel.Cells[aRow, aCol] = row[col];
                                    aCol++;                            }
                                aRow++;
                            }                        MessageBox.Show("导出成功!    ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);   
                            if (!myExcel.Application.Workbooks["sheet1"].Saved)
                                myExcel.Application.Workbooks["sheet1"].Save();
                            myExcel.Application.Workbooks.Close();
                            myExcel.Quit();
                            this.Cursor = Cursors.Arrow;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }        }
        }
    }
      

  18.   

    TO imwjb(燕子的烟斗) :不好意思,没看明白你的问题。还有你的问题好象跟C#不是直接有联系。
      

  19.   

    TO liujb526(): 上面那个写给lwg140811() 的例子是从MSSQL导出到EXCEL,跟ACCESS导出没太大区别,只是改一下数据库。不知道能不能帮的上。
      

  20.   

    顶 虽然不用C# 友情帮LZ P一下
      

  21.   

    TO shabusha() : 当移动滚动条时 怎么知道滚动条 动了几格
    不是几格的问题(格由象素多少来定),是移动了多少像素位置。用AutoScrollPosition这个属性就能知道移动了多少象素,再根据字体大小,来计算几格。
      

  22.   

    C# winform中如何作一个数据库读取显示出来..为什么我绑定完后连数据库表的列名都一起显示出来..应该要怎么写里面代码?
      

  23.   

    http://community.csdn.net/Expert/topic/5322/5322762.xml?temp=.3631403也解答一下以上的问题吧~!!
    谢了
      

  24.   

    TO flyskylf(天高云淡): 不好意思我刚才误解你的问题。现在明白你的意思了。提供一个解决方法:先将Panel1.AutoScroll = false;然后
            static int offset = 200;
            int[] OffSets;        private void button1_Click(object sender, EventArgs e)
            { 
               for (int i = 0; i < panel1.Controls.Count ; i++)
               {
                  if (button1.Text == "下移")
                  {                  OffSets[i] = panel1.Controls[i].Top;
                      panel1.Controls[i].Top -= offset;              }
                  else
                  {
                      panel1.Controls[i].Top = OffSets[i];
                  }                 
                }
                if (button1.Text == "下移")
                    button1.Text = "复原";
                else
                    button1.Text = "下移";
             }         在Form_Load里分配OffSets
            private void Form1_Load(object sender, EventArgs e)
            {
                OffSets = new int[panel1.Controls.Count];
                button1.Text = "下移";        }这样就能达到你要的效果。
      

  25.   

    支持 我来问下 底层持续发出一个事件 然后在UI端接受这个事件 将这个事件中的参数一个string 显示到UI端 现在问题是不能同步的显示这个事件的参数string 该怎么做呢 底层如果不能更改的话
      

  26.   

    TO glicine() :你想达到什么目的?
      

  27.   

    谢谢了!我新建一个表单就可以导出,可是我在原来的表单就不能导出,
    我原来定义了一个 private System.Data.DataTable da = new DataTable(); 
    运行时出现下面的错误:
    “DataTable”是“System.Data.DataTable”和“Excel.DataTable”之间的不明确的引用
    不知道是为什么?麻烦楼主帮忙看一下,谢谢啦!
      

  28.   

    TO nowQuest() ( ) :我对ASP.NET不熟。但是根据IIS对请求的处理:
    1. 在IIS5中,当一个请求到达后,IIS首先会确认是什么类型的资源请求。如果是静态的请求(比如HTML),不会使用外部模块。直接由IIS处理。而IIS在你的网页中发现脚本,但是返回的页面却不是正常的ASP.NET的返回途径。所以会什么都没显示。
    2. 如果发现是aspx类型的请求,会转发给aspnet_isapi.dll来处理。aspnet_isapi.dll通过命名通道把请求传递给aspnet_wp.exe来处理asp.net的请求。
    3. 所以你发现什么没显示,但是数据库变了。一个解决方法: 放到iframe里。
    <html>
     <body>
    <iframe src=Count.aspx?find=226 width="100%" height="100%" scrolling="no"   frameborder="0"></iframe>
     </body>
    </html>这样就能达到你的目的
      

  29.   

    To lwg140811() :“DataTable”是“System.Data.DataTable”和“Excel.DataTable”之间的不明确的引用
    不知道是为什么?
    的意思是说这两个命名空间(System.Data和Excel)中都有DataTable类。而你的程序是直接用DataTable来写的。所以编译器无法识别你的DataTable是哪个命名空间的。你可以在你的DataTable前把命名空间都写上。比如都写成 System.Data.DataTable即可。
      

  30.   

    TO haohaoxi() :你说的不能同步具体是什么? 每次响应事件的延迟很长?或是偶长偶短?
      

  31.   

    谢谢,可以了。不过导出后有点小问题,就是按导出成功提示框中的确定后,那个EXCEL也关闭了,都还没有点击保存就自动保下来了,不知怎么改过来,试了好久都不行。又要麻烦你啦。
      

  32.   

    To lwg140811:你用的哪个代码?我写的那个?还有,你要改成什么样?
      

  33.   

    楼主很热心啊,请帮我这个初学者解决个问题:
        在visual studio 2003 c#.net中新创建一个窗体,加入一个文本框、一个水平滚动条和一个标签。步骤如下:
    (1)设置Labell的Text属性为“字体大小”;
    (2)水平滚动条的Minimum属性值为5,Maximum属性值为55;水平滚动条的LargeChange属性值为5,SmallChange属性值为1;
    (3)添加程序代码如下:
    private void HScrollBar1_Scroll(object sender, ScrolleventArgs e)
      {
        int mysize;
      mysize = HScrollBar1.Value;
      TextBox1.Font = new System.Drawing.Font("宋体", mysize);
      }
        按以上方法编写完后却无法生成,不能运行,请楼主帮解。以下为全部代码:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    namespace WindowsApplication3
    {
          /// <summary>
          /// Form1 的摘要说明。
          /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.RichTextBox richTextBox1;
    private System.Windows.Forms.HScrollBar hScrollBar1;
    private System.Windows.Forms.Label label1;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.richTextBox1 = new System.Windows.Forms.RichTextBox();
    this.hScrollBar1 = new System.Windows.Forms.HScrollBar();
    this.label1 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // richTextBox1
    // 
    this.richTextBox1.Location = new System.Drawing.Point(32, 24);
    this.richTextBox1.Name = "richTextBox1";
    this.richTextBox1.Size = new System.Drawing.Size(328, 112);
    this.richTextBox1.TabIndex = 0;
    this.richTextBox1.Text = "TextBox1";
    // 
    // hScrollBar1
    // 
    this.hScrollBar1.LargeChange = 5;
    this.hScrollBar1.Location = new System.Drawing.Point(32, 176);
    this.hScrollBar1.Maximum = 55;
    this.hScrollBar1.Minimum = 5;
    this.hScrollBar1.Name = "hScrollBar1";
    this.hScrollBar1.Size = new System.Drawing.Size(328, 16);
    this.hScrollBar1.TabIndex = 1;
    this.hScrollBar1.Value = 5;
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(32, 152);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(72, 16);
    this.label1.TabIndex = 2;
    this.label1.Text = "字体大小";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(392, 214);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.hScrollBar1);
    this.Controls.Add(this.richTextBox1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    } private void textBox1_TextChanged(object sender, System.EventArgs e)
    {
     
    }
    private void HScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
    int mysize;
    mysize = HScrollBar1.Value;
    TextBox1.Font = new System.Drawing.Font("宋体", mysize);
    }
    }
    }
      

  34.   

    就是用你写的那个 
     private void toolStripButton4_Click(object sender, EventArgs e)   //导出
            {
     string source = "Provider=SQLOLEDB; Data Source=(local);Initial Catalog=Northwind;User ID=sa; Password=140811";
                string select = "select * from Customers where customerid='TORTU'";
                try
                {
                    using (OleDbConnection conn = new OleDbConnection(source))
                    {
                        conn.Open();
                        OleDbDataAdapter da = new OleDbDataAdapter(select, conn);
                        DataSet ds = new DataSet();
                        da.Fill(ds, "Customers");
                        this.Cursor = Cursors.WaitCursor;
                        try
                        {                        Excel.Application myExcel = new Excel.Application();
                            myExcel.Application.Workbooks.Add(true);
                            myExcel.Visible = true;
                            myExcel.Cells[1, 1] = "导入数据";
                            int aRow = 2;
                            int aCol = 1;
                            foreach (DataColumn col in ds.Tables["Customers"].Columns)
                            {
                                myExcel.Cells[aRow, aCol] = col.Caption;
                                aCol++;
                            }                        aRow = 3;                        foreach (DataRow row in ds.Tables["Customers"].Rows)
                            {
                                aCol = 1;
                                foreach (DataColumn col in ds.Tables["Customers"].Columns)
                                {
                                    myExcel.Cells[aRow, aCol] = row[col];
                                    aCol++;
                                }
                                aRow++;
                            }                        if (!myExcel.Application.Workbooks["sheet1"].Saved)                        
                                myExcel.Application.Workbooks["sheet1"].Save();
                            myExcel.Application.Workbooks.Close();
                            myExcel.Quit();
                            this.Cursor = Cursors.Arrow;
                            //MessageBox.Show("导出成功!    ", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        conn.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    我所要做到就是当关闭EXCEL时询问一下是否保存,用你这个代码好象导出完后就保存在我的文档里面了,关闭也没有提示了。你试一下是不是一导出后就已经保存了。能不能做成当关闭EXCEL时询问是否保存。谢谢啦!
      

  35.   

    TO: tommy_ty() 你程序的问题出在
    TextBox1.Font = new System.Drawing.Font("宋体", mysize);这里的mysize不能为0,可以改成
    TextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
    即可。
      

  36.   

    谢谢楼主啦,终于搞定啦,太谢谢你了。我把这几行代码注释掉就OK了
    //if (!myExcel.Application.Workbooks["sheet1"].Saved)
    //    myExcel.Application.Workbooks["sheet1"].Save();
    //myExcel.Application.Workbooks.Close();
    //myExcel.Quit();
      

  37.   

    这么晚了楼主还给我解答,感动ing
    将程序代码改写如下后,可以生成了,但调试时拖动滚动条字体不能改变大小,真苦脑呀!盼着楼主明天能给予解答.
    再次感谢!
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    } private void richTextBox1_TextChanged(object sender, System.EventArgs e)
    {

    }
    private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
    int mysize;
    mysize = hScrollBar1.Value;
    richTextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
    }
    }
    }
      

  38.   

    TO: tommy_ty() 
    在里面加一句: this.label1.Font = new System.Drawing.Font("宋体", mysize+1);应该就可以了,如下:
    private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
    {
     int mysize;
     mysize = hScrollBar1.Value;
     richTextBox1.Font = new System.Drawing.Font("宋体", mysize+1);
     this.label1.Font = new System.Drawing.Font("宋体", mysize+1);
    }
      

  39.   

    早上好。
    上午出去玩,有问题留言,下午回来后看。
    还有,好象有几位怀疑我是否真的是C#的初学者。呵,我也没什么好说的,只是我有其他语言的基础,学C#可能上手快一些。语言毕竟是相通的,只是需要一个熟悉语法的过程。还有,相对其他W32语言,C#已经精简很多了。只要再了解一些.NET平台的工作原理,基本上,一周多点上手是没什么问题,只需要些时间熟悉C#的特有的一些表示方式和方法。
      

  40.   

    我来问下 底层持续发出一个事件 然后在UI端接受这个事件 将这个事件中的参数一个string 显示到UI端 现在问题是不能同步的显示这个事件的参数string 该怎么做呢 底层如果不能更改的话
    TO haohaoxi() :你说的不能同步具体是什么? 每次响应事件的延迟很长?或是偶长偶短?首先谢谢你的回复 我在说明下 假设这个底层事件每1S 钟发出 事件1 事件2 事件3 ...参数string 为s1 s2 s3 s4现在我在UI端接收的话 这个顺序会是杂乱无序的 我在想会不会是UI端想更新显示事件1的时候 事件2又发生 那程序又会跳到事件处理函数开始处 这样就让UI显示无序了.就这个问题 如果底层不能更改 有什么好方法吗?
      

  41.   

    请问楼主,如何让一个exe文件不能被改名,比如我的一个工程,只允许实例化一次,编译后生成test.exe,然后发布给客户,如果客户先点击test.exe,得到一个进程,如果此时客户再双击test.exe无效,但是如果客户改名为mytest.exe,再次双击mytest.exe,这使只实例化一次失效!
    请教楼主,如何解决这个问题?
      

  42.   

    哈哈 发表我的csdn第一贴 最喜欢LZ这样无私的人啦
    同学给我留的作业题帮我解决了:创建一个只能通过操作父类来销毁它的两个子类的方法。
    哈哈 另外问一下 新手应该怎么学习啊 给我介绍几本书 现在感觉对面向对象还有些迷茫呢
    如果可能加我的qq多指导指导我,好吗?
    再次谢谢啦
      

  43.   

    TO:haohaoxi() 我大概明白你的意思了。既然底层不能更改,那么只能在UI端想办法。
    比如:
    1.给底层事件编号,比如利用发生的时间。
    2.统一用一个事件调度程序来所有事件放到UI端的优先队列里。
    2.在UI端建立优先队列来存放底层来的事件。每次从优先队列中取最早的事件出来跟已经处理的最后一个事件的编号比较,如果是下一个事件,那么就处理,如果不是,就等待。优先队列保证了当前取出的事件是最早的。
    3.这样就能按次序来处理事件。不知道这个思路能不能帮上你。
      

  44.   

    TO huheng_0_0():你说的着个好办。有不少办法。其中一个方法就是利用Mutex同步机制. Mutex可以达到进程之间的互斥。如需要具体代码,我现在在外面,晚上回家可以用C#写写看。
      

  45.   

    http://community.csdn.net/Expert/topicview.asp?id=5323560谢谢啊
      

  46.   

    能帮我看看这个问题吗?谢谢。
    http://community.csdn.net/Expert/topic/5323/5323509.xml?temp=.6429407
      

  47.   


    private void Button1_Click(object sender, System.EventArgs e)
    {
    string today=DateTime.Now.ToString("yyyyMMdd");
    string addr="C:\\"+today+".txt"; //打开当天的文件
    string s="",pro_id="",now_time="",now_date="",bad_ness="";
    StreamReader str_read;
    str_read=File.OpenText(addr);
    if (pos==0)
    {
    int i=0;
    for(;str_read!=null;i++)
    {
    s=str_read.ReadLine(); //读取一串数据
    pro_id=s[0].ToString()+s[1].ToString();
    now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
    now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
    bad_ness=""+s[18];
    if(s.Length>19)
    {
    int len=s.Length;
    bad_ness+=s[len-1].ToString();
    }
    string con_instr="insert into [scantable] (proid,nowtime,nowdate,badness) values ('"+pro_id+"','"+now_time+"','"+now_date+"','"+bad_ness+"')";
    operate_sqlserver(con_instr);

    }
    pos=i;
    }


    str_read.Close();
    }未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 122: {
    行 123: s=str_read.ReadLine(); //读取一串数据
    行 124: pro_id=s[0].ToString()+s[1].ToString();
    行 125: now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
    行 126: now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
     源文件: c:\inetpub\wwwroot\showdata\default.aspx.cs    行: 124 
    帮忙看一下,是什么问题,看了半天,没有搞定
      

  48.   

    TO: clementchen()
    不是很明白你的意思。问题描述简单了点。也许说的是通过实现IDisposable接口,用户可以控制销毁的时间.然后在子类中调用GC.SuppressFinalize(this);来让.NET的垃圾收集器不要强制调用该子类的析构函数.把实现销毁的方法放在父类里,让子类继承下来调用。不过把你的作业也拿来让我做,有点过了。
      

  49.   

    TO Rock_318():还真没看懂你的问题。呵
      

  50.   

    TO wmf0708():就象你贴子后跟的,需要实例,具体点的。
      

  51.   

    int i = this.listBox1.Items.Count;
                    tabpage = new System.Windows.Forms.TabPage[i];
                    dataGridView = new System.Windows.Forms.DataGridView[i];
                    bindingSource = new System.Windows.Forms.BindingSource[i];
                    for (int j = 0; j < i; j++)
                    {
                        tabpage[j] = new TabPage();
                        dataGridView[j] = new DataGridView();
                        bindingSource[j] = new BindingSource();
                        this.tabControl1.Controls.Add(tabpage[j]);
                        tabpage[j].Text = this.listBox1.Items[j].ToString();
                        tabpage[j].Controls.Add(this.dataGridView[j]);
                        dataGridView[j].DataSource = this.bindingSource[j];
                        dataGridView[j].Dock = System.Windows.Forms.DockStyle.Fill;
                        dataGridView[j].AllowUserToAddRows = false;
                        OracleConnection conn = new OracleConnection(Properties.Settings.Default.ConnectionString);
                        OracleCommand cmd = new OracleCommand();
                        cmd.CommandText = "select * from test;
                        cmd.Connection = conn;
                        OracleDataAdapter adapter = new OracleDataAdapter();
                        adapter.SelectCommand = cmd;
                        DataTable dt = new DataTable();
                        adapter.Fill(dt);
                        bindingSource[j].DataSource = dt;
    此时数据是不是已经fill到本地机器的内存里了?此时for (int jj = 0; jj < dataGridViewqq.Rows.Count; jj++){dataGridView[j].Rows[jj].Cells[18].Value =0}报错,dataGridViewqq.Rows.Count未实例化,咋搞?然后如何将改动后的数据保存到数据库?
      

  52.   

    TO cjocky (过路人):不好意思,我也是开始学C#,现在是2.0,木用过1.0. 帮不上你。
      

  53.   

    OK.那如果我知道某一个控件的名称,我有没有办法可以操控这个控件?比方说我知道某个菜单项名称叫做"mnuGcbh",它只是在程序运行中动态获得的一个字符串,用来表示某一个菜单项叫做"mnuGcbh",那么有没有办法可以操控这个菜单项?比如执行mnuGcbh.Visible=false;之类的。
      

  54.   

    我研究了一下,发现是因为循环中使用pro_id、now_time、now_date变量,循环注释掉就OK了,是什么原因,为什么字符串s不出现这种问题,是不是与数据库的连接有关?楼主为在下解释一下,万分感谢........
      

  55.   

    http://community.csdn.net/Expert/topicview.asp?id=5323560
      

  56.   

    To picasson() :你拿其中一个函数,里面还调用了其他东西。就让我帮你调试。呵。没有这样的。
      

  57.   

    TO picasson() :你看这里:
    s=str_read.ReadLine(); //读取一串数据
    行 124: pro_id=s[0].ToString()+s[1].ToString();
    行 125: now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
    行 126: now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
    如果你读到的S没那么长,或是空的,哪来的S[0],S[1]....S[10]?
      

  58.   

    主要是我还没完工,不好意思,请楼主谅解,下面是全部代码:
    using System;
    using System.IO;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace ShowData
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Button Button2;
    protected System.Web.UI.WebControls.Button Button3;
    protected System.Web.UI.WebControls.Label Label6;
    protected System.Web.UI.WebControls.DropDownList DropDownList4;
    protected System.Web.UI.WebControls.DropDownList DropDownList5;
    protected System.Web.UI.WebControls.Label Label4;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.DropDownList DropDownList1;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Button Button5;
    protected System.Web.UI.WebControls.Button Button4;
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;

    public static int look_index=0; //查找参数
    public static int aa=0;    // 标志页面页码的参数 
    public static int pos=0;
    public static int find_data=0;                    //查找按钮索引
    public static string value_info;
    public  string count_num="0"; private void operate_sqlserver(string tab)
    {
    SqlConnection con=new SqlConnection();
    string str="server=localhost;uid=sa;pwd=;database=work";
    con.ConnectionString=str;
    SqlCommand sqlcmd= new SqlCommand(tab,con);
    SqlDataAdapter da=new SqlDataAdapter(tab,con);
    sqlcmd.Connection.Open();
    sqlcmd.ExecuteNonQuery();
    sqlcmd.Connection.Close();
    } private DataSet view_data(string tab)
    {
    SqlConnection con=new SqlConnection();
    string str="server=localhost;uid=sa;pwd=;database=work";
    con.ConnectionString=str;
    SqlDataAdapter da=new SqlDataAdapter(tab,con);
    DataSet ds=new DataSet();
    da.Fill(ds);
    return(ds);
    } //page_operate()函数的定义
    private void page_operate(string index,System.Web.UI.WebControls.DataGrid tab)//分页
    {
    System.Web.UI.WebControls.Button up_page=Button2;                //传递上一页按钮
    System.Web.UI.WebControls.Button down_page=Button3;              //传递下一页按钮
    System.Web.UI.WebControls.DropDownList page_size=DropDownList5; //传递显示记录个数的下拉菜单
    System.Web.UI.WebControls.DropDownList data_keys=DropDownList1; //传递查询条件的关键字的下拉菜单
    System.Web.UI.WebControls.DropDownList jump_keys=DropDownList4;  //跳转到按钮
    System.Web.UI.WebControls.TextBox  data_vlue=TextBox1;           //传递文本框
    System.Web.UI.WebControls.Label data_count=Label1;           //传递查找记录的个数的标签
    data_count.Text="";
    //string strID,录入时间,接待台帐表.id as id from 接待台帐表,hotel,交办领导 where 拟住宾馆=hotel.id and 交办领导.id=接待台帐表.交办领导 ";
    //int count_index=0;                    
    //int size_page=(page_size.SelectedIndex+1)*10;   //显示记录的个数
    } private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    string today=DateTime.Now.ToString("yyyyMMdd");
    string addr="C:\\"+today+".txt"; //打开当天的文件
    string pro_id="",now_time="",now_date="",bad_ness="";
    StreamReader str_read;
    str_read=File.OpenText(addr);
    if (pos==0)
    {
    int i=0;
    for(;str_read!=null;i++)
    {
    s=str_read.ReadLine(); //读取一串数据
    pro_id=""+s[0]+s[1];
    now_time=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10]+s[11]+s[12]+s[13]+s[14]+s[15]+s[16];
    now_date=""+s[3]+s[4]+s[5]+s[6]+s[7]+s[8]+s[9]+s[10];
    bad_ness=""+s[18];
    if(s.Length>19)
    {
    int len=s.Length;
    bad_ness+=s[len-1].ToString();
    }
    string con_instr="insert into [scantable] (proid,nowtime,nowdate,badness) values('"+pro_id+"','"+now_time+"','"+now_date+"','"+bad_ness+"')";
    operate_sqlserver(con_instr);

    }
    pos=i;
    }


    str_read.Close();
    }
    }
    }
    希望楼主解答,万分感谢。
      

  59.   

    http://community.csdn.net/Expert/TopicView.asp?id=4827014
      

  60.   

    To cjocky(过路人) :如果你知道一个控件的名称,当然可以操控它。不管是不是动态的。普通控件可以:
               
                for (int i = 0; i < Controls.Count; i++)
                {   
                    if (Controls[i].Name == "xxxxx")
                      (Controls[i] as Button).Visible = false;
                }菜单项:
                for (int i = 0; i < menuStrip1.Items.Count; i++)
                {
                    if (menuStrip1.Items[i].Name == "XXXXXX")
                        menuStrip1.Items[i].Visible = false;
                }
                
              
                
      

  61.   

    TO picasson() :可能它中间有读到不满10个的。数据库里全是因为出错的异常跳出了,没加入到数据库。你最好跟踪一下看看实际数据。
      

  62.   

    http://community.csdn.net/Expert/topic/5323/5323854.xml?temp=.2285883
    请帮个忙了!谢谢了!
      

  63.   

    我这有一个测试时的小程序,同样的错误:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.IO;
    namespace WindowsApplication1
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.label4 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Location = new System.Drawing.Point(96, 16);
    this.button1.Name = "button1";
    this.button1.TabIndex = 0;
    this.button1.Text = "button1";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(40, 64);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(168, 32);
    this.label1.TabIndex = 1;
    this.label1.Text = "label1";
    // 
    // label2
    // 
    this.label2.Location = new System.Drawing.Point(32, 120);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(168, 24);
    this.label2.TabIndex = 2;
    this.label2.Text = "label2";
    // 
    // label3
    // 
    this.label3.Location = new System.Drawing.Point(16, 168);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(248, 56);
    this.label3.TabIndex = 3;
    this.label3.Text = "label3";
    // 
    // label4
    // 
    this.label4.Location = new System.Drawing.Point(16, 232);
    this.label4.Name = "label4";
    this.label4.Size = new System.Drawing.Size(248, 23);
    this.label4.TabIndex = 4;
    this.label4.Text = "label4";
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.label4);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.button1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    string now_time=DateTime.Now.ToString("yyyyMMdd");
    now_time+=".txt";
    string ss;
    ss="C:\\"+now_time;


    StreamReader sr;
    string s;
    sr=File.OpenText(ss);
    s=sr.ReadLine();
    int aa=0;
    string sss="";
    if(s[19].ToString()!=null)
    {
    sss=s[0].ToString()+s[1].ToString()+s[2].ToString()+s[3].ToString()+s[19].ToString();
    }
    label1.Text=sss;
    for(int i=0;s!=null;i++)
    {
    //label1.Text=sss;
    label3.Text=s;
    Console.WriteLine(s);
    s=sr.ReadLine();
    ++aa;
    sss=""+s[0]+s[1]+s[2]+s[3];
    label2.Text=aa.ToString();
    label2.Text=sss;
    }

    sr.Close(); }
    }
    }
    上一个程序他写到数据库的数据是正确的,所以我才不解
    麻烦楼主调试一下这个小程序,看一下
      

  64.   

    楼主,能不能给个具体的例子,万分感谢,我的问题是,怎样保证程序只被实例化一次,哪怕是更改exe的名字之后,谢谢
      

  65.   

    http://community.csdn.net/Expert/topicview.asp?id=5323560
      

  66.   

    恩 非常感谢 你能加我msn吗 [email protected] 多谢了
      

  67.   


    组名txtbox
    组描述。。txtbox
    查找txtbox
    我先在点几查找后就出来原来的ID
    怎么做啊,进行还原
      

  68.   

    http://community.csdn.net/Expert/member/MyForum.asp?typenum=1
    我的问题,谢谢