C# Label Text wird in aufgerufem Form nicht angezeigt

Borstenhorst

Newbie
Registriert
Dez. 2011
Beiträge
7
Tag auch!

Habe folgendes Problem:
Ich baue derzeit einen Splash-Screen der eine Fortschrittsanzeige hat und übergebenen Text anzeigen soll.

Leider zeigt mir das Form den Label-Text nicht. Weder in diesem Form, noch wenn ich ein anderes anlege und alles mit defaul-Settings mache. nichteinmal das "label1" wenn wirklich nichts geändert ist wird angezeigt :freak:

Mainform (Splash ist Splashscreen-Form):
Code:
    public partial class Form1 : Form
    {
        Splash splash = new Splash();

Aufruf
Code:
        private void btnSRCH_Click(object sender, EventArgs e)
        {
            splash.Show();

...

splash.Hide();

Quelltext Splashscreen, srchprog ist eine progress-bar
Code:
    public partial class Splash : Form
    {
        public string teststring="test";

        public Splash()
        {
            InitializeComponent();
            
        }

        private void Splash_Load(object sender, EventArgs e)
        {
            srchprog.Value = 0;  

        }
        public void setvalue (int max)
        {
            srchprog.Maximum = max;
            
        }

        public void pushlb()
        {
            srchprog.Value = ++srchprog.Value;
        }

        public string Description
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }
    }

Einstellungen Label 1, aber auch andere Labels auch mit defauleinstellungen werdne nicht geladen
Code:
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.BackColor = System.Drawing.Color.Silver;
            this.label1.Location = new System.Drawing.Point(232, 86);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(35, 17);
            this.label1.TabIndex = 0;
            this.label1.Text = "label1";
            this.label1.UseCompatibleTextRendering = true;


Einstellungen Splash-Form, aber wie gesagt auch wenn das form komplett default ist geht es nicht:
Code:
            // 
            // Splash
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.WhiteSmoke;
            this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
            this.ClientSize = new System.Drawing.Size(679, 362);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.srchprog);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Name = "Splash";
            this.ShowIcon = false;
            this.ShowInTaskbar = false;
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Splash";
            this.TransparencyKey = System.Drawing.Color.WhiteSmoke;
            this.UseWaitCursor = true;
            this.Load += new System.EventHandler(this.Splash_Load);
            this.ResumeLayout(false);
            this.PerformLayout();


Gruß Thomas
 
Zuletzt bearbeitet:
Wird dir das Label denn im Designer angezeigt?
 
Gut möglich, dass du durch die (Hintergrund)-Operation den Dispatcher-Thread blockierst und somit das Label nicht gezeichnet werden kann.
Außerdem erstellst du im Konstruktor der Form eine lokale Variable splash, in der Click-Methode greifst du aber auf die Instanzvariable splash zu.
 
Im Designer wird das Label angezeigt.

Ah okay also meinst du ich darf das Label nicht innerhalb von Form 1 erzeugen?
Sry ist mein erstes größeres c# proj :cool_alt:
 
Wenn es im Designer angezeigt wird, dann wirst du irgendetwas machen, was den GUI-Thread blockiert.
 
Zuletzt bearbeitet:
Oh ich habe mich verguckt. Das ist nicht der Konstruktor sondern die Klassendeklaration. Insofern stimmt das schon.
Kannst du mal ein Minimalbeispiel hochladen?
 
Zurück
Oben