我可以得到我动态生成的控件的id,比如一个LinkButton ,是这个样子的result_i,由于是动态生成 的 ,所以我顺序分配了i的值,但是怎么在程序中或得指定的某个id的linkbutton的位置数值呢?也就是说,我知道这个控件的id是:“result_”+i.tostring(),如何得到它所在的位置呢?
不知道我 说明白了没有,呵呵。谢谢大家
不知道我 说明白了没有,呵呵。谢谢大家
解决方案 »
- 帮忙看看进程问题-----------------------------?
- ----=====急=====----问个xmlhttp的问题。客户端脚本提交的问题。
- 关于CompactFramework
- 请问C#如何实现delay函数功能
- 为什么我写的Windows服务中的Timer总是不触发Tick事件?
- .net 程序集dll 文件如何在打包部署的时候注册到注册表
- Tesseract-OCR文字训练的问题
- 在線編輯excel
- 一个关于Main()过程的问题!
- 对了, yarshray(saga jion)你好,我想与你联系,OK?
- 很简单的问题!白送分啊!!
- 文件傳輸問題,急(解決就給分)
有了控件的id,哪你怎么定的位置呀
些个JAVASCRIPT来布局!方便。
Control myControl1 = FindControl(receive.ID);
TextBox1.Text =Convert.ToString(myControl1.id);
如果我这样写可以在textbox里显示找到的控件的id,但是我想得到它的位置height怎么做?
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace work
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class WinMain : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
private Button btnAdd ;
private System.ComponentModel.Container components = null ;
private Button txtAdd ;
//给产生的按钮定义一个数量计算器
private int counter ;
//给产生的按钮定义相对位置的纵坐标
private int locY ;
//给产生的文本框定义一个数量计算器
private int counter01 ;
private System.Windows.Forms.Button Close;
//给产生的文本框定义相对位置的纵坐标
private int locY1 ; /// </summary> public WinMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//初始化产生的按钮何文本框位置的纵坐标
locY = this.btnAdd.Location.Y ;
locY1 = this.txtAdd.Location.Y ;
//
// 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.btnAdd = new System.Windows.Forms.Button();
this.txtAdd = new System.Windows.Forms.Button();
this.Close = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnAdd
//
this.btnAdd.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnAdd.Location = new System.Drawing.Point(10, 17);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(90, 25);
this.btnAdd.TabIndex = 0;
this.btnAdd.Text = "生成按钮!";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// txtAdd
//
this.txtAdd.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.txtAdd.Location = new System.Drawing.Point(130, 17);
this.txtAdd.Name = "txtAdd";
this.txtAdd.Size = new System.Drawing.Size(90, 25);
this.txtAdd.TabIndex = 1;
this.txtAdd.Text = "生成文本框!";
this.txtAdd.Click += new System.EventHandler(this.txtAdd_Click);
//
// Close
//
this.Close.Location = new System.Drawing.Point(96, 232);
this.Close.Name = "Close";
this.Close.Size = new System.Drawing.Size(80, 24);
this.Close.TabIndex = 2;
this.Close.Text = "关闭";
this.Close.Click += new System.EventHandler(this.Close_Click);
//
// WinMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(350, 294);
this.Controls.Add(this.Close);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.txtAdd);
this.Name = "WinMain";
this.Text = "在Visual C#中如何动态产生组件!";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new WinMain());
}
private void btnAdd_Click ( object sender , System.EventArgs e )
{
//按钮数量计算器在每次按钮按动后加"1"
counter += 1 ;
//对要产生的按钮的纵坐标的相对位置是前一个产生按钮的相对位置的纵坐标加"3"
locY += this.btnAdd.Height + 3 ;
//创建一个新的Button组件
Button myButton = new Button ( ) ;
//设定他的名称和Text属性,以及产生的位置
myButton.Name = "Button " + counter ;
myButton.Text = "按钮 " + counter ;
myButton.Location = new Point ( btnAdd.Location.X , locY ) ; //为产生的新的Button组件设定事件,本文中为产生的按钮设定了三个事件
myButton.MouseEnter += new System.EventHandler ( this.btn_MouseEnter ) ;
myButton.MouseLeave += new System.EventHandler ( this.btn_MouseLeave ) ;
myButton.Click += new System.EventHandler ( this.btn_Click ) ;
//在窗体中显示此按钮
this.Controls.Add ( myButton ) ;
} private void txtAdd_Click ( object sender , System.EventArgs e )
{
//文本框数量计算器在每次按钮按动后加"1"
counter01 += 1 ;
//对要产生的文本框的纵坐标的相对位置是前一个产生按钮的相对位置的纵坐标加"3
locY1 += this.txtAdd.Height + 3 ;
//创建一个新的TextBox组件
TextBox myBox = new TextBox ( ) ;
//设定他的名称和Text属性,以及产生的位置
myBox.Name = "TextBox " + counter01 ;
myBox.Text = "文本框 " + counter01 ;
myBox.Location = new Point ( txtAdd.Location.X , locY1 ) ;
//为产生的新的TextBox组件设定事件,本文中为产生的文本框设定了一个事件
myBox.Click += new System.EventHandler ( this.btn_Click ) ;
//在窗体中显示此文本框
this.Controls.Add ( myBox ) ;
}
private void btn_MouseEnter ( object sender , System.EventArgs e )
{
//出箱
Button currentButton = ( Button ) sender ;
//设定按钮的背景色
currentButton.BackColor = Color.Red ;
} private void btn_MouseLeave ( object sender , System.EventArgs e )
{
//出箱
Button currentButton = ( Button ) sender ;
currentButton.BackColor = Control.DefaultBackColor ;
} private void btn_Click ( object sender , System.EventArgs e )
{
if ( sender.GetType ( ) == typeof ( Button ) )
{
Button control = ( Button ) sender ;
MessageBox.Show ( control.Text + "被按动了!");
}
else
{
TextBox control = ( TextBox ) sender ;
MessageBox.Show ( control.Text + "被按动了!" ) ;
}
} private void Form1_Load(object sender, System.EventArgs e)
{ } private void OK_Click(object sender, System.EventArgs e)
{
} private void Close_Click(object sender, System.EventArgs e)
{ }
}
}