Image控件的巧用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36981814/article/details/83011273

一、前言

Image控件
简单地实现貌似美化过的Button控件,简单便捷易实现。
纯粹是比赛过程中节省时间使用,建议常规开发中还是使用Blend for Visual Studio进行控件美化

二、效果图

在这里插入图片描述

三、代码实现

/// <summary>
/// 设置image状态
/// </summary>
/// <param name="imgLamp"></param>
/// <param name="imgLampSwitch"></param>
/// <param name="status">true为亮灯图,false为关灯图</param>
private void SetImageAndStatus(Image imgLamp, Image imgLampSwitch, bool status)
{
            //判断要显示的灯状态,设置图片控件的图片为相应的图片
            if (status == true)
            {
                imgLamp.Source = new BitmapImage(new Uri("Resources/lamp_on.png", UriKind.Relative));
                imgLampSwitch.Source = new BitmapImage(new Uri("Resources/btn_switch_on.png", UriKind.Relative));
            }
            else
            {
                imgLamp.Source = new BitmapImage(new Uri("Resources/lamp_off.png", UriKind.Relative));
                imgLampSwitch.Source = new BitmapImage(new Uri("Resources/btn_switch_off.png", UriKind.Relative));
            }
}

四、源码下载

SetImage

猜你喜欢

转载自blog.csdn.net/qq_36981814/article/details/83011273
今日推荐