C#新手问 我也是新手,不知現在學C#好,還是學java好。希望各路高手指點。呵呵:> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected override void OnPaint(PaintEventArgs e){........}会自动刷新的 一般来说,如果在OnPaint以外进行绘制,有可能切换、缩放界面以后就看不到了。如果要实现LZ的这个功能,可以用Timer每隔一段时间执行一次。using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace WindowsApplication1{ /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.timer1 = new System.Windows.Forms.Timer(this.components); // // timer1 // this.timer1.Enabled = true; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "Form1"; this.Text = "Form1"; this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private int pos = 0; private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { // calc a point if (e.ClipRectangle.IsEmpty) return ; // center point Rectangle r = this.ClientRectangle; Point p1 = new Point(r.Left + r.Width / 2, r.Top + r.Height / 2); // another point double x = p1.X + Math.Cos(Math.PI * pos / 180.0) * (r.Width / 2 - 20); double y = p1.Y + Math.Sin(Math.PI * pos / 180.0) * (r.Width / 2 - 20); Point p2 = new Point((int)x, (int)y); // draw line e.Graphics.DrawLine(Pens.Navy, p1, p2); } private void timer1_Tick(object sender, System.EventArgs e) { pos += 3; // using residue number pos = pos % 360; // redraw this form this.Invalidate(); } }} 用timer控件,里面有个tick的属性,就是每隔多长时间执行一次命令 如果是做的是WinForm窗体,加一个Timer控件,在控件栏中可以找到这个控件,Timer控件中的Interval属性是设置循环事件的间隔,单位为毫秒,1秒=1000毫秒,Timer还有一个Tick事件,那是循环时所要调用的事件,在这个事件中写你要调用的代码,就可以实现你的要求了。 你也可以用线程,里面有个sleep(要间隔的时间)方法,在线程里调用就可以了 C#多线程学习遇到的一点疑问 如何往上一控件跳转? 为什么拖到tableLayoutPanel里的其它控件都只能自动左上角对齐啊,能不能改变他的对齐方式? 正则表达式问题关于逻辑或 我弄的OpenProcess有问题,返回的是0 ,不知道怎么改啊?谢谢! listview 分页(C#) 请教一个关于MenuStrip的问题 新建的选项卡在运行时不显示 菜鸟的问题, 急急急!!!,一定给! 我有C/C++基础,请推荐几本C#的书! 如何在两个项目中实现交互 vb.net函数转成C#
{
........
}
会自动刷新的
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //
// TODO: Add any constructor code after InitializeComponent call
//
} /// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private int pos = 0; private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// calc a point
if (e.ClipRectangle.IsEmpty)
return ; // center point
Rectangle r = this.ClientRectangle;
Point p1 = new Point(r.Left + r.Width / 2,
r.Top + r.Height / 2);
// another point
double x = p1.X + Math.Cos(Math.PI * pos / 180.0) * (r.Width / 2 - 20);
double y = p1.Y + Math.Sin(Math.PI * pos / 180.0) * (r.Width / 2 - 20);
Point p2 = new Point((int)x, (int)y);
// draw line
e.Graphics.DrawLine(Pens.Navy, p1, p2);
} private void timer1_Tick(object sender, System.EventArgs e)
{
pos += 3;
// using residue number
pos = pos % 360;
// redraw this form
this.Invalidate();
} }
}