110,477
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Windows.Forms;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
PB1.Visible = PB2.Visible = true;
}
private void button1_Click(object sender, EventArgs e)
{
PB1.Visible = PB2.Visible = false;
}
}
}
namespace Demo
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.panel1 = new System.Windows.Forms.Panel();
this.PB1 = new System.Windows.Forms.PictureBox();
this.pictureBox2 = new System.Windows.Forms.PictureBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.PB2 = new System.Windows.Forms.PictureBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PB1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.PB2)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("panel1.BackgroundImage")));
this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.panel1.Controls.Add(this.PB1);
this.panel1.Controls.Add(this.pictureBox2);
this.panel1.Controls.Add(this.textBox1);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(171, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(489, 154);
this.panel1.TabIndex = 0;
//
// PB1
//
this.PB1.BackColor = System.Drawing.Color.Transparent;
this.PB1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.PB1.Image = ((System.Drawing.Image)(resources.GetObject("PB1.Image")));
this.PB1.Location = new System.Drawing.Point(82, 39);
this.PB1.Name = "PB1";
this.PB1.Size = new System.Drawing.Size(293, 88);
this.PB1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.PB1.TabIndex = 1;
this.PB1.TabStop = false;
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.Transparent;
this.pictureBox2.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
this.pictureBox2.Location = new System.Drawing.Point(42, 25);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(95, 103);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox2.TabIndex = 2;
this.pictureBox2.TabStop = false;
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("宋体", 36F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.textBox1.Location = new System.Drawing.Point(197, 78);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(201, 62);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "这是文本框";
//
// label1
//
this.label1.AutoSize = true;
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("宋体", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(204, 25);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(181, 33);
this.label1.TabIndex = 0;
this.label1.Text = "这是一个LB";
//
// PB2
//
this.PB2.BackColor = System.Drawing.Color.Transparent;
this.PB2.Image = ((System.Drawing.Image)(resources.GetObject("PB2.Image")));
this.PB2.Location = new System.Drawing.Point(37, 51);
this.PB2.Name = "PB2";
this.PB2.Size = new System.Drawing.Size(100, 50);
this.PB2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.PB2.TabIndex = 3;
this.PB2.TabStop = false;
//
// textBox2
//
this.textBox2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.textBox2.Location = new System.Drawing.Point(12, 195);
this.textBox2.Multiline = true;
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(776, 231);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "这种情况下.如何在点击显示的时候把 淘汰 显示是透明的\r\n\r\n淘汰本身 就是透明的图片\r\n\r\n不能挡住后面的文本框,lable 和图片\r\n";
//
// button1
//
this.button1.Location = new System.Drawing.Point(711, 37);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 5;
this.button1.Text = "隐藏";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(711, 116);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 6;
this.button2.Text = "显示";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.PB2);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Text = "Form1";
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.PB1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.PB2)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.PictureBox PB2;
private System.Windows.Forms.PictureBox pictureBox2;
private System.Windows.Forms.PictureBox PB1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}
private void button2_Click(object sender, EventArgs e)
{
PB1.Visible = PB2.Visible = true;
PB1.Image = Bitmap_Tansparent(((new Bitmap(Image.FromFile(Application.StartupPath + "\\淘汰.png")))), 58);
}
是偶了解错了.不是这样弄吗
public Bitmap Bitmap_Tansparent(Bitmap src, int num)
{
try
{
int w = src.Width;
int h = src.Height;
Bitmap dstBitmap = new Bitmap(src.Width, src.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData srcData = src.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
unsafe
{
byte* pIn = (byte*)srcData.Scan0.ToPointer();
byte* pOut = (byte*)dstData.Scan0.ToPointer();
byte* p;
int stride = srcData.Stride;
int r, g, b;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
p = pIn;
b = pIn[0];
g = pIn[1];
r = pIn[2];
pOut[1] = (byte)g;
pOut[2] = (byte)r;
pOut[3] = (byte)num;
pOut[0] = (byte)b;
pIn += 4;
pOut += 4;
}
pIn += srcData.Stride - w * 4;
pOut += srcData.Stride - w * 4;
}
src.UnlockBits(srcData);
dstBitmap.UnlockBits(dstData);
return dstBitmap;
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString());
return null;
}
}