设置Windows窗体中创建的动态控件的最佳位置 [英] set perfact location for created dynamic control in Windows form

查看:74
本文介绍了设置Windows窗体中创建的动态控件的最佳位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我想设置从数据库创建的动态控件的位置.我有2条记录,表中有2个字段.所以我想在第一行中设置1条记录,然后在第二行中设置第二条记录..

我无法成功设置动态控件的位置...

请帮忙...


谢谢和问候....
Mitesh

Dear All,

i want to set the location of created dynamic control from the database. i have 2 records with 2 fields in table. so i want to set 1 record in 1st row and then 2nd record in 2nd row..

i am not success to set the location of dynamic controlllll...

please help...


Thanks and Regards....
Mitesh

推荐答案

没有动态控件和非动态控件.它们都是一样的动态".

您可能不了解两件事.首先,避免找到控件的位置.相反,最好将对接与填充结合使用.在某些情况下,锚点可能很有用,但根据锚点的不同,它们会在调整大小时产生闪烁.请参阅:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.padding.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx [ ^ ].

但是,由于绝对位置在使用Designer时几乎是不可接受的,因此可以在动态"放置控件时使用它,这意味着手动编写代码,而无需使用调试器.顺便说一下,手动编写的代码更受支持.

您可能还有另一个问题,编写代码插入控件.基本上,这是使用Control.Controls.Add(用于父控件)或将父引用分配给Control.Parent来完成的,但是我通常还建议一种非常通用的方法来学习如何插入/排列控件.暂时仅出于学习目的,随心所欲地使用设计器添加一些控件.查看自动生成的代码.您可以轻松地学习如何在代码中编写相同的代码.

—SA
There are no dynamic vs. non-dynamic controls. They are all equally "dynamic".

There are two things you might no understand. First, avoid finding location for a control. Instead, prefer using docking in combination of padding. In some cases, anchors could be useful, but they can create some flicker on resize, depending on what''s anchored. Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.padding.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx[^].

However, as absolute position is hardly acceptable if you are using the Designer, it can be used when you position controls "dynamically", which just means manually written code, without using the Debugger. By the way, manually written code is more supportable.

You might have another problem, writing the code inserting controls. Basically, it''s done using Control.Controls.Add (for a parent control) or assigning a parent reference to Control.Parent, but I usually also recommend a very universal method of learning how to insert/arrange control. Add few control as you like using the Designer, temporarily, just for learning purpose. Look at the auto-generated code. You can easily learn how to code the same thing in your code.

—SA


这篇关于设置Windows窗体中创建的动态控件的最佳位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆