[Mono-osx] Using System.Drawing in a Cocoa# View

Brock Reeve Brock.Reeve at ni.com
Tue Nov 13 16:12:22 EST 2007


Looking at the code for System.Drawing, if I define the 
MONO_GDIP_USE_COCOA_BACKEND environment variable and call 
Graphics.FromHwnd it will create a quartz context using the Cairo backend. 
If I then use that graphics object to draw inside of the View's Draw 
method it should draw something. I am not seeing it draw anything. If I 
use the Cocoa# BezierPath I can get it to draw. Not sure why the 
System.Drawing stuff doesn't work from Cocoa#. Here is some Cocoa #code. 
Maybe someone has tried this before. I was seeing a lot of CGContext*: 
invalid context messages, but it seems like I have a valid context from 
some of my writelines in System.Drawing.Graphics.


 [Export("drawRect:")]
        public void Draw(Rect aRect)
        {
//Must define MONO_GDIP_USE_COCOA_BACKEND on the MacOS
#if USE_GDIPLUS
            Graphics graphics = Graphics.FromHwnd(NativeObject);
            graphics.FillRectangle(Brushes.Black, new Rectangle(0, 0, 100, 
100));
#else
            Cocoa.Color.Black.Set();
            BezierPath.FillRect(new Rect(0, 0, 100, 100));
#endif
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-osx/attachments/20071113/d22fde52/attachment-0001.html 


More information about the Mono-osx mailing list