Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   C# Controls zur laufzeit einem userControl unterordnen (https://www.delphipraxis.net/41746-controls-zur-laufzeit-einem-usercontrol-unterordnen.html)

maximov 7. Mär 2005 23:25


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:
    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));
        }
    }
jetzt will ich diese zur laufzeit in ein userControl hängen:

Code:
  // 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();
So, die schleife läuft er prima durch. Er übergibt alle nötigen daten, ohne fehler. ABER es erscheint kein Control!

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:

Robert_G 8. Mär 2005 00:04

Re: Controls zur laufzeit einem userControl unterordnen
 
Code:
using(Type instance = new Type())
{
   ...
}
ist das gleiche wie
Code:
Type instance = new Type();
try
{
   ...
}
finally
{
   instance.Dispose();
}
Du hast also das Control (also das WinAPI Control, dass hinter JEDEM Winforms control steckt) direkt nach dem Add(dvp) zerstört. ;)

maximov 8. Mär 2005 09:31

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?

Robert_G 8. Mär 2005 09:53

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. :?

maximov 8. Mär 2005 11:28

Re: Controls zur laufzeit einem userControl unterordnen
 
Zitat:

Zitat von Robert_G
Gibt es nicht.
Mittlerweile bin ich auch ganz froh drüber. ;)
Versuche mal fremden Code mit 5 Ebenen verschachtelten with-Blöcken zu entziffern. :?

Ja, stimmt...ist der horror. Danke für die hilfe!


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:16 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz