用圆形的图片做透明处理可以么?
具体怎么来做,谁还有更加好的方法,谢谢.
具体怎么来做,谁还有更加好的方法,谢谢.
解决方案 »
- 求DXperience资料
- 秀代码!C# 多重map的实现!
- C#界面问题
- (上一次提问表达不清楚,再发)不是用vs.net开发的c#web项目,如何看源码? 没有csprj文件的项目代码如何看及学习呢?
- 安装C#,却不能创建WEB应用程序
- 菜鸟请教
- C#如何在窗体中模拟web的Form提交做一个小程序,需要登陆网站,想要模拟网页输入用户和密码进行?
- c# winform里面listview添加完数据后怎么进行筛选功能?
- 表格!又见表格!又见不是一般表格的表格!表是表格的表!格是表格的格!DataGrid问题~~
- c#里面如何控制flash?
- gridview取列
- .net使用问题,为什麽在创建事件时,程序总是无法自动的生成事件?
{
// Create pen.
Pen redkPen = new Pen(Color.Red, 3);
// Create location and size of ellipse.
float x = 0.0F;
float y = 0.0F;
float width = 200.0F;
float height = 200.0F;
// Draw ellipse to screen.
e.Graphics.DrawEllipse(readPen, x, y, width, height);
}
请设置Timer控件的时间触发频率为1毫秒,并且为TRUEusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication5
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label4;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label1;
private int vflag;
private int miflag; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} protected override void OnPaint(PaintEventArgs e)
{
Pen redkPen = new Pen(Color.Black, 2);
Graphics g=CreateGraphics();
g.DrawEllipse(redkPen, 20.0F, 20.0F,60.0F, 60.0F);
g.DrawEllipse(redkPen, 20.0F, 100.0F,60.0F, 60.0F);
g.DrawEllipse(redkPen, 20.0F, 180.0F,60.0F, 60.0F);
} public void DrawGreenFillCircle()
{
Brush bursh=new SolidBrush(Color.Green);
float x = 20.0F;
float y = 20.0F;
float width = 60.0F;
float height = 60.0F;
Graphics g=CreateGraphics();
g.FillEllipse(bursh, x, y, width, height);
} public void DrawYellowFillCircle()
{
Brush bursh=new SolidBrush(Color.Yellow);
float x = 20.0F;
float y = 100.0F;
float width = 60.0F;
float height = 60.0F;
Graphics g=CreateGraphics();
g.FillEllipse(bursh, x, y, width, height);
} public void DrawRedFillCircle()
{
Brush bursh=new SolidBrush(Color.Red);
float x = 20.0F;
float y = 180.0F;
float width = 60.0F;
float height = 60.0F;
Graphics g=CreateGraphics();
g.FillEllipse(bursh, x, y, width, height);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label4 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label4
//
this.label4.Location = new System.Drawing.Point(120, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(104, 48);
this.label4.TabIndex = 0;
//
// label1
//
this.label1.Location = new System.Drawing.Point(160, 104);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 88);
this.label1.TabIndex = 1;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.label1);
this.Controls.Add(this.label4);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{ } private void timer1_Tick(object sender, System.EventArgs e)
{
this.vflag=System.DateTime.Now.Second;
this.miflag=System.DateTime.Now.Millisecond/10;
this.label1.Text=Convert.ToString("当前时间: "+System.DateTime.Now);
this.label4.Text=Convert.ToString("System.DateTime.Now.Millisecon "+this.miflag);
if(System.DateTime.Now.Hour>=22 || System.DateTime.Now.Hour<=7)
{
if(System.DateTime.Now.Second % 2==0)
{
this.DrawYellowFillCircle();
}
if(System.DateTime.Now.Second % 2==1)
{
this.Refresh();
}
}
else
{
if(this.vflag>=0 && this.vflag<=29)
{
this.DrawGreenFillCircle();
}
if(this.vflag>=30 && this.vflag<=59)
{
this.DrawRedFillCircle();
}
if(this.vflag==25 || this.vflag==27 || this.vflag==29 || this.vflag==55 || this.vflag==57 || this.vflag==59)
{
if(this.miflag==0 || this.miflag==99)
this.Refresh();
else
this.DrawYellowFillCircle();
}
}
}
}
}
用label就是好做临界点的处理,画圆的方法的this.Refresh()的时间不好控制.using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Red_green_lamp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label1;
private int vflag;
private System.Windows.Forms.Label label5;
private int vtemp=59; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Black;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Cursor = System.Windows.Forms.Cursors.Arrow;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 40);
this.label1.TabIndex = 0;
this.label1.Text = "绿";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Black;
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(16, 152);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 40);
this.label2.TabIndex = 1;
this.label2.Text = "红";
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Black;
this.label3.ForeColor = System.Drawing.Color.White;
this.label3.Location = new System.Drawing.Point(16, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 40);
this.label3.TabIndex = 2;
this.label3.Text = "黄";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label4
//
this.label4.Location = new System.Drawing.Point(128, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 72);
this.label4.TabIndex = 3;
//
// label5
//
this.label5.BackColor = System.Drawing.Color.Cyan;
this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label5.Location = new System.Drawing.Point(8, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 200);
this.label5.TabIndex = 4;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(248, 214);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.label5);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} private void timer1_Tick(object sender, System.EventArgs e)
{ this.vflag=System.DateTime.Now.Second;
this.label4.Text=Convert.ToString("当前时间: "+System.DateTime.Now);
if(System.DateTime.Now.Hour>=22 || System.DateTime.Now.Hour<=7)
{
this.label1.BackColor=Color.Black;
this.label2.BackColor=Color.Black;
if(System.DateTime.Now.Second % 2==1)
{
this.label3.BackColor=Color.Yellow;
}
if(System.DateTime.Now.Second % 2==0)
{
this.label3.BackColor=Color.Black;
}
}
else
{
if(this.vflag>=0 && this.vflag<30)
{
this.label1.BackColor=Color.Green;
this.label1.Text=("绿 "+Convert.ToString(this.vtemp-this.vflag-30));
}
else
{
this.label1.BackColor=Color.Black;
this.label1.Text="绿";
}
if(this.vflag>=30 && this.vflag<=59)
{
this.label2.BackColor=Color.Red;
this.label2.Text=("红 "+Convert.ToString(this.vtemp-this.vflag));
}
else
{
this.label2.BackColor=Color.Black;
this.label2.Text="红";
}
if(this.vflag==25 || this.vflag==27 || this.vflag==29 || this.vflag==55 || this.vflag==57 || this.vflag==59)this.label3.BackColor=Color.Yellow;
if(this.vflag==26 || this.vflag==28 || this.vflag==30 || this.vflag==56 || this.vflag==58 || this.vflag==0)this.label3.BackColor=Color.Black;
}
} }
}
timer = true 触发时间为 100using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Red_green_lamp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
/// public class myEllipseLabel:System.Windows.Forms.Label
{
private System.Drawing.Pen _pen;
private int _PenWidth = 2;//线宽,描边的线的宽度
private System.Drawing.Rectangle EllipseRect;//边缘尺寸 public myEllipseLabel():base()
{
EllipseRect = new System.Drawing.Rectangle(0,0,150,150);
}
protected override void InitLayout()
{
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
path.AddEllipse(this.ClientRectangle);
EllipseRect = this.ClientRectangle;
EllipseRect.Width -= (_PenWidth + 1);
EllipseRect.Height -= (_PenWidth + 1);
this.Region = new System.Drawing.Region(path);
base.InitLayout ();
}
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
{
base.OnPaintBackground (pevent);
if (_pen==null)
{
_pen = new System.Drawing.Pen(this.ForeColor,_PenWidth);
}
pevent.Graphics.DrawEllipse(_pen,EllipseRect);
} }
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private myEllipseLabel label1;
private myEllipseLabel label2;
private myEllipseLabel label3;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label4;
private int vflag;
private System.Windows.Forms.Label label5;
private int vtemp=59; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new myEllipseLabel();
this.label2 = new myEllipseLabel();
this.label3 = new myEllipseLabel();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Black;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Cursor = System.Windows.Forms.Cursors.Arrow;
this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.Color.White;
this.label1.Location = new System.Drawing.Point(16, 20);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(60, 60);
this.label1.TabIndex = 0;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.Text = "绿";
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Black;
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(16, 100);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 60);
this.label2.TabIndex = 1;
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label2.Text = "红";
//
// label3
//
this.label3.BackColor = System.Drawing.Color.Black;
this.label3.ForeColor = System.Drawing.Color.White;
this.label3.Location = new System.Drawing.Point(16, 180);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 60);
this.label3.TabIndex = 2;
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label3.Text = "黄";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label4
//
this.label4.Location = new System.Drawing.Point(128, 24);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 72);
this.label4.TabIndex = 3;
//
// label5
//
this.label5.BackColor = System.Drawing.Color.Cyan;
this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.label5.Location = new System.Drawing.Point(8, 8);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 250);
this.label5.TabIndex = 4;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(300, 300);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.label5);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
} private void timer1_Tick(object sender, System.EventArgs e)
{ this.vflag=System.DateTime.Now.Second;
this.label4.Text=Convert.ToString("当前时间: "+System.DateTime.Now);
if(System.DateTime.Now.Hour>=22 || System.DateTime.Now.Hour<=7)
{
this.label1.BackColor=Color.Black;
this.label2.BackColor=Color.Black;
if(System.DateTime.Now.Second % 2==1)
{
this.label3.BackColor=Color.Yellow;
}
if(System.DateTime.Now.Second % 2==0)
{
this.label3.BackColor=Color.Black;
}
}
else
{
if(this.vflag>=0 && this.vflag<30)
{
this.label1.BackColor=Color.Green;
this.label1.Text=("绿 "+Convert.ToString(this.vtemp-this.vflag-30));
}
else
{
this.label1.BackColor=Color.Black;
this.label1.Text="绿";
}
if(this.vflag>=30 && this.vflag<=59)
{
this.label2.BackColor=Color.Red;
this.label2.Text=("红 "+Convert.ToString(this.vtemp-this.vflag));
}
else
{
this.label2.BackColor=Color.Black;
this.label2.Text="红";
}
if(this.vflag==25 || this.vflag==27 || this.vflag==29 || this.vflag==55 || this.vflag==57 || this.vflag==59)this.label3.BackColor=Color.Yellow;
if(this.vflag==26 || this.vflag==28 || this.vflag==30 || this.vflag==56 || this.vflag==58 || this.vflag==0)this.label3.BackColor=Color.Black;
}
} }
}
http://community.csdn.net/Expert/topic/4707/4707106.xml?temp=.5346033