如何在此处创建单击事件以在动态创建的图像控件上重新调整图像大小?在ASP.NET C#中 [英] How can I create click event here for re sizing image on dynamically created image control? In ASP.NET C#

查看:93
本文介绍了如何在此处创建单击事件以在动态创建的图像控件上重新调整图像大小?在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(&quot;%&quot;);

        foreach (Coffee coffee in coffeeList)
        {
            //Create Controls
            Panel coffeePanel = new Panel();
            
            Image image = new Image { ImageUrl = coffee.Image };            
            Literal literal = new Literal { Text = &quot;&lt;br /&gt;&quot; };
            Literal literal2 = new Literal { Text = &quot;&lt;br /&gt;&quot; };
            Label lblName = new Label { Text = coffee.Name };
            
            
                
            Label lblPrice = new Label
            {
                Text = String.Format(&quot;{0:0.00}&quot;, coffee.Price + &quot;&lt;br /&gt;&quot;),
                CssClass = &quot;ProductsPrice&quot;
            };
            TextBox textBox = new TextBox
            {
                ID = coffee.Id.ToString(),
                CssClass = &quot;ProductsTextBox&quot;,
                Width = 60,
                Text = &quot;0&quot;
            };

            //Add validation so only numbers can be entered into the textfields
            RegularExpressionValidator regex = new RegularExpressionValidator
            {
                ValidationExpression = &quot;^[0-9]*&quot;,
                ControlToValidate = textBox.ID,
                ErrorMessage = &quot;Please enter a number.&quot;
            };

            //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

推荐答案

在WinForms中有这样的事情(看得太晚,你提到ASP,请将问题标记为ASP):

Something like this in WinForms (saw too late that you mentioned ASP, please tag question as ASP):
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#中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆