一个 Panel上生成多个随机控件以后的问题 你可以配合服务器端的Table来控制位置。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 长度的话,你控制新生成的控件的Width即可咯。 to lese9(乐色.Net) 能具体点么?比如我想把随机控件每生成一个就换一行样子: panel_________________________随机label2 |随机label2 |随机label3 |随机label4 |随机label5 |随机label6 | 在要换行的地方加上:mypanel.Controls.Add(new LiteralControl("<br>"));--------------------------------AspNetPager 免费分页控件4.2版发布,同时发布最新源代码,欢迎下载:http://www.webdiyer.com using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Miner{/// <summary>/// Summary des cription for Form1./// </summary>public class Form1 : System.Windows.Forms.Form{ private System.Windows.Forms.Panel panel1; /// <summary> /// Required designer variable. /// </summary> /// private Button[] n =new Button[100]; private int[] kn=new int[100]; private System.ComponentModel.Container components = null; 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.panel1 = new System.Windows.Forms.Panel(); this.SuspendLayout(); // // panel1 // this.panel1.Location = new System.Drawing.Point(8, 8); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(400, 400); this.panel1.TabIndex = 0; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(416, 413); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panel1}); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Load(object sender, System.EventArgs e) { int a=0; int x=0,y=0; for (a=0;a<=99;a++) { n[a] = new Button(); n[a].BackColor =Color.White; n[a].FlatStyle = FlatStyle.Flat; n[a].Width = panel1.Width / 10; n[a].Left = x * n[a].Width; n[a].Height = panel1.Height / 10; n[a].Top = y * n[a].Height; n[a].Name = "b" + a; panel1.Controls.Add(n[a]); panel1.Controls[a].MouseDown += new MouseEventHandler(this.ButtonArray_OnClick); x += 1; if (x == 10) { x = 0; y += 1; } } } private void ButtonArray_OnClick(object sender, MouseEventArgs e) { MouseEventArgs arg=(MouseEventArgs)e; Button b1=(Button)sender; if (arg.Button==MouseButtons.Right ) b1.BackColor=Color.White ; else { //b1.BackColor =Color.White ; b1.Image=Image.FromFile("f:\\my documents\\my pictures\\elements\\regular_smile.gif"); } }}} 多谢~我自己再去看看mypanel.Controls.Add的用法 repeater,datalist控件嵌套绑定的分页问题?? 新手提问,ajax查询数据 一个页面可以显示两个带runat="server"的form吗? vs2005+sybase 中的GridView 绑定问题 高手看过来,如何写代码生成器! 怎样实现颜色选择 不刷新DropDownList如何弄呢 jquery删除table 如何在javascript中调用服务器端控件textbox的值? 你用过Toolbar,TabScript 吗?其功能???? 在局域网中用asp.net上传超过100M的文件怎么实现? 一个水晶报表的问题,登陆失败
能具体点么?比如我想把随机控件每生成一个就换一行
样子:
panel
_________________________
随机label2 |
随机label2 |
随机label3 |
随机label4 |
随机label5 |
随机label6 |
AspNetPager 免费分页控件4.2版发布,同时发布最新源代码,欢迎下载:http://www.webdiyer.com
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace Miner
{
/// <summary>
/// Summary des cription for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
/// private Button[] n =new Button[100];
private int[] kn=new int[100]; private System.ComponentModel.Container components = null; 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.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(8, 8);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(400, 400);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(416, 413);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void Form1_Load(object sender, System.EventArgs e)
{
int a=0;
int x=0,y=0;
for (a=0;a<=99;a++)
{
n[a] = new Button();
n[a].BackColor =Color.White;
n[a].FlatStyle = FlatStyle.Flat;
n[a].Width = panel1.Width / 10;
n[a].Left = x * n[a].Width;
n[a].Height = panel1.Height / 10;
n[a].Top = y * n[a].Height;
n[a].Name = "b" + a;
panel1.Controls.Add(n[a]);
panel1.Controls[a].MouseDown += new MouseEventHandler(this.ButtonArray_OnClick);
x += 1;
if (x == 10)
{
x = 0;
y += 1;
}
} } private void ButtonArray_OnClick(object sender, MouseEventArgs e)
{
MouseEventArgs arg=(MouseEventArgs)e;
Button b1=(Button)sender;
if (arg.Button==MouseButtons.Right )
b1.BackColor=Color.White ;
else
{
//b1.BackColor =Color.White ;
b1.Image=Image.FromFile("f:\\my documents\\my pictures\\elements\\regular_smile.gif");
}
}
}
}
我自己再去看看mypanel.Controls.Add的用法