110,534
社区成员
发帖
与我相关
我的任务
分享
谢谢两位的关注,找到原因了,散分了
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;
}
}
if (m.WParam.ToInt32() == WM_DEVICEMOVECOMPLETE)
{
this.leftPanelTree.ShowDeviceChanged("WM_DEVICEMOVECOMPLETE");//U盘拔出
ChangeSize(2);//大小为什么会不变化?,但lable1会不可见
}
就是U盘拔出时不能正常变化大小?
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
}
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);
}
}
这样为什么不起作用?