Locking Up??

C

crgsmrt

Hi all,

I'd really appreciate it if someone was able to help me out with a
problem I'm having with C#. I'm a complete newbie to this, so please
excuse what may appear as a stupid question. Basically, I'm trying to
write a .NET distributed app (hopefully :p) with Indigo and .NET
Framework 2.0 (C# as my language of choice). Anyway, what I have is a
client-side object library that, when requested, will create a login
form and pass it back to the client of the library. My intention is for
the user to interact with the user interface to log into the
system.This is where it all goes a little but downhill. The actual
application that uses the object library is shown below:

==============================
Note: HIC means Human Interface Client.
==============================

using System;
using System.Collections.Generic;
using System.Text;
using WorkshopLoading.Client;
using System.Windows.Forms;

namespace WorkshopLoadingHIC
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("HIC Started...");
SystemClient sysClient = new SystemClient();
Console.WriteLine("Registering client with server...");
Console.WriteLine("Creating user login screen...");
WorkshopLoading.Client.LoginPromptForm loginForm =
sysClient.GenerateLoginPrompt();
loginForm.Show();
Console.ReadLine();
}
}
}

As you can see from this code I am attempting to create an instance of
a Windows form that has a reference to the underlying client that
created it. The user of the system creates an instance of the client,
it should (when implemented) register itself with a server and then
allow the user to log-in by providing the appropriate UI.

Anyway, the code above seems to work. I create an instance of the
SystemClient (the object is called 'sysClient'). I ask it to return to
me a Windows.Forms Form of type LoginPromptForm and then I ask it to
show itself. The problem is when I call the show method the form
appears but the controls on the form (such as the buttons Login and
Cancel) appear white (as if they are not being re-drawn properly). Then
the entire Windows Form window turns white and it reads (Not
responding...) in the Window's caption. I haven't got the fogiest what
is going on and I'd really appreciate it someone was able to point out
my mistake.


Client Library Contents...

=============
SystemClient.cs
=============

using System;
using System.Collections.Generic;
using System.Text;

namespace WorkshopLoading.Client
{
public class SystemClient
{


public SystemClient()
{
Console.WriteLine("Client started...");
}

public LoginPromptForm GenerateLoginPrompt()
{
LoginPromptForm loginFormInstance;

//Generates a login prompt for the user.
Console.WriteLine("Creating login prompt...");
loginFormInstance = new LoginPromptForm();
loginFormInstance.SetSystemClient(this);
Console.WriteLine("Login prompt created and
referenced...");
Console.WriteLine("Returning login prompt to user...");
return loginFormInstance;
}
}
}



=============
LoginForm.cs
=============

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WorkshopLoading.Client
{
public partial class LoginPromptForm : Form
{
private SystemClient m_sysClient;

public LoginPromptForm()
{
InitializeComponent();
}

public void SetSystemClient(SystemClient systemClientInstance)
{
m_sysClient = systemClientInstance;
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show("Contructing login form now...");
}

private void label1_Click(object sender, EventArgs e)
{

}
}
}

=================
LoginPromptForm.cs
=================

namespace WorkshopLoading.Client
{
partial class LoginPromptForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.UserNameLabel = new System.Windows.Forms.Label();
this.PasswordLabel = new System.Windows.Forms.Label();
this.CanceLoginlButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(216, 107);
this.button1.Margin = new System.Windows.Forms.Padding(3,
4, 3, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(101, 35);
this.button1.TabIndex = 0;
this.button1.Text = "Login";
this.button1.UseVisualStyleBackColor = true;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(142, 19);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(175, 22);
this.textBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(145, 60);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.Size = new System.Drawing.Size(172, 22);
this.textBox2.TabIndex = 2;
//
// UserNameLabel
//
this.UserNameLabel.AutoSize = true;
this.UserNameLabel.Location = new System.Drawing.Point(10,
23);
this.UserNameLabel.Name = "UserNameLabel";
this.UserNameLabel.Size = new System.Drawing.Size(71, 16);
this.UserNameLabel.TabIndex = 3;
this.UserNameLabel.Text = "Username:";
this.UserNameLabel.Click += new
System.EventHandler(this.label1_Click);
//
// PasswordLabel
//
this.PasswordLabel.AutoSize = true;
this.PasswordLabel.Location = new System.Drawing.Point(11,
60);
this.PasswordLabel.Name = "PasswordLabel";
this.PasswordLabel.Size = new System.Drawing.Size(69, 16);
this.PasswordLabel.TabIndex = 4;
this.PasswordLabel.Text = "Password:";
//
// CanceLoginlButton
//
this.CanceLoginlButton.Location = new
System.Drawing.Point(109, 105);
this.CanceLoginlButton.Name = "CanceLoginlButton";
this.CanceLoginlButton.Size = new System.Drawing.Size(101,
35);
this.CanceLoginlButton.TabIndex = 5;
this.CanceLoginlButton.Text = "Cancel";
this.CanceLoginlButton.UseVisualStyleBackColor = true;
//
// LoginPromptForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F,
16F);
this.AutoScaleMode =
System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(329, 152);
this.Controls.Add(this.CanceLoginlButton);
this.Controls.Add(this.PasswordLabel);
this.Controls.Add(this.UserNameLabel);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Font = new System.Drawing.Font("Arial", 9.75F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "LoginPromptForm";
this.Text = "Login";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label UserNameLabel;
private System.Windows.Forms.Label PasswordLabel;
private System.Windows.Forms.Button CanceLoginlButton;
}
}

Many thanks for sticking with my terrible english until now.

Regards,

:)

Craig.
 
J

Jon Skeet [C# MVP]

Anyway, the code above seems to work. I create an instance of the
SystemClient (the object is called 'sysClient'). I ask it to return to
me a Windows.Forms Form of type LoginPromptForm and then I ask it to
show itself. The problem is when I call the show method the form
appears but the controls on the form (such as the buttons Login and
Cancel) appear white (as if they are not being re-drawn properly). Then
the entire Windows Form window turns white and it reads (Not
responding...) in the Window's caption. I haven't got the fogiest what
is going on and I'd really appreciate it someone was able to point out
my mistake.

I believe the problem is that you don't have a message pump running.
Try using Application.Run (loginForm) instead of calling .Show.
 
G

GoogleEyeJoe

Jon,

You are a wonderful man. I thank you for taking the time to read this
message and help this poor idiot (that being myself). It solved the
issue. I take it the message pump is a loop constantly running to
accept Windows messages.

Regards.

Craig.
 
J

Jon Skeet [C# MVP]

GoogleEyeJoe said:
You are a wonderful man. I thank you for taking the time to read this
message and help this poor idiot (that being myself). It solved the
issue. I take it the message pump is a loop constantly running to
accept Windows messages.

Yup, that's basically it. I suspect that a Google search for "windows
message pump" would find more detailed explanations :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top