C# 在代码隐藏中设置图像按钮的不透明度

C# 在代码隐藏中设置图像按钮的不透明度,c#,asp.net,opacity,C#,Asp.net,Opacity,我有一个现有的图像按钮,想知道是否有可能改变这个按钮(图像)的不透明度从代码隐藏 <input type="image" runat="server" src="Images/UnlockUser.png" title="Unlock User" id="butUnlockUser" onclick="UnlockUser()"/> 亲切问候您可以使用以下替代方法: public static Bitmap ChangeOpacity(Image img, float opaci

我有一个现有的图像按钮,想知道是否有可能改变这个按钮(图像)的不透明度从代码隐藏

<input type="image" runat="server" src="Images/UnlockUser.png" title="Unlock User" id="butUnlockUser" onclick="UnlockUser()"/>

亲切问候

您可以使用以下替代方法:

 public static Bitmap ChangeOpacity(Image img, float opacityvalue)
    {
        Bitmap bmp = new Bitmap(img.Width,img.Height); // Determining Width and Height of Source Image
        Graphics graphics = Graphics.FromImage(bmp);
        ColorMatrix colormatrix = new ColorMatrix();
        colormatrix.Matrix33 = opacityvalue;
        ImageAttributes imgAttribute = new ImageAttributes();
        imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute);
        graphics.Dispose();   // Releasing all resource used by graphics 
        return bmp;
    }
并使用返回值显示


复制自

您可以使用以下替代方法:

 public static Bitmap ChangeOpacity(Image img, float opacityvalue)
    {
        Bitmap bmp = new Bitmap(img.Width,img.Height); // Determining Width and Height of Source Image
        Graphics graphics = Graphics.FromImage(bmp);
        ColorMatrix colormatrix = new ColorMatrix();
        colormatrix.Matrix33 = opacityvalue;
        ImageAttributes imgAttribute = new ImageAttributes();
        imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
        graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttribute);
        graphics.Dispose();   // Releasing all resource used by graphics 
        return bmp;
    }
并使用返回值显示


复制自

我不确定,但在这种情况下可以使用不同的css类。
在两个类中使用不同的不透明度,并根据您的条件进行更改

范例

.class1
{
   opacity:0.4; 
   filter:alpha(opacity=40);
}
.class2
{
     opacity:1; 
     filter:alpha(opacity=100);
}
并有条件地使用它

bool IsLocked = repUser.IsLockedOut(txtDetailUserName.Value);
if (IsLocked)
{
     butUnlockUser.Disabled = false;
     butUnlockUser.CssClass ="class1";
}
else
{
     butUnlockUser.Disabled = true;
     butUnlockUser.CssClass ="class2";
}

我不确定,但在这种情况下可以使用不同的css类。
在两个类中使用不同的不透明度,并根据您的条件进行更改

范例

.class1
{
   opacity:0.4; 
   filter:alpha(opacity=40);
}
.class2
{
     opacity:1; 
     filter:alpha(opacity=100);
}
并有条件地使用它

bool IsLocked = repUser.IsLockedOut(txtDetailUserName.Value);
if (IsLocked)
{
     butUnlockUser.Disabled = false;
     butUnlockUser.CssClass ="class1";
}
else
{
     butUnlockUser.Disabled = true;
     butUnlockUser.CssClass ="class2";
}

您可以创建一个css类来设置不透明度,然后在代码隐藏中将该类添加到图像中,如下所示:

img.Attributes.Add("class", "myClass");

您可以创建一个css类来设置不透明度,然后在代码隐藏中将该类添加到图像中,如下所示:

img.Attributes.Add("class", "myClass");

在代码隐藏的其他条件下,您可以编写

butUnlockUser.cssclass="opacity";

.opacity
{
    cursor:none !important ;
    -moz-opacity: 0.40;
    opacity:.40;
    filter: alpha(opacity=40);      
}

在代码隐藏的其他条件下,您可以编写

butUnlockUser.cssclass="opacity";

.opacity
{
    cursor:none !important ;
    -moz-opacity: 0.40;
    opacity:.40;
    filter: alpha(opacity=40);      
}