问题描述
Hello Guys,我希望你会很好,我面临着一个逻辑问题,它需要像这样的按钮 []
在我的形式,但我不能这样做请帮助我我该怎么办
谢谢
我尝试过的:
按钮按钮=发送者为按钮;
string buttonText = button.Text;
MessageBox.Show(buttonText);
int CatId = OperationAccess.GetId(从tbl_Catagary中选择catID,其中name ='+ button.Text +');
列表按钮=新列表();
列表<字符串> All_Catagary = OperationAccess.GetName(SELECT name FROM tbl_product where catID =+ CatId +);
int repetition = 0;
for(int i = 0; i< All_Catagary.Count; i ++)
{
Button Productbtn = new Button();
Productbtn.Text = All_Catagary [i] .ToString();
string Command =SELECT [image] FROM tbl_product where name ='+ Productbtn.Text +';
string path = OperationAccess。 GetImage(Command);
string appPath = Path.GetDirectoryName(Application.ExecutablePath)+ @\ ProductImage \;
string TotalPath = appPath + path;
Productbtn.Image = System.Drawing.Image.FromFile(TotalPath);
Productbtn.Visible = true;
Productbtn.Location = new Point (3 +重复* 107,3);
Productbtn.Height = 54;
Productbtn.Width = 110;
Productbtn.BackColor = Color.FromArgb(40,40,40) ;
Productbtn.ForeColor = Color.White;
Productbtn.Top = 10;
Productbtn.Font = new Font(Lucida Console ,16);
buttons.Add(Productbtn);
重复++;
this.panel9.Controls.Add(Productbtn);
Productbtn.Click + = new EventHandler(Productbtn_Click);
Hello Guys,I hopeyou will be fine guys i have facing a logical problems that it
i want buttons like this in m[^]
in my form but i can't do it please help me how can i do it
Thanks
What I have tried:
Button button = sender as Button;
string buttonText = button.Text;
MessageBox.Show(buttonText);
int CatId = OperationAccess.GetId("SELECT catID from tbl_Catagary where name='" + button.Text + "'");
List buttons = new List();
List<string> All_Catagary = OperationAccess.GetName("SELECT name FROM tbl_product where catID=" + CatId + "");
int repetition = 0;
for (int i = 0; i < All_Catagary.Count; i++)
{
Button Productbtn = new Button();
Productbtn.Text = All_Catagary[i].ToString();
string Command = "SELECT [image] FROM tbl_product where name ='" + Productbtn.Text + "'";
string path = OperationAccess.GetImage(Command);
string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\ProductImage\";
string TotalPath = appPath + path;
Productbtn.Image = System.Drawing.Image.FromFile(TotalPath);
Productbtn.Visible = true;
Productbtn.Location = new Point(3 + repetition * 107, 3);
Productbtn.Height = 54;
Productbtn.Width = 110;
Productbtn.BackColor = Color.FromArgb(40, 40, 40);
Productbtn.ForeColor = Color.White;
Productbtn.Top =10;
Productbtn.Font = new Font("Lucida Console", 16);
buttons.Add(Productbtn);
repetition++;
this.panel9.Controls.Add(Productbtn);
Productbtn.Click += new EventHandler(Productbtn_Click);
推荐答案
buttons.Add(Productbtn);
尝试:
try:
this.Controls.Add(Productbtn);
/ ravi
int leftPosition = 10;
for(int i =0; i< 5;i++)
{
Button myButton = new Button();
myButton.Name = "Button" + i.ToString();
myButton.Text = i.ToString();
myButton.width = 110;
myButton.Height = 58;
myButton.top = 10;
myButton.Left = leftPosition;
panel1.Controls.Add(myButton);
leftPosition += 120;
}
这篇关于如何安排动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!