WinForm中有一个PictureBox控件,通过Panel控件来做滚动条,现在想根据图片上的某点坐标来动态生成一个Label到该坐标上,请问如何实现?谢谢
解决方案 »
- 急等!c#获取word内容和图片,就是word里面包含有图片同时获取
- 做加工线的上位机监管程序用C#和组态王哪个更适合
- 求教:关于跨线程调用窗体控件
- 水晶报表问题
- richtextbox样式问题??
- 怎么用C#在B/S架构下上传图片
- 如何用installshield X制作系列号验证!
- 右键传递长文件名的问题
- 为什么Math.Round把0.5变成了0?
- c# 请问网站电影用流媒体播放的书籍,我想学
- 多线程访问文件,The process cannot access the file 'D:\1.txt' because it is being used by another process.
- 一个C#内存问题
private void AddLabelToPanle(string txt, Panel aPanel, int LblTop, int LblLeft)
{
Label lbl = new Label();
lbl.Text = txt;
lbl.Top = LblTop;
lbl.Left = LblLeft;
aPanel.Controls.Add(lbl);
}
private void AddLabelToPanle(string txt, Panel aPanel, int LblTop, int LblLeft)
{
Label lbl = new Label();
lbl.Text = txt;
lbl.Top = LblTop;
lbl.Left = LblLeft;
aPanel.Controls.Add(lbl);
lbl.Click += new System.EventHandler(lbl_Click);//在楼上代码的基础上增加这句
}
//在同一个代码文件中实现响应
private void lbl_Click(object sender, EventArgs e)
{ }
应当延长它的生存期,改用类的成员等方法会好些
lbl.Click += new System.EventHandler(lbl_Click);//在楼上代码的基础上增加这句
错误 1 “lbl_Click”的重载均与委托“System.EventHandler”不匹配
{
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()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(228, 51);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(256, 95);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(38, 51);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(12, 66);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(212, 167);
this.panel1.TabIndex = 2;
//
// Form1
//
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.panel1);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Panel panel1;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.Threading; namespace WindowsApplication1
{
public partial class Form1 : Form
{
Label lbl = null;
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{ }
private void lbl_Click(object sender, EventArgs e)//相应事件
{ }
private void button1_Click(object sender, EventArgs e)//动态添加
{
lbl = new Label();
lbl.Text = "2222";
lbl.Top = 10;
lbl.Left = 20;
panel1.Controls.Add(lbl);
lbl.Click += new System.EventHandler(lbl_Click);//在楼上代码的基础上增加这句
}
}
}
这是我试验的代码