ButtonStateChanged事件详解 - 当按钮状态改变时触发的事件
作者:作者不详  发布日期:2021/06/26 18:05:43
  ButtonStateChanged事件详解 - 当按钮状态改变时触发的事件

ButtonStateChanged事件详解 - 当按钮状态改变时触发的事件


ButtonStateChanged事件


当用户点击【新增】、【删除】、【修改】、【保存】、【取消】等数据操作按钮时立即触发,通知程序按钮状态发生变化。



注意事项:


ButtonStateChanged事件适用于控制当前界面的组件状态,比如设置组件的ReadOnly, Enable属性。

ButtonStateChanged事件被频繁触发,不建议在该事件内调用后台接口或查询数据。



【新增】操作按钮调用ButtonStateChanged事件


C# Code:


/// <summary>
/// 新增记录
/// </summary>
/// <param name="sender"></param>
public virtual void DoAdd(IButtonInfo sender)
{
  
this._UpdateType = UpdateType.Add;
  
this.SetEditMode();
  
this.ButtonStateChanged(_UpdateType);
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




【修改】操作按钮调用ButtonStateChanged事件


C# Code:


/// <summary>
/// 修改数据
/// </summary>
/// <param name="sender"></param>
public virtual void DoEdit(IButtonInfo sender)
{
  
this._UpdateType = UpdateType.Modify;
  
this.SetEditMode();
  
this.ButtonStateChanged(_UpdateType);
}

//来源:C/S框架网 | www.csframework.com | QQ:23404761




ButtonStateChanged事件应用实例(1),源码参考:


C# Code:


/// <summary>
/// 当按钮状态改变时触发的事件
/// </summary>
/// <param name="currentState"></param>
protected override void ButtonStateChanged(UpdateType currentState)// 按钮状态改变时触发的事件
{
//设置编辑明细页面的控件
this.SetDetailEditorsAccessable(panelDetailPage, this.DataChanged);
this.SetDetailEditorsAccessable(panelControl2, this.DataChanged);

txtARNO.Enabled
= false;
txtAppDate.Enabled
= false;
txtAppUser.Enabled
= false;
txtCurrency.Enabled
= false;
lblStatus.Text
= this.UpdateTypeName;

this.SetEditorEnable(txtCustomerName, false, true);//禁用客户名称
base.SetGridCustomButtonAccessable(gcDetail, this.DataChanged);//设置明细表格的按钮状态

//显示图片状态
ucOpacityImage1.ShowImage(_BLL);
}


//来源:C/S框架网 | www.csframework.com | QQ:23404761



ButtonStateChanged事件应用实例(2),源码参考:


C# Code:

//按钮状态改变时触发的事件
protected override void ButtonStateChanged(UpdateType currentState)
{
  
base.ButtonStateChanged(currentState);
  
  
if (currentState == UpdateType.Modify)
  {
    
//txtSONO.Enabled= false;//修改状态下不允许修改【主键】的数据
    
txtSONO.Properties.ReadOnly = true;//修改状态下不允许修改【主键】的数据
    
}
    txtISID.Properties.ReadOnly
= true;//禁止修改
    
txtCreationDate.Properties.ReadOnly = true;//禁止修改
    
txtCreatedBy.Properties.ReadOnly = true;//禁止修改
    
txtLastUpdateDate.Properties.ReadOnly = true;//禁止修改
    
txtLastUpdatedBy.Properties.ReadOnly = true;//禁止修改
    
txtFlagApp.Properties.ReadOnly = true;//禁止修改
    
txtAppUser.Properties.ReadOnly = true;//禁止修改
    
txtAppDate.Properties.ReadOnly = true;//禁止修改
    
}
    
    
    
//来源:C/S框架网 | www.csframework.com | QQ:23404761





C/S框架网|原创精神.创造价值.打造精品


扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务


上一篇 下一篇