问题描述
我在Linux / UNIX计算机上使用MonoDevelop IDE,并在C#和.NET框架中进行编码。我似乎无法弄清楚如何在项目构建时让Gtk :: DrawingArea显示在父Gtk.Window中。
我尝试将::: drawingArea对象手动添加到代码中,直接将其放置在窗口中(在设计视图中,请参见屏幕截图),然后我也尝试将:: drawingArea对象放置在“固定”框中。
下面是我要实现的代码。设计是您所能获得的最基本的东西,只是为了使我能理解捕获和处理到drawingArea的信号-它具有父窗口(MainWindow)和绘图区域(drawingarea1)。
我的问题:如何获取drawingArea对象显示在Gtk.Window中?而且,更重要的是,我缺少使对象响应设置到绘图区域的信号的某些东西吗?我希望最终能够在绘图区域窗口内进行绘图和着色,但是到目前为止,我什至无法使绘图区域小部件显示和捕获信号。
谢谢!
MainWidow.cs
library(data.table)
DT[,lapply(.SD,function(x) fcase(x %in% invalid_values,-99,!x %in% invalid_values,x))]
Driver.cs
using System;
using Gtk;
public partial class MainWindow : Gtk.Window
{
public DrawingArea d;
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
d = drawingarea1;
Build();
}
protected void OnDeleteEvent(object sender,DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
protected void OnExpose(object o,ExposeEventArgs args)
{
Console.WriteLine("OnExpose...");
}
protected void OnRealization(object sender,EventArgs e)
{
Console.WriteLine("OnRealization...");
}
protected void OnDragMotion(object o,DragMotionArgs args)
{
Console.WriteLine("OnDragMotion...");
}
}
// *******部分解决方案********** //
ColorSelectorDraw.cs
using System;
using Gtk;
class MainClass
{
public static void Main(string[] args)
{
Application.Init();
MainWindow win = new MainWindow();
// throws NULLREFERENCE EXECPTION
win.d.Show();
win.Show();
Application.Run();
}
}
Program.cs
using System;
using Gtk;
using Gdk;
namespace GUIDraw4
{
public class DemoColorSelection : Gtk.Window
{
private Gdk.Color color;
private Gtk.DrawingArea drawingArea;
public DemoColorSelection() : base("Color Selection")
{
BorderWidth = 8;
VBox vbox = new VBox(false,8);
vbox.BorderWidth = 8;
Add(vbox);
// Create the color swatch area
Frame frame = new Frame();
frame.ShadowType = ShadowType.In;
vbox.PackStart(frame,true,0);
drawingArea = new DrawingArea();
drawingArea.ExposeEvent += new ExposeEventHandler(ExposeEventCallback);
// set a minimum size
drawingArea.SetSizeRequest(400,250);
// set the color
color = new Gdk.Color(255,255,255);
drawingArea.ModifyBg(StateType.Normal,color);
frame.Add(drawingArea);
Alignment alignment = new Alignment(1.0f,0.5f,0.0f,0.0f);
Button button = new Button("_Change the above color");
button.Clicked += new EventHandler(ChangeColorCallback);
alignment.Add(button);
vbox.PackStart(alignment);
ShowAll();
}
protected override bool OnDeleteEvent(Gdk.Event evt)
{
Destroy();
return true;
}
// Expose callback for the drawing area
private void ExposeEventCallback(object o,ExposeEventArgs args)
{
EventExpose eventExpose = args.Event;
Gdk.Window window = eventExpose.Window;
Rectangle area = eventExpose.Area;
window.DrawRectangle(drawingArea.Style.BackgroundGC(StateType.Normal),area.X,area.Y,area.Width,area.Height);
args.RetVal = true;
}
private void ChangeColorCallback(object o,EventArgs args)
{
using (ColorSelectionDialog colorSelectionDialog = new ColorSelectionDialog("Changing color"))
{
colorSelectionDialog.TransientFor = this;
colorSelectionDialog.ColorSelection.PreviousColor = color;
colorSelectionDialog.ColorSelection.CurrentColor = color;
colorSelectionDialog.ColorSelection.HasPalette = true;
if (colorSelectionDialog.Run() == (int)ResponseType.Ok)
{
Gdk.Color selected = colorSelectionDialog.ColorSelection.CurrentColor;
drawingArea.ModifyBg(StateType.Normal,selected);
}
colorSelectionDialog.Hide();
}
}
}
}
这似乎至少在GUI上建立了一个交互式绘图板。取自csharp.hotexamples.com
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)