本文介绍了如何在此处创建单击事件以在动态创建的图像控件上重新调整图像大小?在ASP.NET C#中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每件事情都很顺利但是在这里我想要什么时候ASP表格加载了控件和控件来填充数据库中的数据。
然后我想点击图片来重新调整它。我该怎么办?它。有可能吗?如果有,请有人帮助我。
Every thing is going fine but here i want when ASP form loaded with controls and control filled with data from database.
Then i want to click on image for re sizing it.How can i do it.Is it possible? if yes, Please someone help me.
<pre lang="C#">//Fill page with dynamic controls showing products in database
private void GenerateControls()
{
//Get all coffeeObjects from database
ArrayList coffeeList = Connectionclass.GetCoffeeByType("%");
foreach (Coffee coffee in coffeeList)
{
//Create Controls
Panel coffeePanel = new Panel();
Image image = new Image { ImageUrl = coffee.Image };
Literal literal = new Literal { Text = "<br />" };
Literal literal2 = new Literal { Text = "<br />" };
Label lblName = new Label { Text = coffee.Name };
Label lblPrice = new Label
{
Text = String.Format("{0:0.00}", coffee.Price + "<br />"),
CssClass = "ProductsPrice"
};
TextBox textBox = new TextBox
{
ID = coffee.Id.ToString(),
CssClass = "ProductsTextBox",
Width = 60,
Text = "0"
};
//Add validation so only numbers can be entered into the textfields
RegularExpressionValidator regex = new RegularExpressionValidator
{
ValidationExpression = "^[0-9]*",
ControlToValidate = textBox.ID,
ErrorMessage = "Please enter a number."
};
//Add controls to Panels
coffeePanel.Controls.Add(image);
coffeePanel.Controls.Add(literal);
coffeePanel.Controls.Add(lblName);
coffeePanel.Controls.Add(literal2);
coffeePanel.Controls.Add(lblPrice);
coffeePanel.Controls.Add(textBox);
coffeePanel.Controls.Add(regex);
pnlProducts.Controls.Add(coffeePanel);
}
}</pre>
我尝试过:
如何在此处创建点击事件,以便在动态创建的图像控件上重新调整图像大小?与c#asp.net
What I have tried:
How can i create click event here for re sizing image on dynamically created Image control? with c# asp.net
推荐答案
private void GenerateControls()
{
Button button = new Button();
button.BackgroundImage = Image.FromFile("coffee.png");
button.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
coffeePanel.Controls.Add(button);
button.Click += new System.EventHandler(this.button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Clicked !");
}
如果您不想看到按钮边框,请按如下方式设置属性:
If you don't want to see the button borders, set the properties as follows:
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
这篇关于如何在此处创建单击事件以在动态创建的图像控件上重新调整图像大小?在ASP.NET C#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!