Login window issues

A

Andrus

I created login form class below.

I have the following issues with it:

1. Log message is shown only after messagebox is displayed.
How to force text to be displayed in login form immediately after calling
Log method ?

2. Log window is displayed in top of screen.
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
seems not working. How to show login form in lower part of screen ?

3. If there are more items than login area height, a scroll bar appears.
How to remove the scroll bar.

4. How to remove icon and all buttons from login form title bar ?

5. In case many messages they consume a lot of memory.
How to dispose messages (listbox items) which scroll out of login window ?

Andus.

using System;
using System.Windows.Forms;
using System.IO;

class main {
[STAThreadAttribute()]
public static void Main() {

Status s = new Status("Performing task x");
s.Log("This text is not shown immediately");

System.Threading.Thread.Sleep(8000);
MessageBox.Show ("now it is shown");
}

public class Status : Form {

ListBox lb;

public Status(string title) {

lb = new ListBox();
lb.Dock = DockStyle.Fill;
Controls.Add(lb);

Screen screen = Screen.AllScreens[0];
AutoScroll = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Text = title;
Left = 0;
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
Height = screen.WorkingArea.Height / 3;
Width = screen.WorkingArea.Width;
Show();
}

public void Log(string s) {
lb.Items.Add(s);
lb.TopIndex = lb.Items.Count - 1;
}
}
}
 
N

Nicholas Paldino [.NET/C# MVP]

Andrus,

See inline:
I created login form class below.

I have the following issues with it:

1. Log message is shown only after messagebox is displayed.
How to force text to be displayed in login form immediately after calling
Log method ?

Your example isn't really a proper one. If you are going to show a
form, you need to pass the constructed instance of the form to the Run
method on the Application class. This will start the message pump that is
needed for windows forms.

Once you do that, you should NOT be calling Show in the constructor for
your form. Rather, you should leave it to the code creating the instance of
the Status class to show the form.
2. Log window is displayed in top of screen.
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
seems not working. How to show login form in lower part of screen ?

The coordinate system begins from 0 at the bottom of the screen. Try
reducing your multiplier (right now the top of the form is at the point 60%
from the bottom of the screen).
3. If there are more items than login area height, a scroll bar appears.
How to remove the scroll bar.

Set the AutoScroll property to false.
4. How to remove icon and all buttons from login form title bar ?

If you set the ControlBox property to false, then you should be able to
get rid of the system menu, and it ^might^ remove the icon. You can try
setting the Icon property to null as well. As for removing the buttons, you
can set the MaximizeBox property to false, as well as the MinimizeBox
property. You can't remove the close button. If you really need to do
this, then you will have to custom paint the frame of your window, which is
a pain in the a$$, and you REALLY don't want to do that.
5. In case many messages they consume a lot of memory.
How to dispose messages (listbox items) which scroll out of login window ?

You are going to have to figure out how many items can fit in the form's
listbox, and then as you add new items, see how many are in the list. If
you exceed that number, then remove the first item in the list.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Andus.

using System;
using System.Windows.Forms;
using System.IO;

class main {
[STAThreadAttribute()]
public static void Main() {

Status s = new Status("Performing task x");
s.Log("This text is not shown immediately");

System.Threading.Thread.Sleep(8000);
MessageBox.Show ("now it is shown");
}

public class Status : Form {

ListBox lb;

public Status(string title) {

lb = new ListBox();
lb.Dock = DockStyle.Fill;
Controls.Add(lb);

Screen screen = Screen.AllScreens[0];
AutoScroll = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Text = title;
Left = 0;
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
Height = screen.WorkingArea.Height / 3;
Width = screen.WorkingArea.Width;
Show();
}

public void Log(string s) {
lb.Items.Add(s);
lb.TopIndex = lb.Items.Count - 1;
}
}
}
 
A

Andrus

Nicholas,
Your example isn't really a proper one. If you are going to show a
form, you need to pass the constructed instance of the form to the Run
method on the Application class. This will start the message pump that is
needed for windows forms.

This issue reproduction performs some task and exists.
It uses form only to show progress messages.
Since it does not need to enter to message bump it does not call
Application.Run() method.
My actual MDI application calles Run() method for MDI parent form.
However, it encounters exactly the same issue.

So my questions were:

1. How to force listbox to show new item immediately, without entering wait
state ?
2. How to force status window to continue display messages when I switch to
other application and then back to my application ?
Current not responding appears and window stops updating.

Once you do that, you should NOT be calling Show in the constructor for
your form. Rather, you should leave it to the code creating the instance
of the Status class to show the form.

If I remove Show() call form does not display at all. So Show() call must
exist.
The coordinate system begins from 0 at the bottom of the screen. Try
reducing your multiplier (right now the top of the form is at the point
60% from the bottom of the screen).

Setting
StartPosition = FormStartPosition.Manual;

fixes this. 0.6 is right value.
Set the AutoScroll property to false.

as you see my code, AutoScroll is set to false.
This does not remove scrollbar which appers in ListBox.
Since ListBox is inside form, setting forms AutoScroll does not have any
effect at all.
If you set the ControlBox property to false, then you should be able to
get rid of the system menu, and it ^might^ remove the icon. You can try
setting the Icon property to null as well. As for removing the buttons,
you can set the MaximizeBox property to false, as well as the MinimizeBox
property. You can't remove the close button. If you really need to do
this, then you will have to custom paint the frame of your window, which
is a pain in the a$$, and you REALLY don't want to do that.

After setting all those properties, close button disappears.
So I do'nt understand this: "You can't remove the close button"
You are going to have to figure out how many items can fit in the
form's listbox, and then as you add new items, see how many are in the
list. If you exceed that number, then remove the first item in the list.

This sounds too complicated.
Where to find some sample ? Or should I use some other control instead of
ListBox ?

Andrus.
 
A

Andrus

Nicholas,

how are you ?

Andrus.
I created login form class below.

I have the following issues with it:

1. Log message is shown only after messagebox is displayed.
How to force text to be displayed in login form immediately after calling
Log method ?

Your example isn't really a proper one. If you are going to show a
form, you need to pass the constructed instance of the form to the Run
method on the Application class. This will start the message pump that is
needed for windows forms.

Once you do that, you should NOT be calling Show in the constructor for
your form. Rather, you should leave it to the code creating the instance
of the Status class to show the form.
2. Log window is displayed in top of screen.
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
seems not working. How to show login form in lower part of screen ?

The coordinate system begins from 0 at the bottom of the screen. Try
reducing your multiplier (right now the top of the form is at the point
60% from the bottom of the screen).
3. If there are more items than login area height, a scroll bar appears.
How to remove the scroll bar.

Set the AutoScroll property to false.
4. How to remove icon and all buttons from login form title bar ?

If you set the ControlBox property to false, then you should be able to
get rid of the system menu, and it ^might^ remove the icon. You can try
setting the Icon property to null as well. As for removing the buttons,
you can set the MaximizeBox property to false, as well as the MinimizeBox
property. You can't remove the close button. If you really need to do
this, then you will have to custom paint the frame of your window, which
is a pain in the a$$, and you REALLY don't want to do that.
5. In case many messages they consume a lot of memory.
How to dispose messages (listbox items) which scroll out of login window
?

You are going to have to figure out how many items can fit in the
form's listbox, and then as you add new items, see how many are in the
list. If you exceed that number, then remove the first item in the list.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Andus.

using System;
using System.Windows.Forms;
using System.IO;

class main {
[STAThreadAttribute()]
public static void Main() {

Status s = new Status("Performing task x");
s.Log("This text is not shown immediately");

System.Threading.Thread.Sleep(8000);
MessageBox.Show ("now it is shown");
}

public class Status : Form {

ListBox lb;

public Status(string title) {

lb = new ListBox();
lb.Dock = DockStyle.Fill;
Controls.Add(lb);

Screen screen = Screen.AllScreens[0];
AutoScroll = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
Text = title;
Left = 0;
Top = (int)(0.6 * (double)screen.WorkingArea.Height);
Height = screen.WorkingArea.Height / 3;
Width = screen.WorkingArea.Width;
Show();
}

public void Log(string s) {
lb.Items.Add(s);
lb.TopIndex = lb.Items.Count - 1;
}
}
}
 

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