我正在编写一个程序,以便单击按钮并根据您将鼠标按住的时间打印链接的注释。我的问题是第一次点击工作正常,但是当我第二次坚持时它没有更新,这让我发疯。任何帮助都感激不尽。下面找到我正在使用的以下代码。谢谢
对于 Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NoteShape
{
public partial class Form1 : Form
{
public int duration = 0;
MusicNote mn;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
duration++;
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
timer1.Enabled = true;
duration = 0;
}
}
private void button1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
timer1.Enabled = false;
}
duration = duration % 20;
string bNoteShape = "";
if (duration >= 12)
{
bNoteShape = "SemiBreve";
}
if ((duration >= 6) && (duration <= 11))
{
bNoteShape = "Minim";
}
if ((duration >= 3) && (duration <= 5))
{
bNoteShape = "Crotchet";
}
if ((duration >= 1) && (duration <= 2))
{
bNoteShape = "Quaver";
}
if (duration == 0)
{
bNoteShape = "SemiQuaver";
}
mn = new MusicNote(1, bNoteShape);
MessageBox.Show(bNoteShape);
this.Controls.Add(this.mn);
}
}
}
对于相应的类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace NoteShape
{
class MusicNote: PictureBox
{
public string path = "ImagesName\\";
public int pitch;
public string noteShape;
public MusicNote(int iPitch, string iNoteShape) : base()
{
pitch = iPitch;
noteShape = iNoteShape;
Location = new Point(150, 50);
Size = new Size(40, 40);
Bitmap bmp1 = new Bitmap(path + noteShape + ".bmp");
Image = bmp1;
BackColor = Color.Transparent;
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
}