我在c#中创建了一个winform,我在页面和另一个控件上有3个控件,并以编程方式在其中一个原始控件上创建。这不是渲染,所以我改变了其他控件的背景颜色(它们都是明亮的颜色开始),当我运行应用程序时,变化没有发生,我匆匆过去,看不到我是什么做错了。谁能帮忙?Winform not rendering control alterations
更新: *我已设置位置,大小和名称,但它没有区别。 *奇怪的是,当我把它放在没有参数的构造函数中时,它工作正常。这似乎与第二个构造函数中的代码有关(它确实在两个构造函数中都运行了代码)。
感谢萨拉:)
GameForm.cs
namespace Hangman
{
public partial class GameForm : Form, IGameView
{
public GameForm()
{
InitializeComponent();
}
public GameForm(Game game) : this()
{
wordToGuessControl = new WordToGuessControl(game.Level);
new GamePresenter(this, wordToGuessControl, hangmanControl);
}
}
WordToGuessControl.cs
namespace Hangman.UserControls
{
public partial class WordToGuessControl : UserControl, IWordToGuessView
{
private string _word;
public WordToGuessControl()
{
InitializeComponent();
}
public WordToGuessControl(Level level) : this()
{
_word = GenerateWord(level);
foreach (var character in _word)
{
var characterInWord = new RenderLetterControl();
characterInWord.Location = new Point(0, 0);
characterInWord.Name = character.ToString();
characterInWord.Size = new Size(50,50);
characterInWord.Text = "_";
Controls.Add(characterInWord);
}
}
private string GenerateWord(Level level)
{
return new WordGenerator().GenerateWord(level);
}
}
RenderLetterControl.cs
namespace Hangman.UserControls
{
public partial class RenderLetterControl : Label
{
public RenderLetterControl()
{
InitializeComponent();
Text = "_";
}
public RenderLetterControl(char character): this()
{
string characterGuessed = character.ToString();
}
}
}
没有任何代码,几乎不可能回答这个问题。请尝试发布一个简短但完整的程序来演示问题。 – 2009-11-01 16:37:34
我会回应Jon的评论,但如果出现可怕的错误,可能需要尝试清理解决方案(手动如果需要) – Lee 2009-11-01 16:48:38
确保您的更改正在* .designer.cs文件中更新,而没有任何代码我们无法真正帮助你。 – 2009-11-01 16:55:56