在面板顶部添加控件 [英] Add controls at the top of the panel

查看:130
本文介绍了在面板顶部添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何在面板顶部动态添加控件?

我的问题:

我有5条通知.每隔10秒,计时器将运行并从数据库中获取数据.如果找到新的通知,则会在顶部的面板中插入.意味着新的通知将显示在顶部,而较旧的则显示在该按钮上.每当新的通知到来时,它都会放在顶部,然后会显示旧的通知.

例如:首先我有5个通知2个新来的通知,比顶部2个通知和5个通知要多.10秒钟后又有4个新通知比顶部4个新通知来了,其余7个旧通知将保留在按钮上,依此类推.

请提出我将如何解决此问题的建议,或提出其他解决此问题的想法.

谢谢

How i will add controls dynamically at the top of the panel??

My problem:

I have 5 notifications . After each 10 second a timer will run and take data from database. If new notification found than that will insert to the panel at the top.Means new notifications will present at the top and older are at the button. Every time when new notification will come it will feed at the top and then it will show the older notification.

Example:first i have 5 notifications 2 new came than that 2 notifications will present at the top and than the 5 notifications.After 10 seconds again 4 new notifications came than that 4 new notifications will present at the top and rest 7 older notifications will remain at the button and so on.

please suggest how i will solve this problem or any alternate ideas to solve this problem .

Thanks

推荐答案

对于这类问题,我有一个非常通用的食谱.

您怀疑如何在代码中创建UI的某些部分?但是,您可以仅使用设计器制作想要的UI设计示例吗?如果是这样,请在某些研究项目的设计师中进行.进行裸露布局;您以后可以在代码中添加的所有其他内容.可能只需要几分钟.编译并运行该示例以确保它可以按照您的要求运行.

完成此操作后,找到在设计时自动生成的代码.如果您不知道在哪里找到它,请按子字符串使用文件搜索(对于WPF,请不要从Visual Studio进行搜索,请从外部搜索),对于搜索子字符串,请使用由以下成员创建的成员的某些成员名称:设计的(对于WPF,至少创建一些UI元素的Name属性).

现在,看看自动生成的代码并了解其工作原理.这真的很简单.



您应该了解每个控件都是动态添加的.设计的代码仅有助于生成代码,但是一旦生成,它就可以在运行时以与手工编程完全相同的方式运行.请记住,在很多情况下,手动编程会更快(因为使用鼠标"进行编程是一项人工操作,因此无法使用高效的编程抽象,例如循环和代码重用),并且可以提供更好的质量,因此您的要求非常合理.

使用设计器进行学习的方法已证明是有用的.

—SA
I have a very general cookbook recipe for many problems of such kind.

You have a doubt how to create some part of UI in code? But can you make just a sample of the UI design you want using the designer? If so, do it in designer in some research project. Do bare layout; everything else you can add later in code. It may take just few minutes. Compile and run the sample to make sure it works as you wanted.

When this is done, locate the code auto-generated during design time. If you don''t know yes where to find it, use file search by sub-string (for WPF, do it not from Visual Studio, search from outside), for a search substring, use some member name of the member created by the designed (for WPF, create at least one Name attribute of some UI element).

Now, take a look at the auto-generated code and learn how it works. This is really simple.



You should understand that every control is added dynamically. The designed simply helps to generate the code, but once generated, it works during run time exactly the same way you would program it by hand. Remember that in many cases programming by hand is faster (because programming "with mouse" is a manual labor, it cannot use efficient programming abstractions like loops and code reuse) and can give better quality, so your request makes perfect sense.

The method of using designer for learning has proven its usefulness.

—SA


这篇关于在面板顶部添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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