C#删除按钮消息问题

C#删除按钮消息问题

本文介绍了C#删除按钮消息问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone!



i在Windows窗体应用程序中创建一个图片框并制作两个按钮1:浏览图像和2:删除图像都正常工作。 但是现在我想要两件事,



1:启动应用程序时如果用户点击删除按钮然后删除按钮显示错误消息和错误我应该在文本形式中的删除按钮下方显示消息。 请先选择图像。然后选择图像后消息自动消失。



2:如果用户选择图像然后再次将其删除第二次按下按钮然后再次出现相同的消息图片信息应自动消失。



如果有人对此有任何想法,请帮助我。

Hello Everyone!

i create a picture Box in Windows Forms Application and make two button 1:Browse image and 2:Remove Image both work Right. but now i want Two Things,

1:on starting the Application if user click on Remove Button Then Remove Button Show Error Message and Error Message Should Me Show Below the Remove Button In The Form Of Text. "Please Select Image First". And Then message Automatically Disappear after Selecting Image.

2:If User Select image and then remove it and again Second time Press Button Then Same Message Will Occur Again and after Selecting image Message Should Be Automatically Disappear.

Please Help me If Anyone Have Any Idea About this.

推荐答案


public class MainViewModel : INotifyPropertyChanged
{
    private Image mImage;

    public event PropertyChangedEventHandler PropertyChanged;

    public Image Image
    {
        get { return mImage; }
        set
        {
            if (mImage != value)
            {
                mImage = value;
                OnPropertyChanged();
                OnPropertyChanged("RemoveButtonEnabled");
                OnPropertyChanged("ErrorMessageVisible");
            }
        }
    }

    public bool RemoveButtonEnabled
    {
        get
        {
            return Image != null;
        }
    }

    public bool ErrorMessageVisible
    {
        get
        {
            return Image == null;
        }
    }

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
}


这篇关于C#删除按钮消息问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 11:51