使用Pictureboxes和amp;编码的更智能的编码方式文本框C#Windows窗体 [英] Smarter way of coding with Pictureboxes & textboxes C# Windows Forms
问题描述
您好!我需要一些帮助来弄清楚如何更快地编写代码(将在一分钟内解释)
PS很长的代码!!!!
我几乎是C#&的初学者通常编码并做最简单的事情。最慢的方式..
我有一张包含150多个图片盒的表格。当点击一个图片框时,它会加载文字信息和诸如此类的东西。
如果你以游戏英雄联盟而闻名,这将更加理解(我希望)
无论如何,这是我编写代码的方式。看看我可以用编程嘿嘿。
我想知道是否有更快的编码方法,而不是在每个图片框中编码。 br />
这是我目前5个当前图片盒的代码。
(代码很长,所以不得不上传它对于pastebin,我很抱歉。)
代码 - > http://pastebin.com/4r73jLzg [ ^ ]
以下是每个图片框的功能。
•加载图片框的声音(每个pB上的声音不同)
•单击Picturebox获取Borderstyle Fixed3D并将所有其他声音更改为None。
•更改程序top各个点击的名称pB
•为某个文本框添加第二个名称
•txtAtk1~10& txtDef1~10& txtAbi1~10& txtDiff11~10使纹理框颜色变为白色,然后根据此pB的统计数据将其从1到10进行着色(我说pB但它适用于相应的角色)
•为每个角色添加价格(不同的价格)
•为每个冠军添加生命值/法力/力量(统计数据)(也有不同的)
•最后从pBSkins1~7清除之前的图像然后添加相应的图像取决于哪个图片框被点击。
以下是一些图片,看起来像......
http://i.gyazo.com/e0e623a40a86338c5ee7a91408815540.png [ ^ ]
http://i.gyazo.com/67c166de694d276682a22b928ac59c8a.png [ ^ ]
http:// i。 gyazo.com/a2ddcf51d83ff01a78b0d2a11afb0ede.png [ ^ ]
http://i.gyazo.com/732d52622144c4d3152783bf23924b2e.png [ ^ ]
http://i.gyazo.com/f9f9e803bc65d8e42eee2b97015e82e8.png [ ^ ]
Hello! I need some help to figure out how to code things "faster" (will explain this in a minute)
P.S Very long code!!!!
I am pretty much a beginner with C# & coding generally and do things the easiest & slowest way possible..
I got a form with 150+ pictureboxes & when clicking a picturebox it loads text information and whatnot.
If you are known for the game League of Legends this will be more understanding (I hope)
Anyhow it is a way for me to code & see how far I can get with programming hehe.
I would like to know if there is a faster way of coding this instead of coding in each and every picturebox.
This is my current code for 5 current pictureboxes.
(Code is VERY long so had to upload it to pastebin, I am so sorry for that.)
The Code -> http://pastebin.com/4r73jLzg[^]
Here are the things each picturebox does.
• Loads the sound of the picturebox (Different sounds on each pB)
• Clicked Picturebox gets Borderstyle Fixed3D and changes all others to None.
• Changing programs top name to respective clicked pB
• Adds second name for a certain textbox
• txtAtk1 ~ 10 & txtDef1 ~ 10 & txtAbi1 ~ 10 & txtDiff11 ~ 10 makes the texturebox color White and thereafter colors it from 1 to 10 depending on the stats of this pB (I say pB but it is for the respective Character)
• Adding Prices for each Character (Different Price)
• Adding Health / Mana / Atk (Stats) For each champion (Different there too)
• At the end Clearing previous Images from pBSkins1 ~ 7 then adding respective Images depending which picturebox is clicked.
Here are some images with how it looks like..
http://i.gyazo.com/e0e623a40a86338c5ee7a91408815540.png[^]
http://i.gyazo.com/67c166de694d276682a22b928ac59c8a.png[^]
http://i.gyazo.com/a2ddcf51d83ff01a78b0d2a11afb0ede.png[^]
http://i.gyazo.com/732d52622144c4d3152783bf23924b2e.png[^]
http://i.gyazo.com/f9f9e803bc65d8e42eee2b97015e82e8.png[^]
推荐答案
是的,根本不要使用PictureBoxes。
学习直接在控制界面上绘图,如TabPage或Form或Panel控件。这是在每个控件的Paint事件中完成的。
Google:如何在表单上绘制 [ ^ ]
Yeah, don't use PictureBoxes at all.
Learn to draw directly on the control surface, like TabPage or Form or a Panel control. This is done in the Paint event for each control.
Google: How to draw on form[^]
首先,从xml文件中读取数据。它可以是这样的;
First of all, read data from a xml file. It can be something like this;
<game>
<champion id = 1 name = "Ahri" Health = 460>
<Skins id = 1 name = "A Ahri"/>
<Skins id = 2 name = "B Ahri"/>
<Skins id = 3 name = "C Ahri"/>
<Skins id = 4 name = "D Ahri"/>
</champion >
<champion id = 2 name = "Akali" Health = 550>
<Skins id = 1 name = "A Akali"/>
<Skins id = 2 name = "B Akali"/>
<Skins id = 3 name = "C Akali"/>
<Skins id = 4 name = "D Akali"/>
</champion >
</game>
将所有这些角色图片放入特定文件夹,例如Char Images。我知道字符名称是唯一的,你可以用字符名称命名图像。
+现在读取这个xml,你有一个可枚举的XDocument变量。
+将一个flowlayoutpanel停靠在你的选择冠军标签中。
+此XDocument中的Foreach XElement
+我不知道你在做什么样的操作与champs的picturebox但你宁愿做一个usercontrol而不是它。使用XElement填充此usercontrol,注册其click事件,并添加到flowlayoutpanel。
Put all those character images into a specific folder, like "Char Images". I know character names are unique, you can name images by char name.
+ Now read this xml, you have an enumerable XDocument variable.
+ Put a flowlayoutpanel docked into your "Select champion" tab.
+ Foreach XElement in this XDocument
+ I don't know what kind of operations you are doing with picturebox of champs but you'd rather make a usercontrol instead of it. Populate this usercontrol with XElement, register its click event, and add to flowlayoutpanel.
private void LoadXml(string xmlPath)
{
var doc = XDocument.Load(xmlPath);
var champGroups = from grp in doc.Descendants("champion")
select grp;
foreach (XElement champion in champGroups)
{
Champion champUC = new Champion(champion);
champUC.Click += champUC_Click;
}
}
void champUC_Click(object sender, EventArgs e)
{
(sender as Champion).BorderStyle = BorderStyle.Fixed3D;
flowLayoutPanel1.Controls.OfType<Champion>().ToList().ForEach(p=> p.BorderStyle = BorderStyle.None);
//Populate other controls with this champion object, like;
//CharacterAttributesUC.Load(sender as Champion);
//SkinsUC.Load(sender as Champion);
}
如果你卡住了,我可以走得更远。
快乐编码。
If you stuck, I can go further.
Happy coding.
这篇关于使用Pictureboxes和amp;编码的更智能的编码方式文本框C#Windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!