packages/Windows API Code Pack 1.1/source/Samples/DirectX/CS/Direct2D/ChartDemo/Window1.xaml.cs
/// <summary>
/// This method creates the render target and all associated D2D and DWrite resources
/// </summary>
This method creates the render target and all associated D2D and DWrite resources
This method creates the render target and all associated D2D and DWrite resources
void CreateDeviceResources()
        {
            if (renderTarget == null)
            {
                textFormat = dwriteFactory.CreateTextFormat("Bodoni MT", 24, DWrite.FontWeight.Normal, DWrite.FontStyle.Italic, DWrite.FontStretch.Normal);
                SizeU size = new SizeU((uint)host.ActualWidth, (uint)host.ActualHeight);
                RenderTargetProperties props = new RenderTargetProperties();
                HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties(host.Handle, size, PresentOptions.None);
                renderTarget = d2dFactory.CreateHwndRenderTarget(props, hwndProps);
                ColorF cf = new ColorF(0, 0, 0, 1);
                blackBrush = renderTarget.CreateSolidColorBrush(cf);
                GradientStop[] stops = 
                { 
                    new GradientStop(1, new ColorF(1f, 0f, 0f, 0.25f)),
                    new GradientStop(0, new ColorF(0f, 0f, 1f, 1f))
                };
                GradientStopCollection pGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties(new Point2F(50, 25), new Point2F(25, 50));
                linearGradientBrush = renderTarget.CreateLinearGradientBrush(gradBrushProps, pGradientStops);
                gridPatternBitmapBrush = CreateGridPatternBrush(renderTarget);
                solidBrush1 = renderTarget.CreateSolidColorBrush(new ColorF(0.3F, 0.5F, 0.65F, 0.25F));
                solidBrush2 = renderTarget.CreateSolidColorBrush(new ColorF(0.0F, 0.0F, 0.65F, 0.5F));
                solidBrush3 = renderTarget.CreateSolidColorBrush(new ColorF(0.9F, 0.5F, 0.3F, 0.75F));
                stops[0] = new GradientStop(1, new ColorF(0f, 0f, 0f, 0.25f));
                stops[1] = new GradientStop(0, new ColorF(1f, 1f, 0.2f, 1f));
                GradientStopCollection radiantGradientStops = renderTarget.CreateGradientStopCollection(stops, Gamma.Linear, ExtendMode.Wrap);
                RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties(new Point2F(25, 25), new Point2F(0, 0), 10, 10);
                radialGradientBrush = renderTarget.CreateRadialGradientBrush(radialBrushProps, radiantGradientStops);
            }
        }
void CreateDeviceResources ( ) { if ( renderTarget == null ) { textFormat = dwriteFactory . CreateTextFormat ( " " , 24 , DWrite . FontWeight . Normal , DWrite . FontStyle . Italic , DWrite . FontStretch . Normal ) ; SizeU size = new SizeU ( ( uint ) host . ActualWidth , ( uint ) host . ActualHeight ) ; RenderTargetProperties props = new RenderTargetProperties ( ) ; HwndRenderTargetProperties hwndProps = new HwndRenderTargetProperties ( host . Handle , size , PresentOptions . None ) ; renderTarget = d2dFactory . CreateHwndRenderTarget ( props , hwndProps ) ; ColorF cf = new ColorF ( 0 , 0 , 0 , 1 ) ; blackBrush = renderTarget . CreateSolidColorBrush ( cf ) ; GradientStop [ ] stops = { new GradientStop ( 1 , new ColorF ( 1f , 0f , 0f , 0.25f ) ) , new GradientStop ( 0 , new ColorF ( 0f , 0f , 1f , 1f ) ) } ; GradientStopCollection pGradientStops = renderTarget . CreateGradientStopCollection ( stops , Gamma . Linear , ExtendMode . Wrap ) ; LinearGradientBrushProperties gradBrushProps = new LinearGradientBrushProperties ( new Point2F ( 50 , 25 ) , new Point2F ( 25 , 50 ) ) ; linearGradientBrush = renderTarget . CreateLinearGradientBrush ( gradBrushProps , pGradientStops ) ; gridPatternBitmapBrush = CreateGridPatternBrush ( renderTarget ) ; solidBrush1 = renderTarget . CreateSolidColorBrush ( new ColorF ( 0.3F , 0.5F , 0.65F , 0.25F ) ) ; solidBrush2 = renderTarget . CreateSolidColorBrush ( new ColorF ( 0.0F , 0.0F , 0.65F , 0.5F ) ) ; solidBrush3 = renderTarget . CreateSolidColorBrush ( new ColorF ( 0.9F , 0.5F , 0.3F , 0.75F ) ) ; stops [ 0 ] = new GradientStop ( 1 , new ColorF ( 0f , 0f , 0f , 0.25f ) ) ; stops [ 1 ] = new GradientStop ( 0 , new ColorF ( 1f , 1f , 0.2f , 1f ) ) ; GradientStopCollection radiantGradientStops = renderTarget . CreateGradientStopCollection ( stops , Gamma . Linear , ExtendMode . Wrap ) ; RadialGradientBrushProperties radialBrushProps = new RadialGradientBrushProperties ( new Point2F ( 25 , 25 ) , new Point2F ( 0 , 0 ) , 10 , 10 ) ; radialGradientBrush = renderTarget . CreateRadialGradientBrush ( radialBrushProps , radiantGradientStops ) ; } }
This method creates the render target and all associated D2D and DWrite resources
This method creates the render target and all associated D2D and DWrite resources
// Only calls if resources have not been initialize before // The text format // Create the render target // A black brush to be used for drawing text // Create a linear gradient. // Create a linear gradient.