锚点改变控件的大小

时间:2012-04-13 16:41:49

标签: c# winforms

为了好玩,我决定手动编码我的表单,而不是使用设计器。 我的代码看起来像这样

        tpgPack.SuspendLayout();
        tpgUnpack.SuspendLayout();

        //this
        this.ClientSize = new Size(400, 600);
        this.Text = "Folder Packer";
        this.MinimumSize = new Size(250, 350);
        this.Icon = Resources._lock;
        this.Load += new EventHandler(frmMain_Load);
        this.FormClosing += new FormClosingEventHandler(frmMain_FormClosing);


        //tbctabs
        tbcTabs.Dock = DockStyle.Fill;
        this.Controls.Add(tbcTabs);

        //tpgPack
        tpgPack.Text = "Pack";
        tpgPack.UseVisualStyleBackColor = true;
        tbcTabs.Controls.Add(tpgPack);

        //tpgUnpack
        tpgUnpack.Text = "Unpack";
        tpgUnpack.UseVisualStyleBackColor = true;
        tbcTabs.Controls.Add(tpgUnpack);

        //txtselectedfolder
        txtSelectedFolder.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
        txtSelectedFolder.Location = new Point(3, 3);
        txtSelectedFolder.Width = 385;
        txtSelectedFolder.KeyPress += new KeyPressEventHandler(txtSelectedFolder_KeyPress);
        txtSelectedFolder.MouseDown += new MouseEventHandler(txtSelectedFolder_MouseDown);
        tpgPack.Controls.Add(txtSelectedFolder);

        //trvSelectedFolder
        trvSelectedFolder.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
        trvSelectedFolder.Location = new Point(3, 26);
        trvSelectedFolder.Size = new Size(385, 517);
        trvSelectedFolder.BeforeExpand += new TreeViewCancelEventHandler(trvSelectedFolder_BeforeExpand);
        trvSelectedFolder.AfterSelect += new TreeViewEventHandler(trvSelectedFolder_AfterSelect);
        trvSelectedFolder.ImageList = ilstTreeImages;
        trvSelectedFolder.ShowLines = false;
        tpgPack.Controls.Add(trvSelectedFolder);

        //lstPackedFolders
        lstPackedFolders.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
        lstPackedFolders.IntegralHeight = false;
        lstPackedFolders.Location = new Point(3, 5);
        lstPackedFolders.Size = new Size(385, 538);
        tpgUnpack.Controls.Add(lstPackedFolders);

        //btnPack
        btnPack.Text = "Pack Folder";
        btnPack.Width = 95;
        btnPack.Location = new Point(294, 548);
        btnPack.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
        btnPack.MouseClick += new MouseEventHandler(btnPack_MouseClick);
        btnPack.Enabled = false;
        tpgPack.Controls.Add(btnPack);

        //btnUnpack
        btnUnpack.Text = "Unpack Folder";
        btnUnpack.Width = 95;
        btnUnpack.Location = new Point(294, 548);
        btnUnpack.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
        btnUnpack.MouseClick += new MouseEventHandler(btnUnpack_MouseClick);
        btnUnpack.Enabled = false;
        tpgUnpack.Controls.Add(btnUnpack);

        //ilstTreeImages
        ilstTreeImages.ColorDepth = ColorDepth.Depth24Bit;
        ilstTreeImages.Images.Add(Resources.folder.ToBitmap());
        ilstTreeImages.Images.Add(Resources.drive.ToBitmap());

        tpgUnpack.ResumeLayout(false);
        tpgPack.ResumeLayout(false);

即使使用SuspendLayout()和ResumeLayout(false),为任何控件设置锚点仍然会改变它的大小,因此它远离表单的边缘。如果我移除锚,一切看起来很好。我不明白我做错了什么。我甚至将我与表单设计师“InititalizeComponent”进行了比较,并且找不到任何不同的东西。我做错了什么?

编辑:更清楚一点,它是标签页面中的控件,而不是标签控件本身,我遇到了问题。

0 个答案:

没有答案