未知错误,没有错误或崩溃。辅助PC上的C#程序

时间:2014-07-29 01:30:49

标签: c# winforms

我在以下系统中专门为在线游戏(流亡之路)编写了一个自定义计算器。

Windows 7 Home Premium, Service Pack 1, 64位操作系统

使用

适用于Windows桌面的Visual Studio Express 2013, 发布版本,任何CPU

将.exe文件复制到c:\ drive,然后双击程序exe文件运行。这在我编写程序的PC上运行得很好。

然而,当我将程序复制到辅助PC并从该PC运行时,它看起来并不正确。创建的自定义文本框与它们应该的位置不一致。

我使用以下线程中的代码来创建文本框:

Textbox not clickable but editable

public partial class TextBoxMod : TextBox
{
    protected override void WndProc(ref Message m)
    {
        int msg = m.Msg;
        if (msg == (int)WindowsMessage.WM_LBUTTONDOWN)
        {
            // messagebox here
            return;
        }
        base.WndProc(ref m);
    }
}

在构造函数中我调用了一个方法来初始化文本框,其中包含一些基本信息:

// txtBoxPDMin
box.Location = new System.Drawing.Point(155, 191);
box.Name = "txtBoxPDMin";
box.TabIndex = 0;
box.TextChanged += new System.EventHandler(txtBox_TextChanged);
box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
boxes.Add(box);

并在最后一个文本框之后:

foreach (TextBoxMod mod in boxes)
{
    mod.Size = new System.Drawing.Size(40, 22);
    if (mod.Name == "txtBoxAttSpd")
        mod.Text = "0.00";
    else
        mod.Text = "0";

    mod.ForeColor = Color.PaleTurquoise;
    mod.BackColor = SystemColors.ControlDarkDark;
    mod.Enter += new System.EventHandler(txtBoxMods_Enter);

    this.Controls.Add(mod);
}

我有一个图像文件,显示两台计算机上程序的图片,你可以看到差异:

在此图中,左侧显示了在我的主PC上运行的程序的示例,其中我进行了实际编程,它没有在调试模式下运行,而是将其构建,然后复制到运行它的单独文件夹中。右侧的图像是我在辅助PC上的样子,因为您可以看到自定义文本框未对齐,有些甚至没有在表单上显示。

Multi-PC Error on Second PC

所以我的问题是什么可能导致这个问题?没有错误或崩溃。

任何帮助都是赞赏......

路线大师

**编辑**

    private void InitializeTextBoxes()
    {
        boxes = new List<TextBoxMod>();
        box = new TextBoxMod();

        // txtBoxPDMin
        box.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left));
        box.Location = new System.Drawing.Point(155, 191);
        box.Name = "txtBoxPDMin";
        box.TabIndex = 0;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxPDMax
        box.Location = new System.Drawing.Point(220, 191);
        box.Name = "txtBoxPDMax";
        box.TabIndex = 1;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxFDMin
        box.Location = new System.Drawing.Point(155, 219);
        box.Name = "txtBoxFDMin";
        box.TabIndex = 2;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxFDMax
        box.Location = new System.Drawing.Point(220, 219);
        box.Name = "txtBoxFDMax";
        box.TabIndex = 3;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxLDMin
        box.Location = new System.Drawing.Point(155, 247);
        box.Name = "txtBoxLDMin";
        box.TabIndex = 4;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxLDMax
        box.Location = new System.Drawing.Point(220, 247);
        box.Name = "txtBoxLDMax";
        box.TabIndex = 5;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxCDMin
        box.Location = new System.Drawing.Point(155, 275);
        box.Name = "txtBoxCDMin";
        box.TabIndex = 6;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxCDMax
        box.Location = new System.Drawing.Point(220, 275);
        box.Name = "txtBoxCDMax";
        box.TabIndex = 7;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
        boxes.Add(box);

        box = new TextBoxMod();

        // txtBoxAttSpd
        box.Location = new System.Drawing.Point(155, 303);
        box.Name = "txtBoxAttSpd";
        box.TabIndex = 8;
        box.TextChanged += new System.EventHandler(txtBox_TextChanged);
        box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxAttSpd_KeyDown);
        boxes.Add(box);

        foreach (TextBoxMod mod in boxes)
        {
            mod.Size = new System.Drawing.Size(40, 22);
            if (mod.Name == "txtBoxAttSpd")
                mod.Text = "0.00";
            else
                mod.Text = "0";

            mod.ForeColor = Color.PaleTurquoise;
            mod.BackColor = SystemColors.ControlDarkDark;
            mod.Enter += new System.EventHandler(txtBoxMods_Enter);
            //box.KeyDown += new System.Windows.Forms.KeyEventHandler(txtBoxKeyMove_KeyDown);
            this.Controls.Add(mod);
        }
    }

0 个答案:

没有答案