Paul,

Your program seems to work fine in VisualStudio 2005.

Address label appears but is truncated because the size you set is too short (90 rather than 72 displays it all).
KeyPress is being entered.

I hope this is helpfull but probably not.

Brian


On 3/7/06, Paul F. Johnson <[EMAIL PROTECTED] > wrote:
Hi,

The code attached works fine with Mono. VC# moans like crazy and I'm not
sure why - comments would be welcome.

The code also has 2 problems. The first is that then Address label
doesn't appear and it should (could someone confirm this so that I can
file it in Bugzilla) and the second is the KeyPress event for the
NumberBox is being ignored (from what I can see). Again, if someone can
confirm this, I'd appreciate it.

The code compiles without a hitch under Mono 1.1.13. I'm using the
Fedora Core RPMs over the build from source (don't ask).

Sorry about the length...

using System.Windows.Forms;
using System.ComponentModel;
using System.Collections;
using System.Drawing;

public class testwindow : Form
{
  private Label ServerAddress;
  private Label Address;
  private Label User;
  private Label Pass;
  private Button Connect;
  private TextBox Username;
  private TextBox Password;
  private ComboBox IPAddress;
  private NumberBox[] IP;

  private GroupBox box;

  private StatusBar StateBar;
  private ProgressBar Progress;
  private Label Connection;

  private System.ComponentModel.Container components = null;

  private testwindow()
  {
    InitializeComponent();
  }

  protected override void Dispose(bool disposing)
  {
    if (disposing)
    {
      if (components != null)
      {
        components.Dispose();
      }
    }
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    this.SuspendLayout();

    this.Size = new Size(300, 150);
    this.Text = "Server connection";

    this.ServerAddress = new Label();
    this.ServerAddress.Size = new Size(72, 12);
    this.ServerAddress.Name = "address";
    this.ServerAddress.Text = "Server Address";
    this.ServerAddress.Location = new Point(11, 14);
    this.ServerAddress.TabIndex = 0;

    this.IPAddress = new ComboBox();
    this.IPAddress.DropDownStyle = ComboBoxStyle.DropDownList ;
    this.IPAddress.BackColor = Color.White;
    this.IPAddress.ForeColor = Color.Black;
    this.IPAddress.Size = new Size(160, 8);
    this.IPAddress.Name = "ipaddress";
    this.IPAddress.Location = new Point(100, 12);
    this.IPAddress.Items.Add("Localhost");
    this.IPAddress.Items.Add("Other");
    this.IPAddress.SelectedIndex = 0;
    this.IPAddress.SelectedIndexChanged += new
System.EventHandler(this.IPAddress_SelectedIndexChanged);
    this.IPAddress.TabIndex = 1;

    this.Address = new Label();
    this.Address.Size = new Size (72, 12);
     this.Address.Name = "numaddr";
    this.Address.Text = "IP Address";
    this.Address.Enabled = false;
    this.Address.Location = new Point(11, 36);
    this.Address.TabIndex = 2;

    this.IP = new NumberBox[4];
    for (int i = 0; i < 4; ++i)
    {
      this.IP[i] = new NumberBox();
      this.IP[i].Size = new Size(44, 8);
      this.IP[i].Enabled = false;
      this.IP[i].Location = new Point(100 + (48 * i), 34);
      this.IP[i].TabIndex = 3 + i;
      this.IP[i].MaxLength = 3;
    }

    this.User = new Label();
    this.User.Size = new Size(54, 12);
    this.User.Name = "user";
    this.User.Text = "Username";
    this.User.Location = new Point(11, 64);
    this.User.TabIndex = 7;

    this.Username = new TextBox();
    this.Username.Size = new Size(80, 8);
     this.Username.Name = "username";
    this.Username.Location = new Point(70, 62);
    this.Username.TextChanged += new
System.EventHandler(this.Username_TextChanged);
    this.Username.TabIndex = 8;

    this.Pass = new Label();
    this.Pass.Size = new Size(48, 12);
    this.Pass.Name = "pass";
    this.Pass.Text = "Password";
    this.Pass.Location = new Point(150, 64);
    this.Pass.TabIndex = 9;

    this.Password = new TextBox();
    this.Password.Size = new Size(80, 12);
    this.Password.Name = "password";
    this.Password.PasswordChar = (char)'*';
    this.Password.Location = new Point (200, 62);
    this.Password.TextChanged += new
System.EventHandler(this.Password_TextChanged);
    this.Password.TabIndex = 10;

    this.box = new GroupBox();
    this.box.SuspendLayout();
    this.box.Controls.AddRange(new Control[]
        {this.ServerAddress, this.IPAddress, this.Address, this.IP[0],
         this.IP[1], this.IP[2], this.IP[3], this.User, this.Username,
         this.Pass, this.Password});
    this.box.Location = new Point(8, 4);
    this.box.Name = "groupbox";
     this.box.Size = new Size(290, 86);
    this.box.Text = "Connection details";
    this.box.TabIndex = 11;

    this.Connect = new Button();
    this.Connect.Size = new Size(70, 20);
     this.Connect.Name = "connect";
    this.Connect.Enabled = false;
    this.Connect.Text = "Connect";
    this.Connect.Location = new Point (200, 100);
    this.Connect.Click += new System.EventHandler (this.Connect_Click);
    this.Connect.TabIndex = 12;

    this.StateBar = new StatusBar();
    this.StateBar.Location = new Point(0, 130);
    this.StateBar.Height = 20;
     this.StateBar.Name = "status";
    this.StateBar.ForeColor = Color.Blue;
    this.StateBar.Text = "Disconnected";
    this.StateBar.TabIndex = 13;

    this.Connection = new Label();
    this.Connection.Size = new Size(50, 12);
    this.Connection.Text = "Progress";
    this.Connection.Enabled = false;
    this.Connection.Name = "connprog";
    this.Connection.Location = new Point(11, 106);
    this.Connection.TabIndex = 14;

    this.Progress = new ProgressBar();
    this.Progress.Location = new Point(68,100);
    this.Progress.Minimum = 0;
    this.Progress.Step = 1;
    this.Progress.Maximum = 10;
    this.Progress.Name = "progbar";
    this.Progress.Enabled = false;
    this.Progress.TabIndex = 15;

    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.Controls.AddRange(new Control[] {this.box,
                                          this.Connect, this.Connection,
                                           this.StateBar, this.Progress,
                                          this.Address});
    this.box.ResumeLayout();
    this.ResumeLayout();
  }

  public static void Main()
  {
    testwindow t = new testwindow();
    Application.Run(t);
  }

  private void Password_TextChanged(object sender, System.EventArgs e)
  {
    if (Username.Text.Length > 0 && Password.Text.Length > 0)
      Connect.Enabled = true;
    else
      Connect.Enabled = false;
  }

  private void Username_TextChanged(object sender, System.EventArgs e)
  {
    if (Username.Text.Length > 0 && Password.Text.Length > 0)
      Connect.Enabled = true;
    else
      Connect.Enabled = false;
  }

  private void IPAddress_SelectedIndexChanged(object sender,
System.EventArgs e)
  {
    Address.Enabled = IPAddress.SelectedIndex == 1 ? true : false;
    for (int i = 0; i < 4; ++i)
    {
      IP[i].Enabled = IPAddress.SelectedIndex == 1 ? true : false;
    }
  }

  private void Connect_Click(object sender, System.EventArgs e)
  {
  }
}

class NumberBox : TextBox
{
  public NumberBox()
  {
    this.KeyPress += new KeyPressEventHandler(NumberBox_KeyPress);
  }

  private void NumberBox_KeyPress(object sender, KeyPressEventArgs kpe)
  {
    int KeyCode = (int)kpe.KeyChar;
    if (!IsNumberInRange(KeyCode, 48, 57) && KeyCode != 8)
      kpe.Handled = true;
  }

  private bool IsNumberInRange(int Val, int Min, int Max)
  {
    return (Val >= Min && Val <= Max);
  }
}

TTFN

Paul
--
"Logic, my dear Zoe, is merely the ability to be wrong with authority" -
Dr Who

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list



--
Brian Pickles
_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to