开发者

Random GUI errors using C# Mono on Mac OS X

开发者 https://www.devze.com 2022-12-28 00:55 出处:网络
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 b

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 = Creat开发者_如何转开发eHere;
        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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号