![]() |
Controls zur laufzeit einem userControl unterordnen
Hallo,
ich hab ein kleines problem, welches normalerweise keins wäre, wenn ich es nicht mit den WinForms zu tun hätte ;) Also eine Control klasse
Code:
jetzt will ich diese zur laufzeit in ein userControl hängen:
public class DoaViewProperty : Control
{ private DaoViewCore daoViewCore; private PropertyInfo propertyInfo; public DoaViewProperty(DaoViewCore aDaoViewCore, PropertyInfo aPropertyInfo) :base() { daoViewCore = aDaoViewCore; propertyInfo = aPropertyInfo; this.Text = propertyInfo.Name; //this.Parent = daoViewCore; //daoViewCore.Controls.Add(this); daoViewCore.ResumeLayout(false); daoViewCore.PerformLayout(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawString(propertyInfo.Name, Font, Brushes.Black, new Point(2, 2)); } }
Code:
So, die schleife läuft er prima durch. Er übergibt alle nötigen daten, ohne fehler. ABER es erscheint kein Control!
// im userControl
foreach (PropertyInfo pi in modelType.GetProperties()) { using(DoaViewProperty dvp = new DoaViewProperty(this, pi)) { dvp.AutoSize = false; dvp.BackColor = System.Drawing.SystemColors.ControlDark; dvp.Location = new System.Drawing.Point(0, 0); dvp.Name = "mu"; dvp.Size = new System.Drawing.Size(100, 16); dvp.TabIndex = 0; Controls.Add(dvp); } } Update(); Wie geht der trick, die WinForms zu überreden dies zu tun? (kann auch delphi code sein) (benutze VS 2005, sollte aber hier nix zur sache tun). :gruebel: |
Re: Controls zur laufzeit einem userControl unterordnen
Code:
ist das gleiche wie
using(Type instance = new Type())
{ ... }
Code:
Du hast also das Control (also das WinAPI Control, dass hinter JEDEM Winforms control steckt) direkt nach dem Add(dvp) zerstört. ;)
Type instance = new Type();
try { ... } finally { instance.Dispose(); } |
Re: Controls zur laufzeit einem userControl unterordnen
Oooooh, arg...danke für den hinweis!
Und ich dachte, das wäre das with-do--konstrukt. Gibt es in C# denn ein normales with? |
Re: Controls zur laufzeit einem userControl unterordnen
Gibt es nicht.
Mittlerweile bin ich auch ganz froh drüber. ;) Versuche mal fremden Code mit 5 Ebenen verschachtelten with-Blöcken zu entziffern. :? |
Re: Controls zur laufzeit einem userControl unterordnen
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:27 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz