遇见一个问题,在构造函数最后一行为控件注册一个drag事件居然无效,放到form_load里才有效.why?
解决方案 »
- 正则表达式问题
- 未能加载文件或程序集“System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken
- 求个简单的触发器 给个完整编码带注释
- ORACLE数据库-连-接-字-符。长长长
- 如何用C#製作ISO 文件
- datagridview的单元格输入问题?
- 在B/S下如何对网站加一个软件使用期.非常感谢!!!
- 数据绑定,addnew()方法调用的非空布尔值字段如何处理!散分!
- 求助:c# 线程池问题,绕了半天,绕不出来
- AD域在调用设置密码SetPassword时报"调用的对象发生异常" RPC服务器不可用
- C#中无法调用方法
- C# 将一个Treeview的树形结构保存成文件并可以实现将文件内容导入Treeview中
注册一个drag要给出目标窗口, 当form_load的时候,窗口句柄已经创建了,这时注册drag有效。
不懂你玩winform不?,你创建一个事例,然后分步运行就很容易理解了他先是进入一个构造方法 public MainForm()
{
InitializeComponent();
} private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.bnt_4 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.bnt_1 = new System.Windows.Forms.Button();
this.bnt_2 = new System.Windows.Forms.Button();
this.bnt_5 = new System.Windows.Forms.Button();
this.bnt_3 = new System.Windows.Forms.Button();
this.pb_min = new System.Windows.Forms.PictureBox();
this.pb_exit = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.bnt_6 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb_min)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb_exit)).BeginInit();
this.SuspendLayout();
........
}
你会发现他都是先定义了就去加绑事件
如果你在构造方法里写,那么就相当于在InitializeComponent()之前去绑定了,都时都还没有初使化
你根本没有看清楼主的描述!楼主说的那句话是放在 initializecomponent 方法后面的,也就是说那个时候控件都已经创建完成,在那个时候,你绑定其它事件都是没有问题的,之所以有问题,你根本没有解释清楚,#2 说的很清楚,是因为 window handler 的问题,而不是加载不加载的问题。