AnsweredAssumed Answered

Resizing problems with ScreenDisplay class

Question asked by dresel on Feb 3, 2012
Hi guys,

im playing around with simple drawing operations with the ScreenDisplay class on a WPF Sample. I'm developing a System.Windows.Forms.Control class which holds the reference to the ScreenDisplay. The control is hosted by an WindowsFormsHost. The code i use is collected from different scattered ressources i found in the internet.

In my control i create the display like this:

//Create SimpleDisplay
display = (IScreenDisplay3)new ESRI.ArcGIS.Display.ScreenDisplay();
display.hWnd = (int)this.Handle;

//Set Bounds
IEnvelope2 envelope = (IEnvelope2)new ESRI.ArcGIS.Geometry.Envelope();
envelope.PutCoords(0, 0, 200, 200);

display.DisplayTransformation.Bounds = envelope;

envelope = (IEnvelope2)new ESRI.ArcGIS.Geometry.Envelope();
envelope.PutCoords(0, 0, 100, 100);

display.DisplayTransformation.VisibleBounds = envelope;

display.ScaleContents = false;
display.UseScrollbars = false;

display.Invalidate(null, true, (short)esriScreenCache.esriAllScreenCaches);

During OnPaint im displaying a simple line for testing purpose:

protected override void OnPaint(PaintEventArgs e)

protected void Draw(System.Drawing.Graphics graphics)
 //Create Polyline
 IPolyline polyline = (IPolyline)new Polyline();
 polyline.FromPoint = ContructESRIPoint(20, 20);
 polyline.ToPoint = ContructESRIPoint(200, 80);


  //Start Drawing
  display.StartDrawing(graphics.GetHdc().ToInt32(), (short)esriScreenCache.esriNoScreenCache);

  //Create Symbology
  ISimpleLineSymbol s = new SimpleLineSymbol();
  s.Style = esriSimpleLineStyle.esriSLSSolid;
  s.Width = 3;


  //Draw Polyline

  //Finish Drawing

  ESRI.ArcGIS.esriSystem.tagRECT emptyRect = new ESRI.ArcGIS.esriSystem.tagRECT();

  display.DrawCache(graphics.GetHdc().ToInt32(), (short)esriScreenCache.esriScreenRecording, emptyRect, emptyRect);

When i resize the control i encounter two different problems:

  • The background color changes from transparent to white (see screenhots). In First.png you see the ScreenDisplay only renders the Polyline with transparent background, in Second.png during the resize the Background changes to white - this only occurs when using the ScreenRecording cache. Why is this happening and how can i prevent this?

  • The control flickers. Tried to use DoubleBuffering = true, but that only results in weird behaviour. I tried resizing in ArcMap, where no flickering occurs - so this must be somehow possible.

Hope you can help me, it's really hard to find samples working directly with the ScreenDisplay class...

Thank you,