-
2021-12-07 10:23:45
取按钮为例子:
Button.BackColor = Color.FromArgb(50,Color.White);
方法FormArgb的第一个参数就是透明度的意思,后面跟着你设置的颜色。
更多相关内容 -
WinForm 设置控件的透明度
2021-06-30 11:50:50第一个参数代表透明度,数值在0-255之间 在***.Designer.cs中加入以下代码 this.OpenFileButton.BackColor = System.Drawing.Color.FromArgb(255, Color.Crimson); this.NextButton.BackColor = System.Drawing....使用方法:Color.FromArgb(Int32,Color)
第一个参数代表透明度,数值在0-255之间
选中button将属性“FlatStyle”设置为:“Flat”在***.Designer.cs中加入以下代码
this.OpenFileButton.BackColor = System.Drawing.Color.FromArgb(255, Color.Crimson); this.NextButton.BackColor = System.Drawing.Color.FromArgb(100, Color.Crimson);
效果图:
-
C#WinForm开发:将控件背景色设置为透明
2020-09-22 20:30:24以pictureBox控件上label控件为例,设置label控件的背景色透明,可以看到pictureBox控件的背景色。 -
winform自定义透明背景的panel控件
2019-01-15 17:05:53winform自定义的透明背景的panel,可以覆盖在其他控件上,然后在该透明panel上做绘图、点击获取坐标等操作。 -
winform实现控件透明(实现真透明)
2021-04-19 15:19:45使用BackColor=Color.Translate这种方法只能实现和背景色一样但是不是真的透明,控件后面的控件还是看不到 1.首先写一个基类 using System; using System.Collections.Generic; using System.Text; using System....使用BackColor=Color.Translate这种方法只能实现和背景色一样但是不是真的透明,控件后面的控件还是看不到
1.首先写一个基类
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.ComponentModel; namespace CYControls { /// <summary> /// 提供透明和旋转功能的基础控件 /// </summary> public class CYBaseControl : Control { private float _iBorderThickness = 1f; private float _iOpacity = 1f; private Brush _brushBg = null; private Pen _penFg = null; public CYBaseControl() { this.SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.Opaque, true); this.BackColor = Color.Transparent; BackgroundBrush = Brushes.Transparent; ForegroundPen = Pens.Black; } #region Propertys #region HideParent [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override string Text { get { return base.Text; } set { base.Text = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override Image BackgroundImage { get { return base.BackgroundImage; } set { base.BackgroundImage = value; } } [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] public override ImageLayout BackgroundImageLayout { get { return base.BackgroundImageLayout; } set { base.BackgroundImageLayout = value; } } #endregion public override Color BackColor { get { return base.BackColor; } set { base.BackColor = value; ResetBgBrush(); } } //[EditorAttribute(typeof(BrushTypeEditor), typeof(System.Drawing.Design.UITypeEditor))] //public double Background //{ // get; // set; //} public override Color ForeColor { get { return base.ForeColor; } set { base.ForeColor = value; ResetFgPen(); } } public float BorderThickness { get { return _iBorderThickness; } set { if (value < 0) { throw new Exception("Out off range"); } _iBorderThickness = value; ResetFgPen(); ResetDrawRect(); } } public virtual float RotateAngle { get; set; } public float Opacity { get { return _iOpacity; } set { if (value > 1 || value < 0) { throw new Exception("Out of range,the Value be in [0,1]"); } else { _iOpacity = value; ResetBrushes(); } } } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle = 0x20; return cp; } } protected virtual Brush BackgroundBrush { get { return _brushBg; } set { _brushBg = value; } } protected virtual Pen ForegroundPen { get { return _penFg; } set { _penFg = value; } } protected virtual RectangleF DrawRect { get; set; } #endregion #region Methods protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; } protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); ResetDrawRect(); } protected override void OnPaddingChanged(EventArgs e) { base.OnPaddingChanged(e); ResetDrawRect(); } protected void ResetBrushes() { ResetBgBrush(); ResetFgPen(); } protected void ResetBgBrush() { BackgroundBrush = new SolidBrush(GetOpacityColor(BackColor, Opacity)); } protected void ResetFgPen() { ForegroundPen = new Pen(GetOpacityColor(ForeColor, Opacity), BorderThickness); } protected Color GetOpacityColor(Color baseColor, float op) { return Color.FromArgb(Convert.ToInt32(op * baseColor.A), baseColor); } private void ResetDrawRect() { float dbwidth = 2 * BorderThickness; float halfwidth = BorderThickness / 2; int paddingWhith = Padding.Left + Padding.Right; int paddingHeight = Padding.Top + Padding.Bottom; if (dbwidth > Width - paddingWhith || dbwidth > Height - paddingHeight) { DrawRect = this.Bounds; } else { DrawRect = new RectangleF(Padding.Left + halfwidth, Padding.Top + halfwidth, Width - BorderThickness - paddingWhith, Height - BorderThickness - paddingHeight); } } #endregion } }
2.创建RectangleShape
public class RectangleShape:CYBaseControl { protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); e.Graphics.FillRectangle(BackgroundBrush,this.ClientRectangle); e.Graphics.DrawRectangle(ForegroundPen,Rectangle.Round(this.DrawRect)); } }
3.应用实例
RectangleShape recS=new RectangleShape (); recS.Name="TestShape"; recS.Height=100; recS.Width=100; recS.BackColor=Color.Transparent; recS.Location=new Point(0,0); //设置透明度 recS.Opacity=0.5F; //把自定义的这个控件添加到需要的容器中 **.Controls.Add(recS);
-
winform panel控件背景透明
2014-07-24 15:09:56winform panel控件背景透明 在网页中通过div+css实现半透明效果不难,今天我们看看一种在winfrom中实现的方法 -
winform自定义控件(1)———设置透明背景色
2021-08-11 12:01:09} } 自定义一个控件,如果我想设置背景色是透明色的话如下: transparentControl1.BackColor = Color.FromArgb(100, 255, 0, 0); 会直接报错,并且提示控件不支持透明的背景色,此时要执行下面一句代码即可: this....class TransparentControl : Control { public TransparentControl() { this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.SetStyle(ControlStyles.ResizeRedraw, true); this.SetStyle(ControlStyles.Selectable, true); //this.SetStyle(ControlStyles.SupportsTransparentBackColor, false ); this.SetStyle(ControlStyles.UserPaint, true); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); } }
自定义一个控件,如果我想设置背景色是透明色的话如下:
transparentControl1.BackColor = Color.FromArgb(100, 255, 0, 0);
会直接报错,并且提示控件不支持透明的背景色,此时要执行下面一句代码即可:
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
该句代码的作用就是指示控件的背景色可以支持透明色
-
WinForm 实现半透明控件
2012-09-19 23:13:59半透明控件,包括直线,矩形,五角星等简单图形,还有实现了图片控件的半透效果 -
WinForm控件半透明遮罩dll
2019-10-07 10:06:40可在目标控件上显示或隐藏半透明遮罩层,支持透明度和颜色自定义,支持在遮罩层上显示自定义文本,文本颜色可调。已封装有x86/x64/AnyCpu三种dll,使用时引用相应的dll调用相关方法即可,方法参数说明已以截图形式放... -
C#WinForm开发:如何将控件背景色设置为透明
2020-09-22 16:31:05C#WinForm开发:如何将控件背景色设置为透明引言关于透明实现步骤常见问题 引言 在项目开发中,有时需要将控件的背景颜色设置为透明,比如label控件。那么,如何将控件的背景颜色设置为透明?是不是只要将控件的... -
C# 控件透明背景(winform)
2021-04-26 23:59:49原文出自:C# 实现真正的透明控件(Windows桌面程序)_yangshengchuan的博客-CSDN博客_c# 控件透明 修改了一点bug和方式,现在可以根据任意指定颜色镂空,还可以一次性镂空多个颜色 使用方法: using System; using System... -
winform 控件半透明设置
2018-06-04 14:52:001.backcolor属性为color.FromArgb(100, 220, 220, 220); 2.全透明设置为transparent方法。 转载于:https://www.cnblogs.com/gaara-zhang/p/9133335.html -
winform实现透明控件
2019-01-17 17:39:46但是,winform项目的控件透明都是将父控件的图像绘制成子控件的背景来实现的,这种透明存在很大的问题,不合格。 然后,我想到wpf在透明这块做的比较好,想是不是可以在winform中使用wpf控件来实现,结果发现还是走... -
Winform 使用 WPF控件 设置图片透明度样例
2017-06-23 09:51:05Winform使用自定义WPF控件设置图片透明度样例: 点击1加载图片,点击2设置透明度0.1,点击3设置透明度0.9; -
c#Winform自定义控件-目录
2021-08-17 17:19:49入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。 GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git 如果... -
C# winform生成全透明控件方法
2020-12-08 10:46:24C# winform生成全透明控件方法 private void Login_Load(object sender, EventArgs e) { LoginBtn.FlatStyle = FlatStyle.Flat;///设置平面样式外观为平面 LoginBtn.BackColor = Color.Transparent;///设置... -
Winform窗体半透明,控件不透明,皮肤美化效果
2012-05-10 13:47:33Winform窗体半透明,控件不透明,及窗体美化效果 -
C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法
2020-09-02 06:02:44主要介绍了C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法,结合实例形式分析了WinForm图片重叠后造成图片不透明的原因与相应的解决方法,需要的朋友可以参考下 -
C# WinForm 图片控件重叠透明
2020-12-10 14:09:26请注意这个透明并不是真正的透明,而是用父控件的当前位置的颜色填充PictureBox内的相应位置的颜色。 如果你有两个叠加的pictureBox,则实现互相透明是不行的。 如上高亮所示,我们都会试着设置背景为Transparent,... -
winform设置透明图片
2021-05-28 12:59:04效果图如上,第二张图片就是透明的,分两个步骤 1.BackColor设置Transparent 2.在Form_Load方法里面指定 pictrueBox的父控件 private void Form5_Load(object sender, EventArgs e) { this.pictureBox2.... -
用 C# Winform做出全透明的磨砂玻璃窗体效果代码
2020-12-26 02:03:28首先, 调用系统 API, 这里如果要引用神马的, 就不一一列出了, 大家自己引用一下. 代码如下: [StructLayout(LayoutKind.Sequential)] public struct MARGINS { public int Left; public int Right;... -
Winform 视频流上叠加透明控件 (基于DSKin框架实现)
2019-03-22 14:50:01winform窗体上叠加一些透明控件,基于DSkin框架实现。效果优美,无锯齿. (DSKIN属于商业版 而非开源框架),开发需官网购买授权码 ,请考虑后下载.. -
(二十二)c#Winform自定义控件-半透明窗体
2019-10-02 08:07:57入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。 GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git 如果... -
winform 透明控件
2011-11-25 11:31:07winform 透明控件 C# .net -
C# Winform 中真正意义的透明控件-附件资源
2021-03-05 15:20:12C# Winform 中真正意义的透明控件-附件资源 -
C# WinForm 透明控件 PictureBox透明
2014-07-30 13:27:481.要实现C# WinForm中的控件与背景的透明,可以通过设置控件的BackColor属性为Transparent,同时设置其父控件。因为在C#中,控件的透明指对父窗体透明。如果不设置Parent属性,那么控件将只对Form透明,显示的时候... -
(一)c#Winform自定义控件-基类控件-HZHControls
2022-07-04 15:17:21http://www.hzhcontrols.com...https://gitee.com/kwwwvagaa/net_winform_custom_control.git如果觉得写的还行,请点个 star 支持一下吧欢迎前来交流探讨: 企鹅群568015492 c#Winform自定义控件-目录-HZHControls - 冰
收藏数
3,660
精华内容
1,464