views:

175

answers:

1

I'm developing an application in C# (Windows Forms), which uses Mono to run on Mac OS X. It contains some dynamic controls, for example a custom groupbox which contains some labels and textboxes, a button, etc.These boxes can both be added and removed dynamically.

My CustomGrpBx inherits from GroupBox and this is the contructor I use:

    public CustomGrpBx(Point CreateHere,Info Inf)
    {

        this.Name = Inf.Name;

        this.Location = CreateHere;
        CreateHere.Y = 10;
        CreateHere.X = 10;
        CreateHere.Y += 7;

        Button btnPress = new Button();
        btnPress.Location = CreateHere;
        btnPress.Size = new Size(40, 24);
        btnPress.Text = Name;
        btnPress.Enabled = false;
        this.Controls.Add(btnPress);
        CreateHere.X += 45;
        CreateHere.Y += 2;

        TextBox txtName = new TextBox();
        txtName.Location = CreateHere;
        txtName.Size = new Size(75, 20);
        txtName.Text = Name;
        txtName.ReadOnly = true;
        this.Controls.Add(txtName);
        CreateHere.X += 80;

        //More code here, but the same pattern as above

        this.Size = new Size(CreateHere.X + 30, CreateHere.Y + 35);
    }

The problem arises both when they are created, and removed, or even when a messagebox is shown. What happens is that sometimes on rendering white boxes appears, or some labels are not drawn correctly. And sometimes when a messagebox appears, it first opens up like 5 dummies which are just blank, and which you can't close.

Am I doing something wrong, should I sleep the GUI thread a bit after each creation, or should I invalidate stuff on my own? Or should I try GTK#?

Many thanks on input on this.

A: 

It is hard to advise something without seeing actual code, but first of all, check your assembly with MoMa for incompatibility issues (for example, pinvoke's), if you primarily developed your project targeting .NET platform. Then, mono team claims that windows form support in mono is complete:

Support for Windows Forms 2.0 is complete. At this point, we are largely just fixing bugs and polishing our code.

So, you can try to run your project under .NET and see if the bug persists.

As for Gtk#. I think it is better to use gtk# if a primary OS for your project is OSX. At the very least you will be able to use some OSX-specific stuff, for example, integrate in it's toolbar. Look here for an open-source example of Gtk# project which uses some native OSX features and integrates well in it's environment. There also is a support for gtk# in MonoDevelop's designer.

P.S. Some interesting Gtk# projects to play with: Beagle, Tomboy

n535
Added code exampleAnd i get zero problems with the same code in windows, and MoMa gives me no errors : /
Erik Karlsson
Well, to be honest i don't see anything that can correlate with your errors.
n535
I will try to get a printscreen of it next time im on a mac.Should prob bug report it to mono team?
Erik Karlsson
I don't know, first, try running your application on a Linux machine, for example, it does not look line a bug in mono, the code is too simple, really. Essentially, you are just dynamically adding controls to your form, that is a common scenario. I think the bug is in a different place. But everything is possible.
n535