private void FrmMain_Load(object sender, EventArgs e)
        {
            ChangeSize(2);
         }
         private void ChangeSize(int type)
        {
            if(type==1)
            {
                this.Size = new Size(970, 515);                
            }
            else
            {
                this.Size = new Size(698, 515);                
            }
        }
    
  这样为什么不起作用?

解决方案 »

  1.   

    private void FrmMain_Load(object sender, EventArgs e)
            {
                ChangeSize(2);
            }
            private void ChangeSize(int type)
            {
                if(type==1)
                {
                    this.Size = new Size(970, 515);               
                }
                else
                {
                    this.Size = new Size(698, 515);               
                }
            }
       
      这样为什么不起作用?
      

  2.   

    好使
    会根据
    if(type==1) 
                { 
                    this.Size = new Size(970, 515);                
                } 
                else 
                { 
                    this.Size = new Size(698, 515);                
                } 
    而改变你的是vs200?
    你说的不起作用是什么
      

  3.   

    private void ChangeSize(int type)
            {
                if(type==1)
                {
                    this.Size = new Size(970, 525);
                    this.lable1.Visible = true;
                }
                else
                {
                    this.Size = new Size(698, 525);
                    this.lable1.Visible = false;
                }
            }        /// <summary>
            /// 监视Windows消息
            /// </summary>
            /// <param name="m"></param>
            protected override void WndProc(ref Message m)
            {
                const int WM_DEVICECHANGE = 0x219;
                const int WM_DEVICEARRVIAL = 0x8000;//如果m.Msg的值为0x8000那么表示有U盘插入
                const int WM_DEVICEMOVECOMPLETE = 0x8004;//U盘拔出
                switch (m.Msg)
                {
                    case WM_DEVICECHANGE:
                        {
                            this.leftPanelTree.ShowDeviceChanged("WM_DEVICECHANGE");
                            if (m.WParam.ToInt32() == WM_DEVICEARRVIAL)
                            {
                                this.leftPanelTree.ShowDeviceChanged("WM_DEVICEARRVIAL");//U盘插入
                                ChangeSize(1);//能正常变大,lable1也会不可见
                            }
                            else if (m.WParam.ToInt32() == WM_DEVICEMOVECOMPLETE)
                            {
                                this.leftPanelTree.ShowDeviceChanged("WM_DEVICEMOVECOMPLETE");//U盘拔出
                                ChangeSize(2);//大小为什么会不变化?,但lable1会不可见
                            }
                        }
                        break;
                }
                base.WndProc(ref m); //将系统消息传递自父类的WndProc
            }
      

  4.   

                            if (m.WParam.ToInt32() == WM_DEVICEMOVECOMPLETE)
                            {
                                this.leftPanelTree.ShowDeviceChanged("WM_DEVICEMOVECOMPLETE");//U盘拔出
                                ChangeSize(2);//大小为什么会不变化?,但lable1会不可见
                            }
                            
                            就是U盘拔出时不能正常变化大小?
      

  5.   

    你确定别的地方没设置lable1?
    测试了你的代码 没啥问题
      

  6.   

    谢谢两位的关注,找到原因了,散分了private void ChangeSize(int type)
            {
                if(type==1)
                {
                    this.Size = new Size(970, 525);
                    this.lable1.Visible = true;
                }
                else
                {
                    this.lable1.Visible = false;//移到前面就可以了,先false掉
                    this.Size = new Size(698, 525);
                    //this.lable1.Visible = false;
                }
            }