在 Mac OS X 上使用 C# Mono 时出现随机 GUI 错误
我正在用 C#(Windows 窗体)开发一个应用程序,它使用 Mono 在 Mac OS X 上运行。 它包含一些动态控件,例如包含一些标签和文本框的自定义组框、按钮等。这些框都可以动态添加和删除。
我的 CustomGrpBx 继承自 GroupBox,这是我使用的构造函数:
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);
}
在创建和删除它们时,甚至在显示消息框时,都会出现问题。 发生的情况是,有时渲染时会出现白框,或者某些标签未正确绘制。有时,当出现消息框时,它首先会打开,就像 5 个空白的虚拟对象一样,而且您无法关闭它们。
我是否做错了什么,我应该在每次创建后让 GUI 线程休眠一下,还是应该自己使东西无效?或者我应该尝试GTK#?
非常感谢您对此的投入。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在没有看到实际代码的情况下很难提出建议,但首先,使用 MoMa 对于不兼容问题(例如,pinvoke 的问题),如果您主要开发针对 .NET 平台的项目。然后,Mono 团队声称 Mono 中的 Windows 窗体支持已经完成:
因此,您可以尝试在.NET下运行您的项目,看看错误是否仍然存在。
至于Gtk#。我认为如果您的项目的主要操作系统是 OSX,最好使用 gtk#。至少你将能够使用一些 OSX 特定的东西,例如,集成到它的工具栏中。请在此处查看 Gtk# 项目的开源示例,该项目使用了一些本机 OSX 功能并在其中很好地集成环境。 MonoDevelop 的设计器中还支持 gtk#。
聚苯乙烯
一些有趣的 Gtk# 项目可供使用:
小猎犬,
假小子
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:
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